Ideogram 4 FlashAttention (CRT)
Make Ideogram 4 stop dragging — FlashAttention for the 9B text champ
- model
- MODEL
Ideogram 4 is the open-weights release that finally shipped the best text-in-image renderer the community had ever seen: 9.3B params, legendary character and text recall. It also ships quantized and has a real appetite for compute, and its attention path isn't what you'd call optimized for local cards. This node patches that: it rewrites Ideogram 4's attention to run through FlashAttention 2, including the model's unusual padding mask via the variable-length kernel, and can shuttle trailing transformer blocks to CPU to free up VRAM.
You reach for this when Ideogram 4 runs, but runs slowly - or when it OOMs a card that should be able to hold a 9B model. The speedup from swapping the attention backend is one of the few "free lunch" patches in this ecosystem, and this node wraps it with the mask handling done right.
How it works
The node clones your model and installs an attention override. The subtle part is the mask: Ideogram uses a two-segment block mask (valid tokens vs. padded), which plain FlashAttention can't just consume. The node builds a variable-length plan - it splits the sequence into valid and padded groups, computes cumulative lengths, and feeds that to flash_attn_varlen_func, which is the kernel built exactly for this ragged-token case. If the mask doesn't match the expected Ideogram-style shape, it validates first and falls back to ComfyUI's stock attention with a logged warning instead of silently producing garbage.
The blocks_to_swap input (0–34) is the VRAM lever: set it to N and the last N transformer blocks are kept on CPU and loaded one at a time during inference. Slower per-step, but it's how you squeeze a 9B model onto a card that technically shouldn't hold it.
Inputs and outputs
- model (
MODEL) - the Ideogram 4 model, usually from an AutoDL-style loader. - blocks_to_swap - CPU offload for trailing blocks, default 0 (off).
Output is the patched MODEL (MODEL), which feeds your sampler exactly as the original would.
Installing it
This is the one CRT node with a genuinely heavy extra dependency: FlashAttention 2 (flash-attn). The node imports it at runtime and raises an explicit "install the flash-attn package in ComfyUI's Python environment" error if it's missing. pip install flash-attn is a source build on many machines and can take a while - budget for it. The pack itself installs normally (Manager → CRT-Nodes, or clone + requirements).
Where people get burned
The dependency is the wall: no flash-attn, no node - and the build is the thing that eats an afternoon on Windows especially. Check you actually need it first: if Ideogram 4 runs acceptably for you, the patch is optional speed, not a requirement. If you do hit OOM, try blocks_to_swap before giving up - a few blocks on CPU usually beats a failed render. And remember the fallback: when the node can't use FlashAttention for a given input it warns and uses stock attention, so if you see that warning and nothing else changed, the node isn't the bottleneck.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| blocks_to_swap | INT | 00–34 | Number of trailing Ideogram transformer blocks to keep on CPU and load one at a time during inference. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | — |