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.

feat(models): auto-enable FP8 Storage for scaled fp8 checkpoints too

Alexander Eichhornc826c5d30896
diff --git a/docs/src/content/docs/configuration/fp8-storage.mdx b/docs/src/content/docs/configuration/fp8-storage.mdx
index 145c795c0b..8cfbe7d6a2 100644
--- a/docs/src/content/docs/configuration/fp8-storage.mdx
+++ b/docs/src/content/docs/configuration/fp8-storage.mdx
@@ -11,7 +11,7 @@ FP8 Storage cuts a model's VRAM footprint roughly in half by keeping weights on
It pairs well with [Low-VRAM mode](/configuration/low-vram-mode/): low-VRAM mode streams layers between RAM and VRAM, while FP8 Storage shrinks the layers themselves.
:::caution[For full precision models only]
-FP8 Storage only applies to **full precision** checkpoints (FP16 / BF16 / FP32). It is **silently a no-op** for already-quantized formats — **GGUF**, **NF4**, **int8**, and [**SDNQ**](/configuration/sdnq-quantization/) checkpoints carry their own storage precision and the loader returns a different module type that the FP8 layer cast does not touch. If your model is already quantized, the toggle has no effect; use the full-precision variant of the model if you want to enable FP8 Storage. Checkpoints that store plain FP8 weights are the exception: InvokeAI loads them at BF16 unless FP8 Storage is on, so they get it automatically when installed. Checkpoints that store *scaled* FP8 are left alone — see [When installing](#when-installing) for both cases.
+FP8 Storage only applies to **full precision** checkpoints (FP16 / BF16 / FP32). It is **silently a no-op** for already-quantized formats — **GGUF**, **NF4**, **int8**, and [**SDNQ**](/configuration/sdnq-quantization/) checkpoints carry their own storage precision and the loader returns a different module type that the FP8 layer cast does not touch. If your model is already quantized, the toggle has no effect; use the full-precision variant of the model if you want to enable FP8 Storage. Checkpoints that store FP8 weights are the exception: InvokeAI loads them at BF16 unless FP8 Storage is on, so they get it automatically when installed (see [When installing](#when-installing)).
:::
## Requirements
@@ -56,8 +56,8 @@ The setting takes effect on the next load. If the model is already in the cache,
### When installing
-- **Checkpoints that store plain FP8 weights get FP8 Storage automatically.** InvokeAI reads the weight types from the file while identifying the model, 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. Without this, an FP8 checkpoint would be loaded at BF16 and take twice the VRAM.
-- **"Scaled" FP8 checkpoints are deliberately left alone.** Their weights mean nothing without the per-tensor scale stored next to them, and FP8 Storage has no scale to apply: the loader folds the scale into the weight, and the cast then rounds that to *unscaled* FP8. On FLUX.2 Klein 4B that rounds 3.4% of the weights to zero — the scales are around 1e-3, so the loss is underflow rather than clipping — and it saves nothing, because the file was already one byte per weight. You can still switch it on yourself; [FP8 Compute](#fp8-compute) is the setting that keeps these files exactly as they are.
+- **Checkpoints that already store FP8 weights get FP8 Storage automatically.** InvokeAI reads the weight types from the file while identifying the model, 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. Without this, an FP8 checkpoint would be loaded at BF16 and take twice the VRAM.
+- **"Scaled" FP8 checkpoints are included.** Their weights only mean something together with the per-tensor scale stored beside them, and the loader keeps them in exactly that form, so the setting costs no precision at all — it simply stops InvokeAI from unpacking the file to twice its size.
- **For any other model, tick FP8 storage next to the install source** (a file path, URL or HuggingFace repo, and in folder scan results). It applies to the models you install from there.
Either way the setting stays editable under **Default Settings** afterwards. Re-identifying a model resets its default settings, including this one, to what identification chooses.
@@ -123,7 +123,7 @@ If you see unexpected quality regressions, disable FP8 Storage on the affected m
Everything above describes FP8 *Storage*, which changes how weights are **stored** while the math still runs in BF16. `fp8_compute` is a separate, global setting in `invokeai.yaml` that also does the **math** in FP8, on GPUs that have hardware for it. That makes generation faster, not just smaller.
-It is for models that were **already saved in FP8** by whoever published them — you'll often see these labelled "fp8" or "fp8_scaled" in the filename. Without it InvokeAI unpacks them to BF16 while loading, and FP8 Storage keeps them FP8 in VRAM (plain FP8 files get it automatically when installed, scaled ones do not — see [When installing](#when-installing)); with `fp8_compute` on, they stay as they are and run directly on the GPU's FP8 hardware, and FP8 Storage has nothing left to do for those layers.
+It is for models that were **already saved in FP8** by whoever published them — you'll often see these labelled "fp8" or "fp8_scaled" in the filename. Without it InvokeAI unpacks them to BF16 while loading, and FP8 Storage keeps them FP8 in VRAM (they get it automatically when installed); with `fp8_compute` on, they stay as they are and run directly on the GPU's FP8 hardware, and FP8 Storage has nothing left to do for those layers.
Not every part of a model stays in FP8 — the small, precision-sensitive pieces are always unpacked. Those are a tiny share of the weights, so you still get nearly the full VRAM saving.
diff --git a/invokeai/backend/model_manager/configs/factory.py b/invokeai/backend/model_manager/configs/factory.py
index dd4b17f252..6ea316377f 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.taxonomy import (
ModelType,
variant_type_adapter,
)
-from invokeai.backend.quantization.fp8_scaled import is_scale_metadata_key
logger = logging.getLogger(__name__)
@@ -209,12 +208,10 @@ def _denoiser_stores_float8_weights(mod: ModelOnDisk) -> bool:
Only headers are read, a few KB each. A header that cannot be read is no evidence of float8 weights: identification
did not need that file, and picking a default setting is no reason to fail an install.
- A *scaled* fp8 checkpoint is deliberately excluded. Its weights mean nothing without the per-tensor scale stored
- beside them, and FP8 Storage has no scale to apply: the loader folds the scale into the weight and hands the cast
- plain bf16, which then rounds to *unscaled* fp8. Measured on `flux-2-klein-4b-fp8`, that flushes 3.4% of the
- weights to exactly zero -- by underflow, the scales being ~1e-3, not by saturation -- for 2-4% relative L2 error
- per layer, and it buys nothing: the file already was one byte per weight. Keeping such a file in its own scaled
- form is the lossless way to spend that byte, but that is a loader change rather than a default setting.
+ Scaled fp8 checkpoints count too. They briefly did not: FP8 Storage used to fold their per-tensor scales away and
+ let the layerwise cast re-encode the result as *unscaled* fp8, which on `flux-2-klein-4b-fp8` flushed 3.4% of the
+ weights to zero for the byte count the file already had. The loaders now keep such a file in its own scaled form
+ instead, so switching the setting on is lossless and worth doing by default.
"""
if mod.path.is_file():
candidates = [mod.path]
@@ -235,10 +232,6 @@ 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}")
continue
denoiser = {key: info for key, info in header.items() if not key.startswith(_BUNDLED_COMPONENT_KEY_PREFIXES)}
- if any(is_scale_metadata_key(key) for key in denoiser):
- return False
- # No early return on a float8 hit: a sharded denoiser can keep its scales in a shard of its own, and finding
- # them there still means the whole checkpoint is scaled.
stores_float8 = stores_float8 or any(
isinstance(info, dict) and info.get("dtype") in _FP8_SAFETENSORS_DTYPES for info in denoiser.values()
)
diff --git a/tests/backend/model_manager/configs/test_identified_default_settings.py b/tests/backend/model_manager/configs/test_identified_default_settings.py
index be791ae2d6..fa035300ea 100644
--- a/tests/backend/model_manager/configs/test_identified_default_settings.py
+++ b/tests/backend/model_manager/configs/test_identified_default_settings.py
@@ -1,8 +1,8 @@
"""The default settings a model is identified with.
-FP8 Storage is switched on for a checkpoint whose denoiser weights are stored in *unscaled* float8, read from the
-weights' dtypes and the scale keys beside them, never from the file name: a full-precision file somebody named
-"fp8_scaled" and a genuinely scaled fp8 checkpoint must both come out right. Settings passed along with an install land on top of what identification chose.
+FP8 Storage is switched on for a checkpoint whose denoiser weights are stored in float8, read from the weights'
+dtypes and never from the file name: a Comfy "fp8_scaled" file that nobody renamed and a full-precision file that
+somebody did must both come out right. Settings passed along with an install land on top of what identification chose.
Single files are tiny Qwen-Image checkpoints, the smallest main model identification recognises from real keys. Folders
are the installer's SDXL diffusers fixture, whose placeholder weight files have no readable header at all.
@@ -48,14 +48,13 @@ def test_float8_denoiser_weights_turn_fp8_storage_on_whatever_the_file_is_called
@pytest.mark.parametrize("scale_key", ["img_in.weight_scale", "img_in.scale_weight"])
-def test_a_scaled_fp8_checkpoint_is_left_alone(tmp_path: Path, scale_key: str) -> None:
- """Comfy's fp8_scaled weights mean nothing without the per-tensor scale stored beside them, and the storage cast
- has none to apply: the loader folds the scale into the weight and the cast rounds that to *unscaled* fp8. Measured
- on `flux-2-klein-4b-fp8`, that flushes 3.4% of the weights to exactly zero -- underflow, the scales being ~1e-3 --
- for 2-4% relative L2 error per layer, and it saves nothing: the file already was one byte per weight.
-
- Both spellings of the scale key are checked because matching only `.weight_scale` is the miss that keeps recurring
- (see `iter_weight_scale_pairs`).
+def test_a_scaled_fp8_checkpoint_gets_it_too(tmp_path: Path, scale_key: str) -> None:
+ """A Comfy "scaled fp8" file is float8 on disk like any other, and the loaders keep it in exactly that form when
+ the setting is on -- scale included -- so there is nothing to protect it from. It briefly was excluded, back when
+ storage folded the scale away and re-encoded the result unscaled.
+
+ Both spellings of the scale key are exercised because matching only `.weight_scale` is the miss that keeps
+ recurring (see `iter_weight_scale_pairs`).
"""
path = _qwen_image_checkpoint(
tmp_path / "qwen_image.safetensors",
@@ -65,7 +64,8 @@ def test_a_scaled_fp8_checkpoint_is_left_alone(tmp_path: Path, scale_key: str) -
config = _identify(path)
- assert config.default_settings is None or config.default_settings.fp8_storage is None
+ 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: