mirror of
https://github.com/Comfy-Org/comfy-kitchen.git
synced 2026-11-04 23:37:42 +00:00
[GH-ISSUE #119] Feature Request: Streamed QKV Projection and Packed Low-Bit K/V Support for Extreme Long-Sequence Attention #37
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/comfy-kitchen#37
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @eliowang6 on GitHub (Aug 16, 2026).
Original GitHub issue: https://github.com/Comfy-Org/comfy-kitchen/issues/119
Hi, I would like to propose a low-level attention/matmul feature that could be useful for MiniMax H3 and potentially other very long-sequence diffusion transformers.
Native Sol Attention now provides substantial compute speedups at high token counts, but there is still a separate peak-memory problem before attention begins: the QKV projection itself can be too large to materialize.
Example: MiniMax H3
For an H3 Ref2VA workload with approximately 152,263 packed tokens, I encountered:
The requested ~6.11 GiB is almost exactly the expected size of H3's full BF16 fused-QKV tensor at this sequence length.
Therefore, even a very memory-efficient attention kernel cannot help if:
already needs to allocate ~6 GiB before the kernel receives Q/K/V.
Proposed backend capability
It would be useful to support a streamed QKV projection that never materializes the complete high-precision fused-QKV output.
Conceptually:
Attention would then directly consume:
and decode K/V only tile-by-tile inside the kernel.
This is different from adding a quantization operation after
qkv_proj, because:still requires the original peak allocation and therefore does not solve this class of OOM.
Potential reduction
For the H3 example:
Keeping Q in BF16 while storing K/V at 4-bit gives a theoretical payload around:
So this could approximately halve the QKV working-set size.
Quality-oriented low-bit format
I would not suggest naive INT4 as the final goal.
A more interesting starting point may be fixed-width rotated INT4, inspired by techniques such as TurboQuant:
TurboQuant demonstrated near-quality-neutral very-low-bit K/V compression in its evaluated LLM workloads.
HyperQuant also demonstrated that aggressive rotation-based low-bit quantization can remain highly accurate in large diffusion/video models such as LTX-2, although the LTX-2 experiment quantized linear weights rather than K/V activations.
Therefore, H3 K/V quality would still need direct validation rather than assuming the same near-lossless behavior.
For a first GPU implementation, fixed-width INT4 may be much more practical than variable-length Rice/entropy coding because Triton kernels can address packed tiles directly.
Mixed precision for conditioning
For diffusion/video architectures with packed multimodal sequences, it may be useful to support different precision by token range.
For example, in H3:
This could protect prompt/reference fidelity while compressing the much larger generated-video portion.
Similar policies could also be applied by Transformer block or diffusion timestep.
Dense fallback is important
Packed low-bit K/V support would ideally not exist only inside Sol Attention.
If a dense fallback performs:
the original peak-memory problem can return.
A useful backend would therefore allow both sparse/Sol and dense attention paths to read packed K/V tile-by-tile without globally materializing BF16 K/V.
Why this may be useful beyond H3
H3 is an extreme example because it combines:
into one packed sequence.
But the same issue can appear in future long-context video DiTs and multimodal diffusion transformers.
So a reusable capability such as:
could potentially be useful as a general Comfy Kitchen primitive rather than an H3-only implementation.
The main goal would be peak-VRAM reduction, not merely attention speed.
Would this kind of streamed-QKV / packed-KV backend be within scope for Comfy Kitchen?
@coderabbitai[bot] commented on GitHub (Aug 16, 2026):
🔗 Related PRs
Comfy-Org/comfy-kitchen#94 - HIP: fix RDNA4 GEMM tile selection, vectorize fp8 elementwise kernels [open]
Comfy-Org/comfy-kitchen#103 - Implement optimized int8 attention (CORE-74) [merged]
Comfy-Org/comfy-kitchen#104 - HIP port of
#103: optimized int8 attention [merged]Comfy-Org/comfy-kitchen#108 - Optimize HIP ConvRot and deep-K INT8 kernels [open]
🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord!