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(models): stop recording FP8 Storage for a model whose loader ignores it
Alexander Eichhorn5dbd31decde8
diff --git a/invokeai/backend/model_manager/configs/factory.py b/invokeai/backend/model_manager/configs/factory.pyindex 7e93c73184..8b41c57a61 100644--- a/invokeai/backend/model_manager/configs/factory.py+++ b/invokeai/backend/model_manager/configs/factory.py@@ -187,7 +187,6 @@ from invokeai.backend.model_manager.configs.vae import (from invokeai.backend.model_manager.configs.wan_t5_encoder import WanT5Encoder_WanT5Encoder_Configfrom invokeai.backend.model_manager.model_on_disk import ModelOnDisk, read_safetensors_headerfrom invokeai.backend.model_manager.taxonomy import (- QUANTIZED_MODEL_FORMATS,BaseModelType,ModelFormat,ModelSourceType,@@ -250,19 +249,38 @@ def _identified_default_settings(settings_cls: type[SettingsT],mod: ModelOnDisk,override_fields: dict[str, Any] | None,- fp8_storage_applies: bool,+ # Quoted: `AnyModelConfig` is the union of the concrete config classes and is assembled further down+ # this module. `Config_Base` would not do — it declares none of base/type/format, which only a concrete+ # class does (enforced by `__pydantic_init_subclass__`).+ config: "AnyModelConfig",) -> SettingsT | None:"""Layer the settings sent with an install, and FP8 Storage for a float8 denoiser, over the recommended defaults.An install setting wins over detection in both directions. Fields the settings class does not have (a main-modelfield sent along with a LoRA install) are dropped, since nothing would read them.++ FP8 Storage is enabled only where the model's own loader implements it. It used to be enabled for any float8+ denoiser whose format was not already quantized, which wrote `fp8_storage: true` onto records whose loader ignores+ it -- a Wan fp8 install was told its weights were halved and then loaded at bf16 size. `fp8_storage_verdict` is the+ same answer the loader gate and the API row give; see `load/fp8_capability.py`.++ A request sent with the install is dropped for such a model rather than stored. The detail panel does not offer the+ control where the loader ignores it, so a stored `true` would be a value nobody can see or clear again -- and the+ Add Models flow has one FP8 Storage checkbox for whatever is being installed, so it is easy to send for a model+ that cannot use it."""requested = (override_fields or {}).get("default_settings") or {}update = {name: value for name, value in requested.items() if name in settings_cls.model_fields and value is not None}- if fp8_storage_applies and "fp8_storage" not in update and _denoiser_stores_float8_weights(mod):+ # Imported here, not at module scope: `model_loader_registry` imports this module, so the reverse edge would close+ # a cycle. Identification runs long after import time, and the import is a `sys.modules` hit after the first.+ from invokeai.backend.model_manager.load.fp8_capability import fp8_storage_verdict++ if not fp8_storage_verdict(config.base, config.type, config.format).supported:+ update.pop("fp8_storage", None)+ elif "fp8_storage" not in update and _denoiser_stores_float8_weights(mod):logger.info(f"{mod.name}: denoiser weights are stored in float8, enabling FP8 Storage by default")update["fp8_storage"] = True@@ -889,7 +907,7 @@ class ModelConfigFactory:MainModelDefaultSettings,mod,override_fields,- fp8_storage_applies=config.format not in QUANTIZED_MODEL_FORMATS,+ config=config,)case ModelType.ControlNet | ModelType.T2IAdapter | ModelType.ControlLoRa:config.default_settings = _identified_default_settings(@@ -897,8 +915,7 @@ class ModelConfigFactory:ControlAdapterDefaultSettings,mod,override_fields,- # A ControlLoRA is patched into its base model and never cast on its own.- fp8_storage_applies=config.type is not ModelType.ControlLoRa,+ config=config,)case ModelType.LoRA:config.default_settings = _identified_default_settings(@@ -906,7 +923,7 @@ class ModelConfigFactory:LoraModelDefaultSettings,mod,override_fields,- fp8_storage_applies=False,+ config=config,)case _:passdiff --git a/tests/backend/model_manager/configs/test_identified_default_settings.py b/tests/backend/model_manager/configs/test_identified_default_settings.pyindex fa035300ea..5f06cd2941 100644--- a/tests/backend/model_manager/configs/test_identified_default_settings.py+++ b/tests/backend/model_manager/configs/test_identified_default_settings.py@@ -148,3 +148,53 @@ def test_an_install_setting_keeps_the_architectures_other_defaults(tmp_path: Patassert probed is not None and overridden is not Noneassert overridden.model_dump(exclude={"fp8_storage"}) == probed.model_dump(exclude={"fp8_storage"})+++def _anima_lllite_adapter(path: Path, weight_dtype: torch.dtype) -> Path:+ """The smallest file identification reads as an Anima ControlNet-LLLite adapter.++ Chosen because its loader is one of the seven that declare they do not implement FP8 Storage, and+ it is the cheapest of those to identify. No published LLLite adapter is float8 -- they are 8-66 MB+ bf16 files -- so this one is synthetic on purpose: the subject is the wiring, not the file.+ """+ save_file(+ {+ "lllite_conditioning1.conv1.weight": torch.zeros(8, 3, 4, 4).to(weight_dtype),+ "lllite_dit_blocks_0.down.weight": torch.zeros(4, 8).to(weight_dtype),+ },+ str(path),+ )+ return path+++def test_fp8_storage_is_not_enabled_for_a_model_whose_loader_ignores_it(tmp_path: Path) -> None:+ """The float8 probe is not the whole question, and used to be treated as though it were.++ A Wan fp8 checkpoint or an Anima LLLite adapter is float8 on disk, so identification enabled FP8+ Storage; neither loader touched the setting, so the record promised half the memory and the load+ delivered none of it. `AnimaControlNetLLLiteModel` now declares `NotApplicable`, and identification+ asks (`load/fp8_capability.py`).+ """+ result = ModelConfigFactory.from_model_on_disk(+ _anima_lllite_adapter(tmp_path / "lllite.safetensors", torch.float8_e4m3fn), allow_unknown=False+ )++ assert result.config is not None and result.config.type is ModelType.ControlNet, result.details+ settings = result.config.default_settings+ assert (settings.fp8_storage if settings is not None else None) is None+++def test_an_explicit_install_request_is_dropped_for_such_a_model_too(tmp_path: Path) -> None:+ """Add Models has one FP8 Storage checkbox for whatever is being installed, so the request arrives+ for models that cannot use it. Storing it would leave a value the detail panel no longer shows and+ therefore nobody can clear; the install's other settings are untouched."""+ result = ModelConfigFactory.from_model_on_disk(+ _anima_lllite_adapter(tmp_path / "lllite.safetensors", torch.bfloat16),+ {"default_settings": {"fp8_storage": True, "preprocessor": "canny_edge_detection"}},+ allow_unknown=False,+ )++ assert result.config is not None, result.details+ assert result.config.default_settings is not None+ assert result.config.default_settings.fp8_storage is None+ assert result.config.default_settings.preprocessor == "canny_edge_detection"