Revert "Tiny refactor DefaultModelLoader.Source" (#5825)

This commit is contained in:
Lianmin Zheng
2025-04-28 01:18:57 -07:00
committed by GitHub
parent 966eb90865
commit 693723d1f7
2 changed files with 13 additions and 11 deletions

View File

@@ -515,7 +515,13 @@ class ModelRunner:
def get_weight_iter(config):
iter = loader._get_weights_iterator(
DefaultModelLoader.Source.init_new(config, model)
DefaultModelLoader.Source(
config.model_path,
revision=config.revision,
fall_back_to_pt=getattr(
self.model, "fall_back_to_pt_during_load", True
),
)
)
return iter

View File

@@ -197,15 +197,6 @@ class DefaultModelLoader(BaseModelLoader):
fall_back_to_pt: bool = True
"""Whether .pt weights can be used."""
@classmethod
def init_new(cls, model_config: ModelConfig, model):
return cls(
model_config.model_path,
model_config.revision,
prefix="",
fall_back_to_pt=getattr(model, "fall_back_to_pt_during_load", True),
)
def __init__(self, load_config: LoadConfig):
super().__init__(load_config)
if load_config.model_loader_extra_config:
@@ -350,7 +341,12 @@ class DefaultModelLoader(BaseModelLoader):
model: nn.Module,
) -> Generator[Tuple[str, torch.Tensor], None, None]:
primary_weights = DefaultModelLoader.Source.init_new(model_config, model)
primary_weights = DefaultModelLoader.Source(
model_config.model_path,
model_config.revision,
prefix="",
fall_back_to_pt=getattr(model, "fall_back_to_pt_during_load", True),
)
yield from self._get_weights_iterator(primary_weights)
secondary_weights = cast(