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(quantization): keep Comfy nvfp4 Krea-2 transformers packed

Alexander Eichhornee846d2c0b64
diff --git a/invokeai/backend/model_manager/load/model_loaders/krea2.py b/invokeai/backend/model_manager/load/model_loaders/krea2.py
index 96ea1a0c70..8df31b263a 100644
--- a/invokeai/backend/model_manager/load/model_loaders/krea2.py
+++ b/invokeai/backend/model_manager/load/model_loaders/krea2.py
@@ -30,6 +30,7 @@ from invokeai.backend.model_manager.taxonomy import (
)
from invokeai.backend.model_manager.util.qwen3_vl import normalize_qwen3vl_rope_config
from invokeai.backend.quantization.fp8_scaled import (
+ INPUT_SCALE_SUFFIXES,
attach_fp8_scales,
cast_state_dict,
dequantize_fp8_scaled,
@@ -58,6 +59,12 @@ from invokeai.backend.quantization.int8_convrot import (
split_int8_convrot_layers,
swap_in_int8_linears,
)
+from invokeai.backend.quantization.nvfp4 import (
+ WEIGHT_SCALE_2_SUFFIX,
+ install_nvfp4_layers,
+ pop_nvfp4_layers,
+ predict_nvfp4_install_size,
+)
from invokeai.backend.util.devices import TorchDevice
# Kept as a module-level alias: this helper moved to model_manager.util.qwen3_vl so the MiniMax H3
@@ -149,11 +156,15 @@ DISCARDED_NATIVE_FINAL_KEYS = ("last.down", "last.up")
def _drop_discarded_native_final_layers(sd: dict[str, Any]) -> dict[str, Any]:
- """Remove the dropped final-block projections together with their quantization metadata."""
+ """Remove the dropped final-block projections together with their quantization metadata.
+
+ An nvfp4 layer's global scale and any activation scale go too: left behind without its weight, the nvfp4 pass
+ refuses a global scale as a malformed layer, and an activation scale would linger as an orphan.
+ """
doomed = {
f"{path}{suffix}"
for path in DISCARDED_NATIVE_FINAL_KEYS
- for suffix in (".weight", ".weight_scale", ".comfy_quant")
+ for suffix in (".weight", ".weight_scale", WEIGHT_SCALE_2_SUFFIX, ".comfy_quant", *INPUT_SCALE_SUFFIXES)
}
if not doomed & set(sd):
return sd
@@ -364,7 +375,8 @@ class Krea2CheckpointModel(ModelLoader):
The int8 build stays int8-resident: `swap_in_int8_linears` installs `Int8ConvrotLinear`, which
holds the stored codes and dequantizes per forward, so a 12.0 GiB checkpoint stays 12.0 GiB.
What it does not get is int8 *compute* -- that needs a kernel InvokeAI does not have yet -- so
- the saving here is resident memory, not speed.
+ the saving here is resident memory, not speed. ComfyUI's 'nvfp4' build, whose layers the
+ safetensors header names, stays packed the same way as `NVFP4Linear`.
"""
def _load_model(
@@ -400,6 +412,18 @@ class Krea2CheckpointModel(ModelLoader):
# implement; refusing a tensor that is on its way to the bin would be an odd way to fail.
sd = _drop_discarded_native_final_layers(sd)
+ # Comfy's nvfp4 build names its layers in the header, natively. Take them out before either side-channel
+ # format below reads a scale: both pair every `weight_scale` with its weight, and the key conversion would
+ # rename the packed codes without their global scale. `install_nvfp4_layers` puts them back, packed, under
+ # their diffusers paths once the model exists. The key scheme is read once, here, for the layers and for
+ # both branches below.
+ header_layers = strip_layer_path_prefix(parse_quantization_metadata(metadata))
+ native = _is_native_krea2_format(sd)
+ nvfp4_payloads = pop_nvfp4_layers(sd, header_layers=header_layers)
+ if nvfp4_payloads and native:
+ path_map = _remap_native_layer_paths(nvfp4_payloads)
+ nvfp4_payloads = {path_map.get(path, path): payload for path, payload in nvfp4_payloads.items()}
+
# Two ComfyUI side-channel formats reach this loader and a checkpoint carries one or the
# other, so the format is decided once here. `int8_tensorwise` has to be recognised before
# the key conversion below: that conversion renames `.weight` by substring and so carries a
@@ -418,7 +442,7 @@ class Krea2CheckpointModel(ModelLoader):
sd = drop_unconsumed_quantization_sidecars(sd)
# Native/ComfyUI key naming → diffusers Krea2Transformer2DModel keys.
key_map: dict[str, str] = {}
- if _is_native_krea2_format(sd):
+ if native:
sd = _convert_krea2_native_to_diffusers(sd, key_map=key_map)
quantized = resolve_quantized_module_paths(int8_markers, key_map)
else:
@@ -428,11 +452,8 @@ class Krea2CheckpointModel(ModelLoader):
# full_precision_matrix_mult layers silently multiplied in fp8. The header wins on the rare
# checkpoint carrying both. Header names carry the prefix that was just stripped off the
# state dict, so strip it from them too or they match nothing.
- layer_hints = {
- **extract_comfy_quant_hints(sd),
- **strip_layer_path_prefix(parse_quantization_metadata(metadata)),
- }
- if _is_native_krea2_format(sd):
+ layer_hints = {**extract_comfy_quant_hints(sd), **header_layers}
+ if native:
# Take the quantization side channel out before renaming. The converter renames
# ".weight"-suffixed keys by substring and five more by whole-key equality, so a sibling
# ".scale_weight", ".input_scale", or any scale on one of the equality-renamed keys
@@ -464,14 +485,18 @@ class Krea2CheckpointModel(ModelLoader):
with accelerate.init_empty_weights():
model = Krea2Transformer2DModel(**KREA2_TRANSFORMER_CONFIG)
+ # Honor the model's own precision-sensitive list on every path below. Krea-2 declares `time_embed` and the
+ # `norm*` modules; `time_embed.linear_1/linear_2` are ordinary quantized Linears in a ComfyUI export, and a
+ # module that reads its own weight's dtype finds a quantized dtype on a module left quantized.
+ skip_patterns = _model_declared_skip_patterns(model)
+ # A merged file's bundled submodels are not this model's: their dense weights fall to `strict=False` below,
+ # and their packed layers go the same way instead of naming no module. The rest are added to either
+ # reservation below as they will be held, since a reservation makes that much room rather than adding to one.
+ modules = {name for name, _ in model.named_children()}
+ nvfp4_payloads = {path: payload for path, payload in nvfp4_payloads.items() if path.split(".", 1)[0] in modules}
+ nvfp4_bytes = predict_nvfp4_install_size(model, nvfp4_payloads, model_dtype, skip_patterns)
if int8_markers:
- # Honor the model's own precision-sensitive list here too, not only on the fp8 side.
- # Krea-2 declares `time_embed` and the `norm*` modules; `time_embed.linear_1/linear_2`
- # are ordinary quantized Linears in a ComfyUI export, and a module that reads its own
- # weight's dtype finds `torch.int8` on an `Int8ConvrotLinear`.
- skip_patterns = _model_declared_skip_patterns(model)
-
# Before anything is cast: a scale left over from another scheme means its weight is
# about to be cast without it, and the orphan disappears into `strict=False` below.
# After the model exists, so a merged file's bundled submodels -- which this loader does
@@ -485,6 +510,7 @@ class Krea2CheckpointModel(ModelLoader):
# ~12 GB that this load never uses.
self._ram_cache.make_room(
predict_int8_cast_size(sd, model_dtype, quantized, model=model, skip_patterns=skip_patterns)
+ + nvfp4_bytes
)
quantized = split_int8_convrot_layers(sd, quantized, model_dtype, model=model, skip_patterns=skip_patterns)
cast_unquantized(sd, model_dtype, quantized)
@@ -493,7 +519,6 @@ class Krea2CheckpointModel(ModelLoader):
fp8_layers = {}
kept = 0
else:
- skip_patterns = _model_declared_skip_patterns(model)
# Scaled layers the cast would dequantize anyway (skip patterns, non-Linear weights) are
# folded here, with their scale applied. Left to `cast_state_dict` they would be cast
# *without* it and `attach_fp8_scales` would then skip them for no longer being fp8 —
@@ -513,6 +538,7 @@ class Krea2CheckpointModel(ModelLoader):
skip_patterns=skip_patterns,
scaled_layers=fp8_layers,
)
+ + nvfp4_bytes
)
fp8_layers = split_fp8_scaled_layers(sd, fp8_layers, model_dtype, model=model, skip_patterns=skip_patterns)
@@ -527,6 +553,10 @@ class Krea2CheckpointModel(ModelLoader):
skip_patterns=skip_patterns,
)
+ if nvfp4_payloads:
+ packed = install_nvfp4_layers(model, sd, nvfp4_payloads, model_dtype, skip_patterns)
+ self._logger.info(f"Krea-2: kept {packed} of {len(nvfp4_payloads)} nvfp4 layer(s) packed.")
+
model.load_state_dict(sd, assign=True, strict=False)
_reject_incomplete_load(model, what="Krea-2 single-file checkpoint")
# `assign=True` aliases every param to its `sd` tensor. Drop the dict's references before
diff --git a/invokeai/backend/model_manager/starter_models/__init__.py b/invokeai/backend/model_manager/starter_models/__init__.py
index 741e0d6b60..54813b09c2 100644
--- a/invokeai/backend/model_manager/starter_models/__init__.py
+++ b/invokeai/backend/model_manager/starter_models/__init__.py
@@ -129,6 +129,7 @@ from invokeai.backend.model_manager.starter_models.krea_2 import (
krea2_turbo,
krea2_turbo_gguf_q4_k_m,
krea2_turbo_gguf_q8_0,
+ krea2_turbo_nvfp4,
)
from invokeai.backend.model_manager.starter_models.minimax_h3 import (
minimax_h3_components,
@@ -398,6 +399,7 @@ STARTER_MODELS: list[StarterModel] = [
krea2_raw,
krea2_turbo_gguf_q4_k_m,
krea2_turbo_gguf_q8_0,
+ krea2_turbo_nvfp4,
qwen3_vl_encoder_4b,
wan_22_t5_encoder,
wan_22_a14b_vae,
@@ -565,6 +567,7 @@ krea2_bundle: list[StarterModel] = [
krea2_raw,
krea2_turbo_gguf_q4_k_m,
krea2_turbo_gguf_q8_0,
+ krea2_turbo_nvfp4,
]
# Wan 2.2 starter bundles. Split into T2V and I2V so users only pay for the
diff --git a/invokeai/backend/model_manager/starter_models/krea_2.py b/invokeai/backend/model_manager/starter_models/krea_2.py
index c45e934959..0305f66252 100644
--- a/invokeai/backend/model_manager/starter_models/krea_2.py
+++ b/invokeai/backend/model_manager/starter_models/krea_2.py
@@ -44,6 +44,19 @@ krea2_turbo_gguf_q4_k_m = StarterModel(
dependencies=[qwen_image_vae, qwen3_vl_encoder_4b],
)
+krea2_turbo_nvfp4 = StarterModel(
+ name="Krea-2 Turbo (NVFP4)",
+ base=BaseModelType.Krea2,
+ source="https://huggingface.co/Comfy-Org/Krea-2/resolve/main/diffusion_models/krea2_turbo_nvfp4.safetensors",
+ description="Krea-2 Turbo transformer in Comfy-Org's nvfp4 build: under a third of the full-precision "
+ "transformer's memory (~7.7GB), about the size of the Q4_K_M GGUF. It saves memory, not time - the weights are "
+ "decoded every step. Ships only the transformer, so the Qwen-Image VAE and Qwen3-VL encoder are installed as "
+ "dependencies.",
+ type=ModelType.Main,
+ variant=Krea2VariantType.Turbo,
+ dependencies=[qwen_image_vae, qwen3_vl_encoder_4b],
+)
+
krea2_turbo_gguf_q8_0 = StarterModel(
name="Krea-2 Turbo (Q8_0 GGUF)",
base=BaseModelType.Krea2,
diff --git a/tests/backend/model_manager/load/test_krea2_nvfp4_loader.py b/tests/backend/model_manager/load/test_krea2_nvfp4_loader.py
new file mode 100644
index 0000000000..f9fd7fcea9
--- /dev/null
+++ b/tests/backend/model_manager/load/test_krea2_nvfp4_loader.py
@@ -0,0 +1,188 @@
+"""Krea-2's single-file loader keeps Comfy's nvfp4 build packed.
+
+Comfy names the nvfp4 layers of `krea2_turbo_nvfp4.safetensors` in the safetensors header, in the native key scheme
+(`blocks.N.attn.wq`), and the loader renames native keys to diffusers ones. So what these tests pin is the order in
+the loader: the layers leave the state dict before the conversion and the scale handling of either side-channel
+branch, come back under their diffusers paths -- packed where the model has a plain Linear, decoded under its
+precision-sensitive modules, dropped where a merged file bundles another model -- and the one reservation counts them
+as they end up. The compute dtype is bf16, as in production: the packed global scale must not be cast with it.
+"""
+
+import json
+from types import SimpleNamespace
+from unittest.mock import MagicMock
+
+import pytest
+import torch
+
+from invokeai.backend.model_manager.configs.main import Main_Checkpoint_Krea2_Config
+from invokeai.backend.model_manager.load.model_loaders import krea2
+from invokeai.backend.model_manager.load.model_loaders.krea2 import Krea2CheckpointModel
+from invokeai.backend.model_manager.taxonomy import Krea2VariantType
+from invokeai.backend.quantization.int8_convrot import CONVROT_GROUP_SIZE, Int8ConvrotLinear
+from invokeai.backend.quantization.nvfp4 import NVFP4Linear
+
+COMPUTE_DTYPE = torch.bfloat16
+
+# Native checkpoint layer -> (diffusers module path, [out, in]). Rows are whole 128-row tiles, columns 64 wide.
+NVFP4_LAYERS = {
+ "blocks.0.attn.wq": ("transformer_blocks.0.attn.to_q", (128, 64)),
+ "blocks.0.attn.wo": ("transformer_blocks.0.attn.to_out.0", (128, 64)),
+ "blocks.0.mlp.up": ("transformer_blocks.0.ff.up", (256, 64)),
+ "txtfusion.refiner_blocks.0.attn.gate": ("text_fusion.refiner_blocks.0.attn.to_gate", (128, 64)),
+ # Under Krea-2's `time_embed` skip pattern: decoded, not packed.
+ "tmlp.0": ("time_embed.linear_1", (128, 64)),
+}
+PACKED = [native for native in NVFP4_LAYERS if native != "tmlp.0"]
+# A merged file's bundled encoder layer, named in the same header: not this model's, so dropped rather than refused.
+BUNDLED = "text_encoders.qwen3vl.layers.0.q_proj"
+
+
+class _TinyKrea2(torch.nn.Module):
+ """The diffusers module names the native keys convert to, nothing else."""
+
+ _skip_layerwise_casting_patterns = ["time_embed", "norm"]
+
+ def __init__(self, **_kwargs) -> None:
+ super().__init__()
+ block = torch.nn.Module()
+ block.attn = torch.nn.Module()
+ block.attn.to_q = torch.nn.Linear(64, 128, bias=False)
+ block.attn.to_k = torch.nn.Linear(CONVROT_GROUP_SIZE, 128, bias=False)
+ block.attn.to_out = torch.nn.ModuleList([torch.nn.Linear(64, 128, bias=False)])
+ block.ff = torch.nn.Module()
+ block.ff.up = torch.nn.Linear(64, 256, bias=False)
+ self.transformer_blocks = torch.nn.ModuleList([block])
+ refiner = torch.nn.Module()
+ refiner.attn = torch.nn.Module()
+ refiner.attn.to_gate = torch.nn.Linear(64, 128, bias=False)
+ self.text_fusion = torch.nn.Module()
+ self.text_fusion.refiner_blocks = torch.nn.ModuleList([refiner])
+ self.time_embed = torch.nn.Module()
+ self.time_embed.linear_1 = torch.nn.Linear(64, 128)
+ self.img_in = torch.nn.Linear(8, 4)
+
+
+def _nvfp4_tensors(path: str, shape: tuple[int, int]) -> tuple[dict[str, torch.Tensor], torch.Tensor]:
+ """Codes 2 and 10 are +1.0 and -1.0; with a block scale of 2 and a global scale of 0.25 the weight is +-0.5."""
+ positive = torch.randint(0, 2, shape, dtype=torch.bool)
+ codes = torch.where(positive, 2, 10).to(torch.uint8)
+ tensors = {
+ f"{path}.weight": (codes[:, 0::2] << 4) | codes[:, 1::2],
+ f"{path}.weight_scale": torch.full((shape[0], shape[1] // 16), 2.0).to(torch.float8_e4m3fn),
+ f"{path}.weight_scale_2": torch.tensor(0.25),
+ }
+ return tensors, torch.where(positive, 0.5, -0.5)
+
+
+def _packed_bytes(rows: int, columns: int) -> int:
+ return rows * columns // 2 + rows * (columns // 16) + 4
+
+
[email protected](params=["dense", "int8"])
+def loaded(request, monkeypatch: pytest.MonkeyPatch, tmp_path) -> SimpleNamespace:
+ """The loader run over a native nvfp4 file whose `blocks.0.attn.wk` neighbour is dense or int8 -- the two
+ side-channel branches the nvfp4 layers have to pass through untouched."""
+ import diffusers
+ import safetensors.torch
+
+ torch.manual_seed(0)
+ state_dict: dict[str, torch.Tensor] = {}
+ expected: dict[str, torch.Tensor] = {}
+ header_layers: dict[str, dict[str, str]] = {}
+ for native, (diffusers_path, shape) in NVFP4_LAYERS.items():
+ tensors, weight = _nvfp4_tensors(native, shape)
+ state_dict.update(tensors)
+ expected[diffusers_path] = weight
+ header_layers[native] = {"format": "nvfp4"}
+ for native, shape in ((BUNDLED, (128, 64)), ("last.up", (128, 64))):
+ # `last.up` is the final-block projection the conversion discards; one repack quantizes it, and its global
+ # scale has to go with it rather than be refused as an orphan.
+ tensors, _ = _nvfp4_tensors(native, shape)
+ state_dict.update(tensors)
+ header_layers[native] = {"format": "nvfp4"}
+
+ state_dict["tmlp.0.bias"] = torch.randn(128)
+ state_dict["first.weight"] = torch.randn(4, 8)
+ state_dict["first.bias"] = torch.randn(4)
+ if request.param == "dense":
+ state_dict["blocks.0.attn.wk.weight"] = torch.randn(128, CONVROT_GROUP_SIZE)
+ else:
+ marker = json.dumps({"format": "int8_tensorwise", "convrot": False})
+ state_dict["blocks.0.attn.wk.weight"] = torch.randint(-127, 128, (128, CONVROT_GROUP_SIZE), dtype=torch.int8)
+ state_dict["blocks.0.attn.wk.weight_scale"] = torch.ones(128, 1)
+ state_dict["blocks.0.attn.wk.comfy_quant"] = torch.frombuffer(
+ bytearray(marker.encode("utf-8")), dtype=torch.uint8
+ ).clone()
+ dense = {
+ name: state_dict[name] for name in ("tmlp.0.bias", "first.weight", "first.bias", "blocks.0.attn.wk.weight")
+ }
+
+ checkpoint_path = tmp_path / "krea2_turbo_nvfp4.safetensors"
+ checkpoint_path.touch()
+ config = Main_Checkpoint_Krea2_Config.model_construct(
+ path=str(checkpoint_path), variant=Krea2VariantType.Turbo, fp8_storage=None
+ )
+ loader = object.__new__(Krea2CheckpointModel)
+ loader._ram_cache = SimpleNamespace(make_room=MagicMock())
+ loader._logger = MagicMock()
+ loader._apply_fp8_layerwise_casting = lambda model, _config, _submodel: model
+
+ monkeypatch.setattr(diffusers, "Krea2Transformer2DModel", _TinyKrea2, raising=False)
+ monkeypatch.setattr(safetensors.torch, "load_file", lambda _path: state_dict)
+ monkeypatch.setattr(
+ krea2,
+ "read_safetensors_metadata",
+ lambda _path, _logger: {"_quantization_metadata": json.dumps({"layers": header_layers})},
+ )
+ monkeypatch.setattr(krea2, "should_keep_fp8_weights", lambda _device: False)
+ monkeypatch.setattr(krea2.TorchDevice, "choose_torch_device", lambda: torch.device("cpu"))
+ monkeypatch.setattr(krea2.TorchDevice, "choose_bfloat16_safe_dtype", lambda _device: COMPUTE_DTYPE)
+
+ model = loader._load_from_singlefile(config)
+ return SimpleNamespace(model=model, loader=loader, expected=expected, dense=dense, neighbour=request.param)
+
+
+def test_header_named_nvfp4_layers_are_packed_under_their_diffusers_paths(loaded) -> None:
+ for native in PACKED:
+ path, _ = NVFP4_LAYERS[native]
+ module = loaded.model.get_submodule(path)
+ assert isinstance(module, NVFP4Linear), path
+ assert module.weight.dtype is torch.uint8, path
+ # Installed after the cast, which would otherwise round the global scale to the compute dtype.
+ assert module.weight_scale_2.dtype is torch.float32, path
+ x = torch.randn(3, module.in_features, dtype=COMPUTE_DTYPE)
+ torch.testing.assert_close(module(x), x @ loaded.expected[path].to(COMPUTE_DTYPE).T)
+
+
+def test_the_neighbouring_layers_load_as_their_own_branch_leaves_them(loaded) -> None:
+ model = loaded.model
+
+ time_embed = model.time_embed.linear_1
+ assert type(time_embed) is torch.nn.Linear
+ assert torch.equal(time_embed.weight, loaded.expected["time_embed.linear_1"].to(COMPUTE_DTYPE))
+ assert torch.equal(time_embed.bias, loaded.dense["tmlp.0.bias"].to(COMPUTE_DTYPE))
+ assert torch.equal(model.img_in.weight, loaded.dense["first.weight"].to(COMPUTE_DTYPE))
+
+ to_k = model.transformer_blocks[0].attn.to_k
+ if loaded.neighbour == "int8":
+ assert isinstance(to_k, Int8ConvrotLinear)
+ else:
+ assert torch.equal(to_k.weight, loaded.dense["blocks.0.attn.wk.weight"].to(COMPUTE_DTYPE))
+
+
+def test_a_bundled_models_packed_layer_is_dropped(loaded) -> None:
+ assert not hasattr(loaded.model, "text_encoders")
+
+
+def test_one_reservation_counts_the_nvfp4_layers_as_they_are_held(loaded) -> None:
+ """Counted by hand: the packed layers at their stored size, the decoded one and the dense tensors at the compute
+ dtype, an int8 neighbour at one byte per code with its float32 scale. The bundled layer is not counted."""
+ packed = sum(_packed_bytes(*NVFP4_LAYERS[native][1]) for native in PACKED)
+ decoded = 128 * 64 * COMPUTE_DTYPE.itemsize
+ dense = (128 + 4 * 8 + 4) * COMPUTE_DTYPE.itemsize
+ if loaded.neighbour == "int8":
+ neighbour = 128 * CONVROT_GROUP_SIZE + 128 * torch.float32.itemsize
+ else:
+ neighbour = 128 * CONVROT_GROUP_SIZE * COMPUTE_DTYPE.itemsize
+ loaded.loader._ram_cache.make_room.assert_called_once_with(packed + decoded + dense + neighbour)
diff --git a/tests/backend/model_manager/test_starter_models.py b/tests/backend/model_manager/test_starter_models.py
index 163b375542..1dac42438d 100644
--- a/tests/backend/model_manager/test_starter_models.py
+++ b/tests/backend/model_manager/test_starter_models.py
@@ -1,9 +1,9 @@
"""Tests for the Krea-2 and MiniMax H3 starter-model bundles.
-A single-file / GGUF Krea-2 transformer ships *only* the transformer, so it is unusable without a
+A single-file (nvfp4) or GGUF Krea-2 transformer ships *only* the transformer, so it is unusable without a
standalone Qwen-Image VAE and Qwen3-VL text encoder. These tests assert that the Krea-2 launchpad
-bundle exists, exposes both the diffusers and GGUF options, and that each GGUF entry declares the two
-standalone dependencies so installing it also pulls the pieces needed to run it.
+bundle exists, exposes the diffusers, GGUF and nvfp4 options, and that each transformer-only entry declares the
+two standalone dependencies so installing it also pulls the pieces needed to run it.
"""
from invokeai.backend.model_manager.starter_models import (
@@ -37,7 +37,8 @@ def test_krea2_bundle_contains_diffusers_gguf_and_standalone_components() -> Non
assert "krea/Krea-2-Raw" in by_source
assert any(s.endswith("krea2_turbo-Q4_K_M.gguf") for s in by_source)
assert any(s.endswith("krea2_turbo-Q8_0.gguf") for s in by_source)
- # Standalone components (also declared as GGUF dependencies).
+ assert any(s.endswith("krea2_turbo_nvfp4.safetensors") for s in by_source)
+ # Standalone components (also declared as dependencies of the transformer-only entries).
assert any(m.type is ModelType.VAE for m in by_source.values())
assert any(m.type is ModelType.Qwen3VLEncoder for m in by_source.values())
@@ -49,19 +50,22 @@ def test_krea2_diffusers_variants() -> None:
assert by_source["krea/Krea-2-Raw"].variant is Krea2VariantType.Base
-def test_krea2_gguf_entries_declare_vae_and_encoder_dependencies() -> None:
- gguf_models = [
+def test_krea2_transformer_only_entries_declare_vae_and_encoder_dependencies() -> None:
+ # Everything but the diffusers pipelines is a single file holding only the transformer: the GGUFs and the nvfp4
+ # safetensors alike.
+ transformer_only = [
m
for m in _krea2_bundle_by_source().values()
- if m.format is ModelFormat.GGUFQuantized and m.base is BaseModelType.Krea2
+ if m.type is ModelType.Main and m.base is BaseModelType.Krea2 and m.source.startswith("https://")
]
- assert len(gguf_models) == 2
+ assert {m.format for m in transformer_only} == {ModelFormat.GGUFQuantized, None}
+ assert len(transformer_only) == 3
- for model in gguf_models:
+ for model in transformer_only:
assert model.variant is Krea2VariantType.Turbo
assert model.dependencies is not None, f"{model.name} must declare its standalone dependencies"
dep_types = {dep.type for dep in model.dependencies}
- # GGUF ships only the transformer -> it must pull a VAE and a Qwen3-VL encoder.
+ # It ships only the transformer -> it must pull a VAE and a Qwen3-VL encoder.
assert ModelType.VAE in dep_types, f"{model.name} is missing a VAE dependency"
assert ModelType.Qwen3VLEncoder in dep_types, f"{model.name} is missing a Qwen3-VL encoder dependency"