Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(models): rebase relocated submodel paths

wunianze666-netizen714875b41a48
diff --git a/invokeai/backend/model_manager/load/load_default.py b/invokeai/backend/model_manager/load/load_default.py
index 9a75588fa6..506cc5f1b1 100644
--- a/invokeai/backend/model_manager/load/load_default.py
+++ b/invokeai/backend/model_manager/load/load_default.py
@@ -70,11 +70,23 @@ def resolve_submodel_path(config: AnyModelConfig, submodel_type: SubModelType, f
instead assumes the key always equals the slot name, so a pipeline that calls its CLIP encoder
something else passes discovery and is then loaded from a directory that does not exist.
+ Remote installs discover components inside a ``tmpinstall_*`` directory before moving the
+ pipeline into its permanent model directory. Existing records may therefore carry a discovered
+ path whose root no longer exists. Discovery only records direct children of the pipeline, so in
+ that case rebase the recorded component name onto the current model root.
+
`fallback` is used when the config carries no such entry — configs persisted before submodel
discovery existed, and the layouts where the component folder *is* the model path.
"""
discovered = (getattr(config, "submodels", None) or {}).get(submodel_type)
- return Path(discovered.path_or_prefix) if discovered else fallback
+ if not discovered:
+ return fallback
+
+ discovered_path = Path(discovered.path_or_prefix)
+ relocated_path = Path(config.path) / discovered_path.name
+ if not discovered_path.exists() and relocated_path.exists():
+ return relocated_path
+ return discovered_path
def _device_supports_fp8_storage(device: torch.device, logger: Optional[Logger] = None) -> bool:
diff --git a/tests/backend/model_manager/load/test_load_default_helpers.py b/tests/backend/model_manager/load/test_load_default_helpers.py
index 0346d448cd..4e9d26d168 100644
--- a/tests/backend/model_manager/load/test_load_default_helpers.py
+++ b/tests/backend/model_manager/load/test_load_default_helpers.py
@@ -60,6 +60,53 @@ class TestResolveSubmodelPath:
assert resolved == Path("/models/pipeline/clip_encoder")
+ def test_it_rebases_a_discovered_path_after_the_pipeline_is_moved(self, tmp_path: Path) -> None:
+ """Remote installs identify a pipeline in a staging dir before moving it into models/."""
+ staging_root = tmp_path / "tmpinstall_pipeline"
+ discovered_component = staging_root / "clip_encoder"
+ discovered_component.mkdir(parents=True)
+
+ installed_root = tmp_path / "models" / "pipeline"
+ installed_root.parent.mkdir()
+ staging_root.rename(installed_root)
+ config = SimpleNamespace(
+ path=installed_root.as_posix(),
+ submodels={SubModelType.TextEncoder: SimpleNamespace(path_or_prefix=discovered_component.as_posix())},
+ )
+
+ resolved = resolve_submodel_path(config, SubModelType.TextEncoder, installed_root / "text_encoder")
+
+ assert resolved == installed_root / "clip_encoder"
+
+ def test_it_keeps_an_existing_discovered_path_outside_the_pipeline(self, tmp_path: Path) -> None:
+ """A valid external component must not be replaced merely because the pipeline has a namesake."""
+ external_component = tmp_path / "shared" / "clip_encoder"
+ external_component.mkdir(parents=True)
+ installed_component = tmp_path / "pipeline" / "clip_encoder"
+ installed_component.mkdir(parents=True)
+ config = SimpleNamespace(
+ path=installed_component.parent.as_posix(),
+ submodels={SubModelType.TextEncoder: SimpleNamespace(path_or_prefix=external_component.as_posix())},
+ )
+
+ resolved = resolve_submodel_path(config, SubModelType.TextEncoder, installed_component.parent / "text_encoder")
+
+ assert resolved == external_component
+
+ def test_it_keeps_a_missing_discovered_path_when_no_relocated_component_exists(self, tmp_path: Path) -> None:
+ """Do not hide a genuinely missing component behind an invented path under the model root."""
+ missing_component = tmp_path / "staging" / "clip_encoder"
+ installed_root = tmp_path / "pipeline"
+ installed_root.mkdir()
+ config = SimpleNamespace(
+ path=installed_root.as_posix(),
+ submodels={SubModelType.TextEncoder: SimpleNamespace(path_or_prefix=missing_component.as_posix())},
+ )
+
+ resolved = resolve_submodel_path(config, SubModelType.TextEncoder, installed_root / "text_encoder")
+
+ assert resolved == missing_component
+
def test_it_falls_back_when_the_slot_was_not_discovered(self) -> None:
"""Configs persisted before submodel discovery existed carry no map."""
fallback = Path("/models/pipeline/text_encoder")