RiverField H3 SLA Attention (ROCm)
Block-sparse attention for MiniMax-H3 in ComfyUI on ROCm, routed through comfy-kitchen sol_attn instead of the Triton kernels.
ComfyUI H3 SLA Attention (ROCm fork)
A single ComfyUI node that adds block-sparse attention for MiniMax-H3 on AMD GPUs. It reproduces the sparse inference path expected by LightX2V SLA turbo LoRAs; the LoRA alone changes weights but does not install a sparse attention backend.
This is a ROCm/HIP fork of ComfyUI-H3-SLA-Attention from
ComfyUI-PlagueKind-Nodes,
which targets NVIDIA/CUDA. Launch configs are included for gfx1030
(RX 6800, RDNA2) and gfx1151 (Radeon 8050S, Strix Halo). Other architectures
are autotuned on first use and are not verified.
Node
H3 SLA Attention - ROCM (category CFZ/model_patches)
Place it on the MODEL connection after all LoRA loaders and any attention
backend node, immediately before the sampler:
MODEL -> LoRA loader(s) -> attention backend (optional) -> H3 SLA Attention - ROCM -> sampler
An attention backend node placed after SLA can replace the sparse override.
The node clones and patches the model. It does not modify weights or download anything. Short sequences, masked or unsupported calls and kernel failures fall back to dense attention. If the patch itself fails to install, the model passes through unchanged and the error is logged.
Settings
| Setting | Default | Notes |
| --- | --- | --- |
| sparsity_ratio | 0.90 | Fraction of key blocks skipped. 0.85 for LightX2V parity. Below roughly 0.60 is unlikely to be faster than dense. 0.0 to 0.95. |
| block_size | 64 | 32, 64 or 128. 64 and 128 use the same key-block size (128 only widens the query tile). 32 can improve audio at some cost. Benchmark before assuming one is faster on your card. |
| min_seq_len | 8192 | Shorter sequences stay dense. |
| dense_last_steps | 0 | Runs the last N steps dense. Can recover fine detail. |
| protect_audio | protect | Always attends language tokens, target audio and audio references. |
| enabled | sparse | dense (bypass) passes the model through, for baseline comparisons. |
| dense_steps | empty | Extra 0-based steps to run dense, e.g. 0,1 or 0-2. Each one costs speed. |
| dense_backend | auto | Kernel for dense fall-throughs. See below. |
| disable_fp16_accum | disabled | Turns off fp16/bf16 reduced-precision matmul reduction during this model's run, even with --fast fp16_accumulation. |
| stabilize_motion | off | Biases block selection toward the previous step's choice to reduce double exposure on fast motion. Uses more VRAM. |
| h3_cache | off | Block-stack residual cache applied before SLA. See below. |
| Protect Vid/Ref | Off | Light guarantees the best 15% of every visual-reference range, on top of the normal picks. |
| enable_dense_layers | off | Applies the dense_layers list. |
| dense_layers | 22,24,31-36,38-42,49 | Layers that run dense on every step. See below. |
| exact_audio_queries | sparse | exact lets target-audio query blocks attend all keys, using dense_backend. Adds time. |
| key_grouping | off | Experimental. See below. |
Saved workflows keep their own values. Widget values are stored by position, so after an update that adds or removes settings, delete the node and add it again.
Dense backend
| Value | Kernel |
| --- | --- |
| auto | Whatever attention ComfyUI currently has active |
| pytorch | PyTorch attention |
| comfy_kitchen | Comfy Kitchen int8 |
| sage:* | Calls the sageattention package directly (must be installed) |
The *_cuda names follow sageattention's own kernel names; availability on ROCm
depends on your sageattention build. If a backend cannot be resolved, a warning
is logged and the active attention is used.
Dense layers
The default list is the recommended set. It is filled in but inactive until
enable_dense_layers is on; edit it to use only part of it. Pick the
dense_backend you want these layers to run on.
Numbers are 0-based and count the self-attention calls actually made in a
step. They match H3 block indices only when every block runs. With a
block-skipping node (such as SkipDiTBlocksKJ), later entries shift to other
blocks and entries past the last call do nothing.
H3 cache
Skips the transformer block stack on low-change steps and reuses the previous
residual. Fixed settings: reuse threshold 0.18, active from 15% to 95% of
the run, at most 1 consecutive skip, auto device, verbose logging. With very
few steps there is little for it to skip.
Key grouping (experimental)
group: regroups video tokens per head so each key block holds similar keys.group+summary: also gives every skipped block one weighted summary key.
Both add time at the same sparsity; the aim is to allow a higher sparsity.
stabilize_motion is ignored while grouping.
Logs
Messages are tagged [H3Utils]. At install:
SLA installed | sparsity=0.90 | BLK=64x64 | ... | map_dense_layers=0 | exact_audio_queries=False
map_dense_layers is the number of entries in the active dense layer list
(0 when the switch is off).
After sampling:
SLA: 42 calls | S=38842 | blocks 71/607 kept (88.3% sparse, asked 90%) | 11 pinned | BLK=64x64 | 0 dense fall-throughs (on ?) | displaced attention_sub_quad
(on ?) means no dense fall-through happened, so no dense backend was used.
With dense layers on, a second line reports how many calls they kept dense.
patch installed but never invoked means attention was not sparsified.
ROCm notes
- The sparse kernel computes in fp16 and casts back. fp32 inputs (common with
manual-cast paths) are accepted. To change this, see
_SPARSE_COMPUTE_DTYPEinsla/patch.py. - Shapes without a built-in launch config are timed on first use and cached in
%USERPROFILE%\.cache\sla_kernel_cache.json(~/.cache/on Linux). Expect a slower first run for new shapes. sla_autotune_probe.pysweeps launch configs outside ComfyUI, each in its own process so a GPU fault cannot take down the sweep. It needs only torch and Triton, and writessla_probe_<arch>.json. Run it with--helpfor options.- RDNA2 has no matrix cores, so sparsity does not guarantee a speedup. Compare against your own dense baseline.
Requirements
- A current ComfyUI with the V3
comfy_apiand MiniMax-H3 support - PyTorch built for ROCm, on a supported AMD GPU (works well with comfyui-rocm)
- A ROCm-compatible Triton: on Windows
pip install triton-windows==3.7.0.post26; on Linux, a Triton build with ROCm support sageattention, only for thesage:*dense backends
If the imports fail, ComfyUI still starts but the node is not registered.
Installation
From the ComfyUI/custom_nodes directory:
git clone https://github.com/patientx/comfyui-h3-sla-attention-rocm.git
Restart ComfyUI afterwards.
Tests
From the node's folder inside custom_nodes:
python tests/test_sla.py
Kernel tests are skipped without a GPU and Triton.
Credits and license
- ComfyUI integration derived from ComfyUI-PlagueKind-Nodes.
- Sparse selection and forward kernel vendored and adapted from LightX2V (Apache-2.0).
h3_cacheis based on ComfyUI-MiniMaxH3-Cache by lihaoyun6 (GPL-3.0), reimplemented as a reversibleModelPatcherpatch.- Key grouping follows the idea in comfy-kitchen#367 (arXiv 2611.24256), written in plain torch and Triton.
See LICENSE.