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): leave FP8 Storage off when installing an MXFP8 checkpoint (#10289)
Alexander Eichhornc60c6c938b8b
diff --git a/docs/src/content/docs/Users Guide/03.Models/02.model-families.mdx b/docs/src/content/docs/Users Guide/03.Models/02.model-families.mdxindex bf7a5d588c..e944e7979a 100644--- a/docs/src/content/docs/Users Guide/03.Models/02.model-families.mdx+++ b/docs/src/content/docs/Users Guide/03.Models/02.model-families.mdx@@ -51,7 +51,7 @@ InvokeAI recognizes the format from the file's contents, so you install them lik- **int4** (`convrot_w4a4` or `int4_tensorwise`, ComfyUI repackages that usually keep some layers int8): the weights stay packed in memory at half a byte each and are unpacked per layer, on every device. This saves memory, not time: InvokeAI unpacks the weights for every step rather than running 4-bit matrix kernels, and 4-bit weights keep less detail than int8. Supported for the Krea-2 transformer.- **nvfp4** (4-bit, in ComfyUI's checkpoint format, such as Comfy-Org's builds; other nvfp4 exports such as AWQ are refused): the weights stay packed in memory and are unpacked per layer, so no special GPU is needed. Supported for the FLUX.3, Z-Image, Krea-2, Qwen-Image and LTX-2 transformers and for the Qwen3, Qwen3-VL 4B/8B, Qwen2.5-VL and FLUX.2 Mistral encoders; for FLUX.3 also Black Forest Labs' own nvfp4 build, in NVIDIA ModelOpt's layout. InvokeAI refuses FLUX.1, FLUX.2, Ideogram 4 and Qwen-Image-2.1 nvfp4 transformer checkpoints at install.- **fp8** (plain or `fp8_scaled`): a transformer keeps its weights in fp8 when [FP8 Storage](/configuration/optimization/fp8-storage/) is on, which installation does for you, or when `fp8_compute` is enabled. The single-file T5, Qwen3, Qwen3-VL, Qwen2.5-VL and FLUX.2 Mistral text encoders have neither setting: they keep their fp8 layers on their own on a GPU that can store fp8, and are widened elsewhere.-- **MXFP8** (fp8 with one scale per block of 32 weights): loaded by unpacking to BF16. Turn FP8 Storage off for these, except on Wan 2.2; see the [FP8 Storage caution](/configuration/optimization/fp8-storage/).+- **MXFP8** (fp8 with one scale per block of 32 weights): loaded by unpacking to BF16. FP8 Storage is opt-in for a file that is MXFP8 throughout and costs quality there, except on Wan 2.2; see the [FP8 Storage caution](/configuration/optimization/fp8-storage/).Text encoders for T5, Qwen-Image, Z-Image, Krea-2, FLUX.3, Ideogram 4, Qwen-Image-2.1 and MOSS-Image bring their tokenizer and configuration with InvokeAI, so single-file and GGUF encoders load without network access.diff --git a/docs/src/content/docs/configuration/Optimization/fp8-storage.mdx b/docs/src/content/docs/configuration/Optimization/fp8-storage.mdxindex 5c7bb2f264..fc2bcc8064 100644--- a/docs/src/content/docs/configuration/Optimization/fp8-storage.mdx+++ b/docs/src/content/docs/configuration/Optimization/fp8-storage.mdx@@ -1,7 +1,7 @@---title: FP8 Storagedescription: Halve a full-precision model's VRAM by keeping its weights in FP8 on the GPU, per model, from the Model Manager.-lastUpdated: 2026-11-15+lastUpdated: 2026-11-27sidebar:order: 3---@@ -19,11 +19,11 @@ low-VRAM mode streams layers between RAM and VRAM, FP8 Storage shrinks the layerquantized downloads is in the [format comparison](/configuration/optimization/memory-options/#format-comparison).To also run the math in FP8 on the GPU's FP8 hardware, see [FP8 Compute](/configuration/optimization/fp8-compute/).-:::caution[Turn it off for MXFP8 checkpoints]-Installing switches FP8 Storage on for every checkpoint that stores FP8 weights, MXFP8 included. For MXFP8 it costs-quality: see [By file format](#by-file-format). Turn it off under **Default Settings** after installing one. Wan 2.2 is-the exception: its loader leaves at the compute dtype every layer it unpacks with its scale, so on an MXFP8 Wan file-the setting only stores the layers that shipped without a scale as fp8, as it does for any other checkpoint.+:::caution[MXFP8 checkpoints]+A file whose fp8 weights are all MXFP8 is opt-in, like full precision: installing does not switch FP8 Storage on for+it, and switching it on costs quality. A file that also holds scaled fp8 layers keeps the default on, because it costs+nothing there. See [By file format](#by-file-format).+Wan 2.2 is the exception: its loader leaves at the compute dtype every layer it unpacks with its scale, so on an MXFP8 Wan file the setting only stores the layers that shipped without a scale as fp8, as it does for any other checkpoint.:::## What it applies to@@ -39,7 +39,8 @@ nothing, and the log says so once when the model loads:| --- | --- || Full precision (FP16, BF16, FP32) | **Yes**: what it is for. || fp8 or scaled fp8 checkpoint | **On after install.** The weights stay in fp8 with their own scale; without the setting they would be unpacked to BF16 at twice the size. See [Checkpoints that are already FP8](#checkpoints-that-are-already-fp8). |-| MXFP8 checkpoint | **Turn it off.** It stores one scale per block of 32 weights, which InvokeAI does not keep on any GPU: the layers are unpacked at load, and FP8 Storage then re-encodes them as fp8 *without* a scale: blocks whose scale is far below 1 lose their weights to underflow. If the file also has per-tensor fp8 layers, those stay fp8 and FP8 Storage changes nothing. Wan 2.2 does not re-encode the unpacked layers, so turning it off is not needed there. |+| MXFP8 checkpoint (every fp8 weight is MXFP8) | **Off after install; switching it on costs quality.** It stores one scale per block of 32 weights, which InvokeAI does not keep on any GPU: the layers are unpacked at load, and FP8 Storage then re-encodes them as fp8 *without* a scale: blocks whose scale is far below 1 lose their weights to underflow. Wan 2.2 does not re-encode the unpacked layers, so switching it on costs no quality there, and it stays on after install. |+| MXFP8 layers beside scaled fp8 layers | **On after install; keep it on.** The scaled layers stay in fp8 with their own scale, so the model already holds fp8 weights and the cast that would re-encode the MXFP8 layers is skipped. With it off (and FP8 Compute off) the scaled layers are unpacked to BF16 at twice the size. || int8 and int4 single files | **No.** Their quantized layers stay as stored and their other layers stay in the precision the build ships. Those are the layers the build leaves dense (timestep, input and output layers, modulations, text paths), and FP8 Storage would re-encode them without a scale. Measured on the published files, that zeroes 43% of the weights of Krea-2 Turbo's output layer and 95% of MOSS-Image int8's timestep layer, for a saving of 0–7% of the model's size. The setting can still show for these files, since they are the same kind of file as a full-precision one, but it does nothing there. || nvfp4 single files | **Off after install; your choice.** Their nvfp4 layers stay as stored. Turned on, FP8 Storage stores the layers the build ships in full precision in FP8, which saves 4–16% of the model's size (about 4% on Krea-2, 16% on Z-Image). Small weights there can round to zero, but in InvokeAI's measurements the nvfp4 images did not visibly change. FLUX.3 and LTX-2 nvfp4 files ignore the setting. || nvfp4 file with scaled fp8 layers (Qwen-Image's nvfp4 build) | **On after install; keep it on.** Its fp8 layers stay in fp8 with their own scale; unpacked to BF16 they would add about 10.5 GiB. As on Qwen-Image's other scaled fp8 files, its remaining full-precision layers are stored in FP8 too. |@@ -179,7 +180,7 @@ adapters. For small SD1 and SD2 models the savings are negligible and not worth| A checkpoint whose transformer or UNet stores FP8 weights | **On automatically.** InvokeAI reads the weight types from the file, not its name, so a full-precision file with "fp8" in its name is not affected. Only the denoiser counts: an all-in-one checkpoint with an FP8 text encoder beside a full-precision UNet or transformer is left alone. The log says `denoiser weights are stored in float8, enabling FP8 Storage by default`. || A scaled fp8 checkpoint | **On automatically**, and it costs no precision: the weights stay exactly as published, with their scale. || An nvfp4 checkpoint | **Off unless the denoiser also stores float8 weights**, as Qwen-Image's nvfp4 file with scaled fp8 layers does. The fp8 block scales of the nvfp4 format alone do not switch it on; turn it on yourself to store the full-precision layers in FP8 (FLUX.3 and LTX-2 ignore it). If it is already on for an nvfp4 model, it stores those layers in FP8 until you turn it off. |-| An MXFP8 checkpoint | **On automatically, but turn it off**: it costs quality (see [By file format](#by-file-format)). Wan 2.2 is the exception, see above. |+| An MXFP8 checkpoint whose fp8 weights are all MXFP8 | **Off**, like a full-precision file: switching it on costs quality (see [By file format](#by-file-format)). A model installed before this rule may have it stored as on; turn it off under **Default Settings**. Wan 2.2 is the exception, see above. A file that also holds scaled fp8 layers is on automatically, like any scaled fp8 file. || Anything else, from a file path, URL or Hugging Face repo, or from folder scan results | **Tick FP8 storage** next to the install source. It applies to the models from there that support it; for the others the request is dropped, so no model is recorded with a setting that does nothing, except a quantized single file that ignores the setting ([By file format](#by-file-format)), which keeps the request recorded. Starter models don't offer it. |Either way the setting stays editable under **Default Settings**, and re-identifying a model keeps it.diff --git a/docs/src/content/docs/configuration/Optimization/memory-options.mdx b/docs/src/content/docs/configuration/Optimization/memory-options.mdxindex 00f04c0de1..76d0a94e99 100644--- a/docs/src/content/docs/configuration/Optimization/memory-options.mdx+++ b/docs/src/content/docs/configuration/Optimization/memory-options.mdx@@ -55,10 +55,11 @@ With an fp8 checkpoint, `fp8_compute: true` runs it on the GPU's FP8 tensor corean AMD GPU that passes Invoke's FP8 test (it falls back by itself otherwise). Images change, and only repeat at the same seed while themodel is fully in VRAM. [FP8 Compute](/configuration/optimization/fp8-compute/).</MemoryOption>-<MemoryOption id="mxfp8-off" title="Turn FP8 Storage off for MXFP8 checkpoints">-With an MXFP8 checkpoint on an NVIDIA, AMD or Intel GPU: installing switches FP8 Storage on, but for MXFP8 it-re-encodes the weights without their scales and costs quality. Turn it off under **Default Settings** in the Model-Manager. [By file format](/configuration/optimization/fp8-storage/#by-file-format).+<MemoryOption id="mxfp8-off" title="Leave FP8 Storage off for MXFP8 checkpoints">+With an MXFP8 checkpoint on an NVIDIA, AMD or Intel GPU, when every fp8 weight in it is MXFP8 (scaled or unscaled+fp8 layers beside them keep the default on): installing leaves FP8 Storage off, because for MXFP8 it+re-encodes the weights without their scales and costs quality. If an earlier install left it on, turn it off under+**Default Settings** in the Model Manager. [By file format](/configuration/optimization/fp8-storage/#by-file-format).</MemoryOption><MemoryOption id="int8-compute" title="Turn on int8 Compute for a speedup">With an int8 build on an NVIDIA RTX 30-series or newer GPU, `int8_compute: true` runs it on the int8 tensor cores: updiff --git a/invokeai/backend/model_manager/configs/factory.py b/invokeai/backend/model_manager/configs/factory.pyindex 77cd5fc47f..420fb93be5 100644--- a/invokeai/backend/model_manager/configs/factory.py+++ b/invokeai/backend/model_manager/configs/factory.py@@ -252,6 +252,7 @@ from invokeai.backend.model_manager.taxonomy import (ModelType,variant_type_adapter,)+from invokeai.backend.quantization.fp8_scaled import header_is_mxfp8from invokeai.backend.quantization.gguf.loaders import COMFY_QUANT_KEY_PREFIX, parse_gguf_convrot_markerslogger = logging.getLogger(__name__)@@ -267,7 +268,7 @@ _DENOISER_SUBFOLDERS = frozenset({"transformer", "unet"})SettingsT = TypeVar("SettingsT", bound=BaseModel)-def _denoiser_stores_float8_weights(mod: ModelOnDisk) -> bool:+def _denoiser_stores_float8_weights(mod: ModelOnDisk, *, mxfp8_is_lossy: bool = True) -> bool:"""Whether the denoiser's weights are stored in a float8 the storage cast can reproduce, judged by the safetensorsheaders and never by a file name.@@ -284,6 +285,13 @@ def _denoiser_stores_float8_weights(mod: ModelOnDisk) -> bool:layers the file ships in full precision, a lossy trade rather than the lossless keep a scaled-fp8 file gets, soit is left to the user instead of switched on. An nvfp4 file that also stores scaled fp8 weights (Qwen-Image'snvfp4 build) still counts.++ A file whose fp8 weights all carry an MX block-scale grid (MXFP8, `header_is_mxfp8`) does not count either. The+ loaders unpack its block-scaled layers to bf16, and FP8 Storage would cast them back to fp8 without the block+ scale: blocks whose scale is far below 1 flush to zero. Like bf16, it is left to the user, who can still switch it+ on knowingly. A file that mixes MX layers with scaled fp8 layers still counts: its scaled layers stay packed, the+ model then holds fp8 weights and the cast is skipped, so the MX layers are never re-encoded. `mxfp8_is_lossy` is+ False for Wan, whose loader never re-encodes a layer it unpacked with its scale."""if mod.path.is_file():candidates = [mod.path]@@ -295,6 +303,7 @@ def _denoiser_stores_float8_weights(mod: ModelOnDisk) -> bool:]stores_float8 = False+ denoiser_header: dict[str, Any] = {}for path in candidates:if path.suffix != ".safetensors":continue@@ -304,12 +313,13 @@ def _denoiser_stores_float8_weights(mod: ModelOnDisk) -> bool:logger.debug(f"Could not read the safetensors header of {path} to look for float8 weights: {e}")continuedenoiser = {key: info for key, info in header.items() if not key.startswith(_BUNDLED_COMPONENT_KEY_PREFIXES)}+ denoiser_header.update(denoiser)stores_float8 = stores_float8 or any(isinstance(info, dict) and info.get("dtype") in _FP8_SAFETENSORS_DTYPESfor key, info in denoiser.items()if not key.endswith("_scale"))- return stores_float8+ return stores_float8 and not (mxfp8_is_lossy and header_is_mxfp8(denoiser_header))def _identified_default_settings(@@ -348,7 +358,12 @@ def _identified_default_settings(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):+ elif "fp8_storage" not in update and _denoiser_stores_float8_weights(+ # Wan is lossless: `_load_from_singlefile` in load/model_loaders/wan.py passes a `skip=` that keeps every scaled+ # layer out of the cast.+ mod,+ mxfp8_is_lossy=config.base != BaseModelType.Wan,+ ):logger.info(f"{mod.name}: denoiser weights are stored in float8, enabling FP8 Storage by default")update["fp8_storage"] = Truediff --git a/invokeai/backend/quantization/fp8_scaled.py b/invokeai/backend/quantization/fp8_scaled.pyindex ae454cc5d7..4621c19321 100644--- a/invokeai/backend/quantization/fp8_scaled.py+++ b/invokeai/backend/quantization/fp8_scaled.py@@ -479,6 +479,47 @@ def _usable_input_scale(scale: torch.Tensor | None) -> torch.Tensor | None:_MX_SCALE_DTYPES = tuple(dtype for dtype in (torch.uint8, getattr(torch, "float8_e8m0fnu", None)) if dtype is not None)+# The same two spellings as `_MX_SCALE_DTYPES`, as safetensors header names.+_MX_SCALE_HEADER_DTYPES = frozenset({"U8", "F8_E8M0"})+_FP8_HEADER_DTYPES = frozenset({"F8_E4M3", "F8_E5M2"})+++def header_is_mxfp8(header: Mapping[str, Any]) -> bool:+ """Whether every fp8 weight in a safetensors header (``read_safetensors_header``) carries an MX scale grid.++ An MX layer is an fp8 ``<layer>.weight`` beside an exponent-grid weight scale (``.weight_scale`` or+ ``.scale_weight``): a 2-D ``uint8`` (or E8M0) tensor with one row per weight row and one entry per+ :data:`MXFP8_BLOCK_SIZE` columns, the shape :func:`decode_mx_block_scales` requires. The ``comfy_quant`` marker that+ names the format is tensor data, which a header read cannot see. A producer that writes this layout without naming+ it does not load at all, so the layout is enough to go on here.++ A file that also holds an fp8 weight with a per-tensor or per-row scale, or none, is not MXFP8 in this sense: the+ loaders keep such a layer packed with its scale, which makes the model hold fp8 weights and skips the layerwise+ cast, so the MX layers are never re-encoded either. False when the header has no fp8 weight.+ """+ scales = dict(iter_weight_scale_pairs(header))+ fp8_weights = [+ key+ for key, info in header.items()+ if key.endswith(".weight") and isinstance(info, dict) and info.get("dtype") in _FP8_HEADER_DTYPES+ ]+ return bool(fp8_weights) and all(_has_mx_scale_grid(header, key, scales.get(key)) for key in fp8_weights)+++def _has_mx_scale_grid(header: Mapping[str, Any], weight_key: str, scale_key: str | None) -> bool:+ scale = header.get(scale_key) if scale_key is not None else None+ if not isinstance(scale, dict) or scale.get("dtype") not in _MX_SCALE_HEADER_DTYPES:+ return False+ weight_shape, scale_shape = header[weight_key].get("shape"), scale.get("shape")+ return (+ isinstance(weight_shape, list)+ and isinstance(scale_shape, list)+ and len(weight_shape) == len(scale_shape) == 2+ and scale_shape[0] == weight_shape[0]+ and scale_shape[1] * MXFP8_BLOCK_SIZE == weight_shape[1]+ )++def unparsed_fp8_scale_keys(sd: Mapping[str, Any]) -> list[str]:"""The scale keys beside an fp8 weight in a spelling this module does not parse, such as ``.weight_scale_inv``.diff --git a/tests/backend/model_manager/configs/test_identified_default_settings.py b/tests/backend/model_manager/configs/test_identified_default_settings.pyindex bcdcc06460..a0f86cf20d 100644--- a/tests/backend/model_manager/configs/test_identified_default_settings.py+++ b/tests/backend/model_manager/configs/test_identified_default_settings.py@@ -15,10 +15,18 @@ import pytestimport torchfrom safetensors.torch import save_file-from invokeai.backend.model_manager.configs.factory import ModelConfigFactory-from invokeai.backend.model_manager.configs.main import Main_Checkpoint_QwenImage_Config+from invokeai.backend.model_manager.configs.default_settings import MainModelDefaultSettings+from invokeai.backend.model_manager.configs.factory import ModelConfigFactory, _identified_default_settings+from invokeai.backend.model_manager.configs.main import Main_Checkpoint_QwenImage_Config, Main_Checkpoint_Wan_Config+from invokeai.backend.model_manager.model_on_disk import ModelOnDiskfrom invokeai.backend.model_manager.taxonomy import ModelType-from tests.fixtures.quantized_payloads import comfy_quant_marker, nvfp4_codes, nvfp4_tensors+from tests.fixtures.quantized_payloads import (+ comfy_quant_marker,+ mxfp8_marker,+ mxfp8_tensors,+ nvfp4_codes,+ nvfp4_tensors,+)_DIFFUSERS_FIXTURE = Path(__file__).parents[1] / "data" / "test_files" / "test-diffusers-main"@@ -102,6 +110,75 @@ def test_an_nvfp4_file_that_also_stores_float8_weights_gets_it(tmp_path: Path) -assert config.default_settings.fp8_storage is True+def _mxfp8_img_in(scale_suffix: str = "weight_scale") -> dict[str, torch.Tensor]:+ mx, _ = mxfp8_tensors("img_in", torch.full((128, 4), 127.0))+ tensors = {key: value for key, value in mx.items() if not key.startswith("img_in.weight_scale")}+ tensors[f"img_in.{scale_suffix}"] = mx["img_in.weight_scale"]+ tensors["img_in.comfy_quant"] = comfy_quant_marker(mxfp8_marker())+ return tensors+++def _mxfp8_only_checkpoint(path: Path, scale_suffix: str = "weight_scale") -> Path:+ """Every fp8 weight is an MXFP8 layer; `txt_in` stays bf16."""+ return _qwen_image_checkpoint(path, torch.bfloat16, **_mxfp8_img_in(scale_suffix))++[email protected]("scale_suffix", ["weight_scale", "scale_weight"])+def test_a_file_whose_fp8_weights_are_all_mxfp8_is_left_to_the_user(tmp_path: Path, scale_suffix: str) -> None:+ """The loaders unpack MXFP8 layers to bf16, and with nothing else fp8 in the file FP8 Storage would re-encode them+ as fp8 without the block scale, flushing blocks with a small scale to zero. Switching it on stays possible."""+ path = _mxfp8_only_checkpoint(tmp_path / "qwen_image_mxfp8.safetensors", scale_suffix)++ config = _identify(path)+ forced = _identify(path, {"default_settings": {"fp8_storage": True}})++ assert config.default_settings is None or config.default_settings.fp8_storage is None+ assert forced.default_settings is not None and forced.default_settings.fp8_storage is True+++def test_wan_keeps_fp8_storage_on_for_an_mxfp8_file(tmp_path: Path) -> None:+ """Wan's loader leaves every layer it unpacked with its scale at the compute dtype, so FP8 Storage re-encodes none+ of the MX layers there and the default stays on."""+ mod = ModelOnDisk(_mxfp8_only_checkpoint(tmp_path / "wan_mxfp8.safetensors"))+ wan = Main_Checkpoint_Wan_Config.model_construct(name="wan_mxfp8")+ qwen = Main_Checkpoint_QwenImage_Config.model_construct(name="qwen_mxfp8")++ wan_settings = _identified_default_settings(None, MainModelDefaultSettings, mod, None, config=wan)+ qwen_settings = _identified_default_settings(None, MainModelDefaultSettings, mod, None, config=qwen)++ assert wan_settings is not None and wan_settings.fp8_storage is True+ assert qwen_settings is None or qwen_settings.fp8_storage is None+++def test_a_file_mixing_mxfp8_and_scaled_fp8_layers_keeps_fp8_storage_on(tmp_path: Path) -> None:+ """The scaled fp8 layer stays packed with its scale, so the model holds fp8 weights and the layerwise cast is+ skipped: the MX layers are not re-encoded and the setting only saves the scaled layer's VRAM."""+ path = _qwen_image_checkpoint(+ tmp_path / "qwen_image_mixed.safetensors",+ torch.float8_e4m3fn,+ **_mxfp8_img_in(),+ **{"txt_in.weight_scale": torch.ones(1)},+ )++ config = _identify(path)++ assert config.default_settings is not None+ assert config.default_settings.fp8_storage is True+++def test_a_file_with_an_unscaled_fp8_weight_beside_mxfp8_layers_keeps_fp8_storage_on(tmp_path: Path) -> None:+ path = _qwen_image_checkpoint(+ tmp_path / "qwen_image_mixed_unscaled.safetensors",+ torch.float8_e4m3fn,+ **_mxfp8_img_in(),+ )++ config = _identify(path)++ assert config.default_settings is not None+ assert config.default_settings.fp8_storage is True++def test_a_full_precision_file_named_fp8_is_left_alone(tmp_path: Path) -> None:config = _identify(_qwen_image_checkpoint(tmp_path / "qwen_image_fp8_scaled.safetensors", torch.bfloat16))