mirror of
https://github.com/Comfy-Org/comfy-kitchen.git
synced 2026-11-04 23:37:42 +00:00
[PR #171] [CLOSED] Add key bias to chunked Sol-Attn producers #193
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#193
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?
📋 Pull Request Information
Original PR: https://github.com/Comfy-Org/comfy-kitchen/pull/171
Author: @xmarre
Created: 9/10/2026
Status: ❌ Closed
Base:
main← Head:feature/mixed-grid-key-bias📝 Commits (1)
663bfa3Add key bias to chunked Sol-Attn producers📊 Changes
12 files changed (+200 additions, -29 deletions)
View changed files
📝
comfy_kitchen/backends/cuda/__init__.py(+11 -1)📝
comfy_kitchen/backends/cuda/dlpack_bindings.cpp(+12 -3)📝
comfy_kitchen/backends/cuda/sage_attention/sol_attn.cu(+3 -3)📝
comfy_kitchen/backends/cuda/sage_attention/sol_attn_producer.cu(+5 -3)📝
comfy_kitchen/backends/hip/__init__.py(+10 -1)📝
comfy_kitchen/backends/hip/dlpack_bindings.cpp(+5 -3)📝
comfy_kitchen/backends/hip/launchers.h(+4 -3)📝
comfy_kitchen/backends/hip/sage_attention/sol_attn.hip(+9 -8)📝
comfy_kitchen/backends/hip/sage_attention/sol_attn_producer.hip(+7 -4)📝
tests/test_sol_attn.py(+35 -0)➕
tests/test_sol_attn_chunked_api.py(+42 -0)➕
tests/test_sol_attn_weighted_token_aug.py(+57 -0)📄 Description
Summary
Extend the fused-QKV
sol_attn_chunkedpath with the same per-key logit-bias carrier already supported by directsol_attn, for both CUDA and HIP.The chunked API accepts natural-log
key_bias, normalizes it to the existing float32[B,T]contract, converts it once to log2 units, and passes it into K-row quantization. The producer continues to compute pooled K sums and V calibration statistics from the unweighted activations; only the exact routed branch receives the score bias.This preserves the existing sparse-routing/calibration behavior while allowing callers that stream fused QKV to apply exact per-key weighting without materializing full Q/K/V tensors.
Contract
key_biasis a new optional keyword-only argument after the legacy positional tail.sol_attnsemantics where key bias is consumed by the exact branch.kmean/vscalecalibration remains based on unweighted activations; the measure changes exact score semantics, not calibration values.Tests and source audit
Adds shared fused-backend coverage for:
sol_attnon the same post-RoPE Q/K/V;key_biasshape rejection before producer execution;token_aug=64weighted interaction case that compares cold and primed chunked execution against direct fused Sol-Attn, checks finite output, verifies weighted output differs from unweighted output, and requireskmean/vscaleto remain bit-identical to the unweighted calibration;rope_eps,tail,block_len,coarse_gate, andtoken_augparameters remain positional whilekey_biasis optional and keyword-only.The reviewed CUDA and HIP producer implementations both compute post-RoPE K sums and V statistics before key-bias-bearing K quantization. The bias therefore cannot alter the
kmean/vscalecalibration values. Both low-level bindings require the producer bias carrier to be packed contiguous float32 with exactlyB*Telements before a raw pointer reaches the kernel.The token-routing audit also closes the weighted exact-prefix interaction mechanically on both backends: route initialization inserts sink blocks directly into the exact list; sink blocks are excluded from the normal routed-candidate calculation, excluded from the token candidate bitmap, and excluded from the pooled tail. Token augmentation therefore only refines unrelated non-sink blocks and cannot consume or duplicate a biased exact sink block.
The current clean head
663bfa3ab5c29e9cff6b2ab68d7f287ea54ae6bbis one implementation commit directly on current upstreammain(21003fa97bf3b180393446d729ae630ceb6c2a52) and is mergeable. A pre-test checkpoint is retained atcheckpoint/pr-171-before-token-aug-test-20260911.For this exact head, CLA run
34563733264passed.Build Wheelsrun34563734866concludedaction_requiredbefore build execution because fork workflow authorization is required. That status is not a compiler failure and provides no CUDA/HIP numerical evidence.This draft therefore still requires a compiled supported-GPU run before review. Minimum CUDA acceptance is:
That covers zero-token-budget weighted cold/primed parity plus the enabled-token-routing interaction. HIP has structural/source parity but remains behaviorally unvalidated unless run on supported HIP hardware.
Architecture companion: https://github.com/xmarre/MiniMax-H3-Flow-Aligned-Regenerate/pull/29
Core contract: https://github.com/Comfy-Org/ComfyUI/pull/16239
Sol-H3 provider: https://github.com/xmarre/ComfyUI-Sol-H3/pull/9
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.