Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion swift/llm/template/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from transformers.utils import strtobool

from swift.llm import to_device
from swift.plugin.loss_scale.loss_scale import LossScale
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

Removing this top-level import and moving it into __init__ is the right way to fix the circular dependency. However, this will cause a NameError because LossScale is used as a type hint for self.loss_scale on line 116 and will no longer be in scope at class definition time.

To resolve this, you should add from swift.plugin.loss_scale.loss_scale import LossScale inside the if TYPE_CHECKING: block at lines 34-35. This will make the type available for static analysis without re-introducing the circular import at runtime.

from swift.utils import get_env_args, get_logger
from ..utils import Processor, ProcessorMixin
from .template_inputs import InferRequest, StdTemplateInputs, TemplateInputs
Expand Down Expand Up @@ -88,6 +87,7 @@ def __init__(
padding_side: The padding_side when the training batch_size >= 2
loss_scale: The loss scale function to use
"""
from swift.plugin.loss_scale.loss_scale import LossScale
from .template_meta import TemplateMeta
from swift.plugin import agent_templates, loss_scale_map
self._processor_inited = False
Expand Down