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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(model-manager): require PiD backbone name boundaries
joshistoast996b8f0856d0
diff --git a/invokeai/backend/model_manager/configs/pid_decoder.py b/invokeai/backend/model_manager/configs/pid_decoder.pyindex dcc783953a..bc6bec3e98 100644--- a/invokeai/backend/model_manager/configs/pid_decoder.py+++ b/invokeai/backend/model_manager/configs/pid_decoder.py@@ -205,11 +205,11 @@ def _name_components(mod: ModelOnDisk, override_fields: dict[str, Any]) -> tuple# `flux2` before `flux`. That is precedence between two spellings of one answer, not between two# answers — see `_backbone_named_in`._BACKBONE_NAME_PATTERNS: tuple[tuple[BaseModelType, re.Pattern[str]], ...] = (- (BaseModelType.Flux2, re.compile(r"flux[_\-.]?2")),- (BaseModelType.StableDiffusionXL, re.compile(r"sdxl")),- (BaseModelType.QwenImage, re.compile(r"qwen[_\-.]?image")),- (BaseModelType.StableDiffusion3, re.compile(r"sd[_\-.]?3")),- (BaseModelType.Flux, re.compile(r"flux")),+ (BaseModelType.Flux2, re.compile(r"(?<![a-z0-9])flux[_\-.]?2(?![a-z0-9])")),+ (BaseModelType.StableDiffusionXL, re.compile(r"(?<![a-z0-9])sdxl(?![a-z0-9])")),+ (BaseModelType.QwenImage, re.compile(r"(?<![a-z0-9])qwen[_\-.]?image(?![a-z0-9])")),+ (BaseModelType.StableDiffusion3, re.compile(r"(?<![a-z0-9])sd[_\-.]?3(?![a-z0-9])")),+ (BaseModelType.Flux, re.compile(r"(?<![a-z0-9])flux(?![a-z0-9])")),)diff --git a/tests/backend/model_manager/configs/test_pid_decoder_config.py b/tests/backend/model_manager/configs/test_pid_decoder_config.pyindex 62d1045aab..b7c6f3283f 100644--- a/tests/backend/model_manager/configs/test_pid_decoder_config.py+++ b/tests/backend/model_manager/configs/test_pid_decoder_config.py@@ -421,6 +421,17 @@ class TestNameEvidence:"""The name only ever breaks the 16-channel FLUX.1 / SD3 / Qwen-Image tie — the weights decideeverything else. These pin how the name is read when it is consulted."""+ def test_incidental_backbone_substring_in_parent_directory_is_ignored(self) -> None:+ """An unrelated directory containing the letters ``sd3`` must not name the checkpoint's backbone."""+ with TemporaryDirectory() as tmpdir:+ checkpoint_dir = Path(tmpdir) / "modelsd3cache"+ checkpoint_dir.mkdir()+ path = _write_pid_checkpoint(checkpoint_dir, _real_pid_state_dict())+ result = ModelConfigFactory.from_model_on_disk(path, allow_unknown=True)++ assert result.config is not None+ assert result.config.base is BaseModelType.Flux+def test_the_filename_beats_the_parent_directory(self) -> None:"""The reported case. Concatenating every name component into one string and substring-matchingit let a fixed backbone precedence decide what the name had already answered: `/flux/model_sd3.pth`