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.

fix(ideogram4): reserve GGUF loads absolutely and unpack BF16 without a decode

Alexander Eichhorn0672501b2c07
diff --git a/docs/src/content/docs/Users Guide/03.Models/Local Models/ideogram4.mdx b/docs/src/content/docs/Users Guide/03.Models/Local Models/ideogram4.mdx
index 35d32a74a1..788326294e 100644
--- a/docs/src/content/docs/Users Guide/03.Models/Local Models/ideogram4.mdx
+++ b/docs/src/content/docs/Users Guide/03.Models/Local Models/ideogram4.mdx
@@ -1,7 +1,7 @@
---
title: Ideogram 4
description: Generate images with the Ideogram 4 text-to-image models.
-lastUpdated: 2026-09-30
+lastUpdated: 2026-10-08
sidebar:
order: 6
---
@@ -37,7 +37,7 @@ Pick the unconditional branch, the encoder and the VAE in the **Components** sec
Which branch a file holds is read from the file itself, and from the filename for a build that does not record it, so keep these names as published.
-Two builds of the transformers are supported, and they behave differently in memory:
+Two safetensors builds of the transformers are supported, and they behave differently in memory:
| | download, per branch | resident, per branch |
|---|---|---|
@@ -53,9 +53,26 @@ Both branches are resident at once, so double those figures for the pair.
**Use int8 where FP8 Storage is not available.** It requires a CUDA or Intel XPU device; on anything else the fp8 build falls back to the expanded path, while int8 keeps its stored codes and dequantizes them per forward on any device with no setting to turn on.
-On a 24 GB NVIDIA card without the fp8 matmul (RTX 30-series), the int8 pair plus the 8B encoder still adds up to more than the card holds, so the bundled [nf4 build](#installing-ideogram-4) remains the smaller option there.
+On a 24 GB NVIDIA card without the fp8 matmul (RTX 30-series), the int8 pair plus the 8B encoder still adds up to more than the card holds, so the bundled [nf4 build](#installing-ideogram-4) or a [GGUF](#gguf) pair is the smaller option there.
:::
+#### GGUF
+
+Community GGUF conversions of the same two transformers load too, and they are the smallest builds. The weights stay packed in memory and are unpacked layer by layer during generation, on every device, so the download size is about the resident size. Three pairs are available as starter models, each of which installs its unconditional branch, the Qwen3-VL 8B encoder and the VAE with it:
+
+| | download, per branch | 1024px, 12 steps, 4090 |
+|---|---|---|
+| **Ideogram 4 (GGUF, Q4_0)** — [`molbal/ideogram-4-gguf`](https://huggingface.co/molbal/ideogram-4-gguf) | 5.6 GB | 27.9 s |
+| **Ideogram 4 (GGUF, Q5_K)** — [`rectangleworm/ideogram-4-gguf`](https://huggingface.co/rectangleworm/ideogram-4-gguf) | 6.4 GB | 32.2 s |
+| **Ideogram 4 (GGUF, Q5_1)** — [`molbal/ideogram-4-gguf`](https://huggingface.co/molbal/ideogram-4-gguf) | 7.3 GB | not measured |
+
+For comparison, the fp8 single-file pair took 37–38 s on the same card. Both GGUF pairs stay fully on the GPU next to the encoder (5.3 and 6.0 GB per branch), where the fp8 pair has to stream part of its second branch. Q5_K is the closer of the two to the fp8 build's images.
+
+Pick the model and the unconditional branch in **Components** exactly as for the safetensors builds. Two things are different:
+
+- **The branch comes from the filename alone.** No published GGUF records which branch it holds, so a file whose name contains `unconditional` or `uncond` installs as the unconditional branch and anything else as the conditional one. Keep the published names; to fix a renamed file, remove the model, give the file its published name back and install it again.
+- Other GGUF repositories of Ideogram 4 (for example leejet's or stduhpf's) load as well. `IQ4_NL` files work but are unpacked on the CPU at every step, which is much slower. Q8_0 is not offered as a starter: at about 10.1 GB per branch it is larger than the fp8 build.
+
### Memory use during generation
Ideogram 4 keeps both transformer branches loaded for the whole generation. With the single-file builds on a CUDA or ROCm GPU (with partial loading on, the default), InvokeAI checks whether the pair fits next to the working memory a generation needs. If it does not, it keeps only part of the second branch on the GPU and streams the rest in each step. On a 24 GB card with the fp8 pair this keeps about 2.4 GB free instead of 1.2 GB. The bundled nf4 and fp8 folders are not affected. Three things follow:
diff --git a/invokeai/app/invocations/ideogram4/ideogram4_model_loader.py b/invokeai/app/invocations/ideogram4/ideogram4_model_loader.py
index b1b3f445c0..d340a9e43b 100644
--- a/invokeai/app/invocations/ideogram4/ideogram4_model_loader.py
+++ b/invokeai/app/invocations/ideogram4/ideogram4_model_loader.py
@@ -182,8 +182,9 @@ class Ideogram4ModelLoaderInvocation(BaseInvocation):
f"'{config.name}' is the {branch} branch of Ideogram 4 and cannot be used as '{slot}', "
f"which needs the {expected} one. If the two are wired the wrong way round, swap them. "
"A file without branch metadata (every GGUF, and stripped safetensors) is classified by "
- f"its name, so if this one was renamed, rename it to contain '{expected}' (or not) and "
- "re-install it."
+ "its name: a name containing 'uncond' installs as the unconditional branch, any other name "
+ "as the conditional one. If this file was renamed, remove the model, give the file its "
+ "published name back and install it again."
)
def _resolve_encoder(
diff --git a/invokeai/backend/model_manager/load/model_loaders/ideogram4.py b/invokeai/backend/model_manager/load/model_loaders/ideogram4.py
index 41cb76001c..6f508e923d 100644
--- a/invokeai/backend/model_manager/load/model_loaders/ideogram4.py
+++ b/invokeai/backend/model_manager/load/model_loaders/ideogram4.py
@@ -544,9 +544,11 @@ def _dequantize_ggml_at_load(
every forward -- for the BF16 `llm_cond_proj` most releases ship, a 245M-element weight, that is a
measured 1.87 GB transient per call.
- The framework reserved the file's size before the loader ran, which already covers every packed
- tensor, so what is reserved here is each tensor's growth over its packed size: nothing for BF16,
- and little for the rest -- the norms, a two-row embedding and the two embedders.
+ The reservation is absolute, because `make_room` makes that much room rather than adding to the
+ file-size reservation the framework made before the loader ran: everything that stays packed at
+ its packed size, everything replaced at its unpacked size, and one replacement in flight. BF16 is
+ reinterpreted rather than run through the GGML kernel, which widens through int32 and float32 on
+ the way -- about 8 bytes per element, 2 GB for `llm_cond_proj` alone.
"""
linear_params = {
f"{module_name}.{param_name}"
@@ -564,18 +566,26 @@ def _dequantize_ggml_at_load(
or any(pattern in key for pattern in skip_patterns)
)
]
- reserve(
- sum(
- max(0, sd[key].tensor_shape.numel() * sd[key].compute_dtype.itemsize - sd[key].quantized_data.nbytes)
- for key in keys
- )
+ unpacked = {key: sd[key].tensor_shape.numel() * sd[key].compute_dtype.itemsize for key in keys}
+ kept = sum(
+ value.quantized_data.nbytes if isinstance(value, GGMLTensor) else value.nbytes
+ for key, value in sd.items()
+ if key not in unpacked
)
+ reserve(kept + sum(unpacked.values()) + max(unpacked.values(), default=0))
# One at a time, so each packed original is released as its replacement lands.
for key in keys:
- sd[key] = sd[key].get_dequantized_tensor()
+ sd[key] = _unpack(sd[key])
return len(keys)
+def _unpack(value: GGMLTensor) -> torch.Tensor:
+ """`value` as a plain tensor in its compute dtype; BF16 as a view of its bytes, not a decode."""
+ if value._ggml_quantization_type is gguf.GGMLQuantizationType.BF16:
+ return value.quantized_data.view(torch.bfloat16).reshape(value.tensor_shape).to(value.compute_dtype)
+ return value.get_dequantized_tensor()
+
+
@ModelLoaderRegistry.register(base=BaseModelType.Ideogram4, type=ModelType.Main, format=ModelFormat.GGUFQuantized)
class Ideogram4GGUFModel(ModelLoader):
"""Loads ONE branch of Ideogram 4's dual-branch transformer from a GGUF file.
@@ -610,8 +620,6 @@ class Ideogram4GGUFModel(ModelLoader):
target_device = TorchDevice.choose_torch_device()
compute_dtype = TorchDevice.choose_bfloat16_safe_dtype(target_device)
- # The framework has already reserved the file's size, and the weights stay packed, so that
- # covers everything but the growth of the tensors dequantized below, which reserve for it.
sd: dict[str, torch.Tensor] = gguf_sd_loader(Path(config.path), compute_dtype=compute_dtype)
with accelerate.init_empty_weights():
diff --git a/invokeai/backend/model_manager/starter_models/ideogram_4.py b/invokeai/backend/model_manager/starter_models/ideogram_4.py
index 5e194ed3e6..ad935068d9 100644
--- a/invokeai/backend/model_manager/starter_models/ideogram_4.py
+++ b/invokeai/backend/model_manager/starter_models/ideogram_4.py
@@ -124,9 +124,9 @@ ideogram_4_gguf_q4_0 = StarterModel(
name="Ideogram 4 (GGUF, Q4_0)",
base=BaseModelType.Ideogram4,
source=f"{_MOLBAL_GGUF}/ideogram4-transformer-q4_0.gguf",
- description="Community GGUF of Ideogram 4 in Q4_0, the smallest build: 5.6GB per branch in memory "
- "against 8.7GB for fp8, on every device. Installs the unconditional branch, the Qwen3-VL 8B encoder "
- "and the VAE with it. Non-commercial license. ~21GB total",
+ description="Community GGUF of Ideogram 4 in Q4_0, the smallest build: 5.6GB per branch in memory on "
+ "every device, against 8.7GB for fp8 with FP8 Storage (about 17GB without). Installs the unconditional "
+ "branch, the Qwen3-VL 8B encoder and the VAE with it. Non-commercial license. ~21GB total",
type=ModelType.Main,
format=ModelFormat.GGUFQuantized,
dependencies=[ideogram_4_unconditional_gguf_q4_0, ideogram_4_qwen3_vl_encoder_8b, flux2_vae],
@@ -168,8 +168,8 @@ ideogram_4_gguf_q5_1 = StarterModel(
name="Ideogram 4 (GGUF, Q5_1)",
base=BaseModelType.Ideogram4,
source=f"{_MOLBAL_GGUF}/ideogram4-transformer-q5_1.gguf",
- description="Community GGUF of Ideogram 4 in Q5_1, the largest GGUF that is still smaller than fp8: "
- "7.3GB per branch in memory, on every device. Installs the unconditional branch, the Qwen3-VL 8B "
+ description="Community GGUF of Ideogram 4 in Q5_1, the largest of these starters: 7.3GB per branch "
+ "in memory, on every device. Installs the unconditional branch, the Qwen3-VL 8B "
"encoder and the VAE with it. Non-commercial license. ~25GB total",
type=ModelType.Main,
format=ModelFormat.GGUFQuantized,
diff --git a/invokeai/backend/quantization/gguf/ggml_tensor.py b/invokeai/backend/quantization/gguf/ggml_tensor.py
index f26495d7ad..04351bbaa7 100644
--- a/invokeai/backend/quantization/gguf/ggml_tensor.py
+++ b/invokeai/backend/quantization/gguf/ggml_tensor.py
@@ -205,7 +205,8 @@ class GGMLTensor(torch.Tensor):
# What one dequantization allocates beyond its result, per weight element: the block kernels in
# `utils.py` widen codes and scales through integer and float16 intermediates before the final cast.
# Measured on CUDA (torch 2.13) for a 4608x53248 weight: about 2 bytes for Q8_0 and Q4_0, 3 for Q4_K
-# and Q6_K, 5 for Q5_K, 6 for BF16 and 8 for Q5_1.
+# and Q6_K, 5 for Q5_K, 6 for BF16 and 8 for Q5_1. The host-side counterpart, for decoding a whole tensor
+# at load, is `_PEAK_COPIES` in `model_manager/load/quantized_embedding.py`.
_DEQUANT_INTERMEDIATE_BYTES_PER_ELEMENT = 8
diff --git a/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/generateGraphNodeTypes.json b/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/generateGraphNodeTypes.json
index cb7dc0d9e9..88a3f8d4de 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/generateGraphNodeTypes.json
+++ b/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/generateGraphNodeTypes.json
@@ -195,11 +195,6 @@
"ideogram4UnconditionalModel",
"qwen3VLEncoderModel",
"vae"
- ],
- "standalone-gguf": [
- "ideogram4UnconditionalModel",
- "qwen3VLEncoderModel",
- "vae"
]
},
"nodeTypes": [
diff --git a/invokeai/frontend/webv2/src/features/generation/core/graphCoverage.testing.ts b/invokeai/frontend/webv2/src/features/generation/core/graphCoverage.testing.ts
index a2b10da1eb..6340317d65 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/graphCoverage.testing.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/graphCoverage.testing.ts
@@ -33,11 +33,10 @@ export const SHAPE_OVERRIDES: Partial<Record<SupportedGenerateBase, readonly Mod
{ label: 'qwen3', overrides: { format: 'checkpoint', variant: 'anima_qwen3' } },
{ label: 'qwen35', overrides: { format: 'checkpoint', variant: 'anima_qwen35' } },
],
- // Ideogram's single files carry a branch and come as safetensors or GGUF.
+ // Ideogram's standalone fixture is a conditional checkpoint, not GGUF.
'ideogram-4': [
{ label: 'diffusers', overrides: { format: 'diffusers' } },
{ label: 'standalone-components', overrides: { branch: 'conditional', format: 'checkpoint' } },
- { label: 'standalone-gguf', overrides: { branch: 'conditional', format: 'gguf_quantized' } },
],
// FLUX.2 dev and Klein need distinct encoder variants.
flux2: [
diff --git a/tests/app/invocations/test_ideogram4_denoise_branches.py b/tests/app/invocations/test_ideogram4_denoise_branches.py
index d12cad8fe5..bfcb7c3fb4 100644
--- a/tests/app/invocations/test_ideogram4_denoise_branches.py
+++ b/tests/app/invocations/test_ideogram4_denoise_branches.py
@@ -272,8 +272,8 @@ def _gguf_branch(*packed: str) -> Ideogram4Transformer:
def test_a_gguf_branch_adds_its_dequantization_headroom() -> None:
"""A packed GGUF Linear is dequantized inside every forward, as an int8 one is.
- Measured on the released geometry, `llm_cond_proj` alone needs 0.9 to 2.3 GB for that depending
- on the quantization type, so a GGUF branch must not report the zero a dense one does. The layers
+ Measured on the released geometry, `llm_cond_proj` alone needs 0.9 to 2.3 GB for that where a
+ release quantizes it, so a GGUF branch must not report the zero a dense one does. The layers
run one after another, so it is the largest packed layer that counts, not their sum.
"""
largest = "layers.0.feed_forward.w1"
diff --git a/tests/app/invocations/test_ideogram4_model_loader.py b/tests/app/invocations/test_ideogram4_model_loader.py
index fc27a1c813..a4cfcef7dc 100644
--- a/tests/app/invocations/test_ideogram4_model_loader.py
+++ b/tests/app/invocations/test_ideogram4_model_loader.py
@@ -10,7 +10,10 @@ from types import SimpleNamespace
import pytest
-from invokeai.app.invocations.ideogram4.ideogram4_model_loader import Ideogram4ModelLoaderInvocation
+from invokeai.app.invocations.ideogram4.ideogram4_model_loader import (
+ _SINGLE_FILE_FORMATS,
+ Ideogram4ModelLoaderInvocation,
+)
from invokeai.app.invocations.model import ModelIdentifierField
from invokeai.backend.model_manager.taxonomy import (
BaseModelType,
@@ -239,14 +242,11 @@ def test_a_diffusers_model_cannot_be_the_unconditional_branch() -> None:
_invoke(configs)
-def test_the_unconditional_picker_offers_every_single_file_format() -> None:
+def test_the_unconditional_picker_offers_what_the_node_accepts() -> None:
field = Ideogram4ModelLoaderInvocation.model_fields["unconditional_model"]
assert field.json_schema_extra is not None
- assert set(field.json_schema_extra["ui_model_format"]) == {
- ModelFormat.Checkpoint.value,
- ModelFormat.GGUFQuantized.value,
- }
+ assert set(field.json_schema_extra["ui_model_format"]) == {f.value for f in _SINGLE_FILE_FORMATS}
def test_the_vae_picker_offers_the_bases_the_architecture_accepts() -> None:
diff --git a/tests/backend/model_manager/load/ideogram4_gguf_fixture.py b/tests/backend/model_manager/load/ideogram4_gguf_fixture.py
index 6b02b7a4dd..604e93236a 100644
--- a/tests/backend/model_manager/load/ideogram4_gguf_fixture.py
+++ b/tests/backend/model_manager/load/ideogram4_gguf_fixture.py
@@ -46,8 +46,14 @@ def packs_every_weight(name: str, shape: tuple[int, ...]) -> bool:
return name.endswith(".weight")
-def write_ideogram4_gguf(path: Path, packs: Packs, *, seed: int = 0) -> dict[str, torch.Tensor]:
- """Write a randomly initialised tiny transformer to ``path``.
+def write_ideogram4_gguf(
+ path: Path,
+ packs: Packs,
+ *,
+ qtype: gguf.GGMLQuantizationType = gguf.GGMLQuantizationType.Q8_0,
+ seed: int = 0,
+) -> dict[str, torch.Tensor]:
+ """Write a randomly initialised tiny transformer to ``path``, ``packs`` tensors stored as ``qtype``.
Returns the float32 values a reader dequantizes each tensor to, i.e. what the file *means*, so a
test can build the reference model from them rather than from the pre-quantization originals.
@@ -60,11 +66,11 @@ def write_ideogram4_gguf(path: Path, packs: Packs, *, seed: int = 0) -> dict[str
meant: dict[str, torch.Tensor] = {}
for name, tensor in model.state_dict().items():
data = tensor.detach().to(torch.float32).numpy()
- qtype = gguf.GGMLQuantizationType.Q8_0 if packs(name, data.shape) else gguf.GGMLQuantizationType.BF16
- raw = quantize(data, qtype)
+ stored_as = qtype if packs(name, data.shape) else gguf.GGMLQuantizationType.BF16
+ raw = quantize(data, stored_as)
# `raw_shape` is the packed byte shape; gguf derives the logical one from it.
- writer.add_tensor(name, raw, raw_shape=raw.shape, raw_dtype=qtype)
- meant[name] = torch.from_numpy(dequantize(raw, qtype)).reshape(tensor.shape)
+ writer.add_tensor(name, raw, raw_shape=raw.shape, raw_dtype=stored_as)
+ meant[name] = torch.from_numpy(dequantize(raw, stored_as)).reshape(tensor.shape)
writer.write_header_to_file()
writer.write_kv_data_to_file()
writer.write_tensors_to_file()
diff --git a/tests/backend/model_manager/load/test_ideogram4_gguf_loader.py b/tests/backend/model_manager/load/test_ideogram4_gguf_loader.py
index 2230a99b53..dab122c325 100644
--- a/tests/backend/model_manager/load/test_ideogram4_gguf_loader.py
+++ b/tests/backend/model_manager/load/test_ideogram4_gguf_loader.py
@@ -40,10 +40,12 @@ SEAM = Seam(
LAYOUTS = pytest.mark.parametrize("packs", [packs_block_linears, packs_every_weight], ids=["molbal", "rectangleworm"])
-def _load(monkeypatch, tmp_path, packs: Packs) -> tuple[torch.nn.Module, dict[str, torch.Tensor], SeamRun]:
+def _load(
+ monkeypatch, tmp_path, packs: Packs, qtype: gguf.GGMLQuantizationType = gguf.GGMLQuantizationType.Q8_0
+) -> tuple[torch.nn.Module, dict[str, torch.Tensor], SeamRun]:
tmp_path.mkdir(parents=True, exist_ok=True)
path = tmp_path / "ideogram4-transformer-q8_0.gguf"
- meant = write_ideogram4_gguf(path, packs)
+ meant = write_ideogram4_gguf(path, packs, qtype=qtype)
config = Main_GGUF_Ideogram4_Config.model_construct(path=str(path), name="ideogram4", branch="conditional")
run = prepare(
@@ -72,16 +74,24 @@ def _forward(model: torch.nn.Module) -> torch.Tensor:
@LAYOUTS
-def test_the_gguf_branch_computes_what_its_file_means(monkeypatch, tmp_path, packs: Packs) -> None:
+ "qtype",
+ [gguf.GGMLQuantizationType.Q8_0, gguf.GGMLQuantizationType.Q5_1, gguf.GGMLQuantizationType.Q4_0],
+ ids=lambda qtype: qtype.name,
+)
+def test_the_gguf_branch_computes_what_its_file_means(
+ monkeypatch, tmp_path, packs: Packs, qtype: gguf.GGMLQuantizationType
+) -> None:
"""Against a dense model holding the values the file dequantizes to, so the comparison is not
- blurred by quantization error. Not bit-exact all the same: the torch Q8_0 kernel multiplies codes
+ blurred by quantization error. Q4_0 and Q5_1 are the starter builds' types. Not bit-exact all the
+ same: the torch kernels multiply codes
by their fp16 block scale in fp16, the reference reader in float32. A dropped norm weight, a
zeroed embedding or an activation cast to the wrong dtype is off by orders of magnitude more.
Wrapped in the custom layers first, as the model cache does on every load: that is the path the
packed Linear weights take in production.
"""
- model, meant, _ = _load(monkeypatch, tmp_path, packs)
+ model, meant, _ = _load(monkeypatch, tmp_path, packs, qtype)
apply_custom_layers_to_model(model)
reference = Ideogram4Transformer(TINY_CONFIG)
reference.load_state_dict(meant)
@@ -123,19 +133,21 @@ def test_an_unquantized_linear_weight_is_unpacked_and_a_quantized_one_is_not(mon
@LAYOUTS
-def test_the_load_reserves_what_dequantizing_adds(monkeypatch, tmp_path, packs: Packs) -> None:
- """The framework reserves the file's size before the loader runs, so what the loader still owes
- is the growth of each tensor it widens -- not the total of them, which for the BF16 tensors of
- most releases would evict other models from the cache to make room for bytes that already exist.
+def test_the_load_reserves_the_model_as_it_will_be_held(monkeypatch, tmp_path, packs: Packs) -> None:
+ """One absolute reservation: `make_room` makes that much room rather than adding to the file-size
+ reservation the framework made before the loader ran, so reserving only what dequantizing adds
+ would evict nothing. It covers every weight as the model ends up holding it -- packed or
+ unpacked -- plus the largest unpacked tensor, which is briefly held twice while it is replaced.
"""
model, _, run = _load(monkeypatch, tmp_path, packs)
- reader = gguf.GGUFReader(tmp_path / "ideogram4-transformer-q8_0.gguf")
- stored = {tensor.name: int(tensor.n_bytes) for tensor in reader.tensors}
- widened = {
- name: param.numel() * param.element_size() - stored[name]
+ held = {
+ name: param.data.quantized_data.nbytes
+ if isinstance(param.data, GGMLTensor)
+ else param.numel() * param.element_size()
for name, param in model.named_parameters()
- if type(param.data) is torch.Tensor
}
+ largest_unpacked = max(
+ size for name, size in held.items() if not isinstance(model.get_parameter(name).data, GGMLTensor)
+ )
- assert run.reserved == [sum(max(0, growth) for growth in widened.values())]
- assert run.reserved[0] > 0, "the fixture widens at least the quantized norms or BF16 to float32"
+ assert run.reserved == [sum(held.values()) + largest_unpacked]