Nodes/ComfyUI-PainterNodes/H3 SageAttention (Mem Eff)
ComfyUI Node

H3 SageAttention (Mem Eff)

Buying VRAM back when MiniMax H3's attention pass eats your card

By princepainter·Created 9 months ago·Updated 17 days ago· 203
H3 SageAttention (Mem Eff)
  • model
  • model
◄head_chunks4►

MiniMax H3 is a 33B omni-modal model with around 42.5GB of reported weights, and MiniMax never published a consumer hardware floor for it. So the usual question isn't "will the weights fit" - quantize and they'll fit - it's "why am I still OOMing on a card that had room." H3 packs text tokens and video tokens into one long sequence, self-attention scales with that sequence, and the float q/k/v sitting in VRAM while the attention kernel runs is the actual peak.

H3SageAttention is a one-node fix for that one problem. It swaps every self-attention block in an H3 model for SageAttention's int8/fp8 kernels and gets the float copies out of memory before the kernel launches. The author marks it EXPERIMENTAL, which is fair - it's the one node in this pack that touches model internals rather than plumbing.

What it actually does

This is not a wrapper around sageattn(). The top-level SageAttention API keeps extra float copies of q, k and v alive across the call - exactly the memory you're trying to reclaim. This node calls the low-level quantization and attention kernels directly so it can del the float tensors first. That's the whole point of the port, per the source's own docstring.

Concretely, on patch it walks diffusion_model.blocks[i].attn.forward for every transformer block and replaces each one with its own forward: qkv projection, H3's fused RMSNorm + split-half RoPE through comfy_kitchen, then SageAttention's compiled kernels - int8 QK quantization, per-channel fp8 for V. On sm90 it also pads the V sequence to a multiple of 128, because the compiled kernel aborts on odd lengths and H3 sequences with long text prompts land there.

The author also vendored SageAttention's per-thread int8 Triton quantization kernels with the row offsets promoted to int64. That's not decoration: on stock int32 offsets, sequences this long overflow the index and you get garbage or a crash.

The two things you set

model is a MODEL wire, and head_chunks is the only knob. Default 4, range 1–56. Heads are independent, so splitting the attention call into head groups changes nothing mathematically - it just shrinks the kernel's internal working set (the int8 q/k copies and the fp32 accumulator) by the chunk count. The tooltip is unusually honest: measured on a 56-head/128-dim block at 32k tokens, 1 saves nothing (slightly worse than stock), 4 lands about 7% below stock. So 1 is the fastest setting and higher values trade speed for VRAM. That 7% is the realistic ceiling here, not the multi-gigabyte drop people report from Kijai's equivalent Wan nodes.

You get one output, model, which goes wherever the model was going - your sampler, or your next MODEL patch. Wire it in between your H3 loader and the sampler. Since it clones the model and rewrites block forwards, it belongs after anything else that patches the model - the same ordering trap that bites context-bus workflows.

Install

The pack is light: soundfile and numpy, that's the whole requirements.txt. The heavy dependency is the one it does not install for you - SageAttention with CUDA kernels compiled for your GPU.

cd ComfyUI/custom_nodes
git clone https://github.com/princepainter/ComfyUI-PainterNodes
cd ComfyUI-PainterNodes
pip install -r requirements.txt

Or search "PainterNodes" in ComfyUI-Manager. Restart ComfyUI, then install SageAttention separately and verify it before you blame the node:

pip install sageattention
python -c "from sageattention.core import get_cuda_arch_versions; print(get_cuda_arch_versions())"

If that prints your arch, you're in business. On Windows, Triton is what fights you - the single most persistent complaint in every video-model thread that mentions SageAttention. Budget an evening.

Where people get burned

"sageattention is not installed, is too old, or its CUDA arch could not be determined." The node imports SageAttention's internal symbols as a version gate. An ancient build that only ships the compiled extension will fail that import even though import sageattention works. Update the package, don't reinstall ComfyUI.

"can only be applied to a MiniMax H3 model." It checks that diffusion_model.blocks[*].attn.qkv_proj exists. Native H3 loads fine; a GGUF or wrapper path that doesn't expose that structure won't. Related: if comfy.quant_ops.ck (comfy_kitchen) is missing, the fused norm+RoPE kernel isn't available - that means your ComfyUI is too old for H3 support anyway.

Supported architectures are sm75, sm80, sm86, sm89, sm90, sm120, sm121. RTX 20-series through 50-series and Hopper are covered. V100 and pre-Turing raise an error instead of quietly falling back.

Don't expect miracles, and measure. Time head_chunks 1 against 4; if your OOM was marginal this rescues the run, if it wasn't you need quantization instead. And because the patch is scoped to the nodes it's wired to rather than the global --use-sage-attention flag, it's the safer way to have SageAttention on this workflow and off everywhere else - worth remembering, since SageAttention globally has a track record of quietly corrupting some models' output.

CategoryPainter/MiniMax

Inputs (2)

NameTypeDefaultDescription
modelMODEL—
head_chunksINT41–56Split the attention call into this many head groups. Heads are independent so the result is unchanged; the kernel's internal transients shrink by the chunk count. Measured on a 56-head/128-dim block at 32k tokens: 1 = no saving (slightly more than stock), 4 = ~7% below stock. 1 is the fastest, higher values trade speed for VRAM.

Outputs (1)

NameTypeDescription
modelMODEL—