mirror of
https://github.com/Comfy-Org/comfy-kitchen.git
synced 2026-11-04 23:37:42 +00:00
[PR #179] Add draft_attention for block-sparse video attention #196
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#196
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/179
Author: @Yusux
Created: 9/16/2026
Status: 🔄 Open
Base:
main← Head:anemoi-sparse-attention📝 Commits (6)
55c125afeat(attention): add anemoi block-sparse attention529e46cfix(kernels): launch the Ada set on every served SM6588350feat(attention): add native SM120 D64 support2817e13fix(kernels): CUDA 12.8 compatibility for SM120 instantiations6589e66Merge fork/main into anemoi-sparse-attentionb489f25refactor: Rename Anemoi implementation to Draft📊 Changes
93 files changed (+24455 additions, -2 deletions)
View changed files
📝
README.md(+1 -0)📝
comfy_kitchen/__init__.py(+74 -0)📝
comfy_kitchen/backends/cuda/CMakeLists.txt(+12 -2)📝
comfy_kitchen/backends/cuda/__init__.py(+125 -0)📝
comfy_kitchen/backends/cuda/dlpack_bindings.cpp(+7 -0)➕
comfy_kitchen/backends/cuda/draft/CMakeLists.txt(+131 -0)➕
comfy_kitchen/backends/cuda/draft/assembly/output_assembly.cu(+756 -0)➕
comfy_kitchen/backends/cuda/draft/attention/ada/LICENSE(+201 -0)➕
comfy_kitchen/backends/cuda/draft/attention/ada/attention_decl.cuh(+33 -0)➕
comfy_kitchen/backends/cuda/draft/attention/ada/instantiations/inst_k64_d128.cu(+31 -0)➕
comfy_kitchen/backends/cuda/draft/attention/ada/instantiations/inst_k64_d128_int8_dense.cu(+16 -0)➕
comfy_kitchen/backends/cuda/draft/attention/ada/instantiations/inst_k64_d64.cu(+31 -0)➕
comfy_kitchen/backends/cuda/draft/attention/ada/instantiations/inst_k64_d64_int8_dense.cu(+16 -0)➕
comfy_kitchen/backends/cuda/draft/attention/ada/instantiations/inst_q128_k64_d128.cu(+19 -0)➕
comfy_kitchen/backends/cuda/draft/attention/ada/instantiations/inst_q128_k64_d128_fp16.cu(+13 -0)➕
comfy_kitchen/backends/cuda/draft/attention/ada/instantiations/inst_q128_k64_d128_int8.cu(+13 -0)➕
comfy_kitchen/backends/cuda/draft/attention/ada/instantiations/inst_q128_k64_d64.cu(+19 -0)➕
comfy_kitchen/backends/cuda/draft/attention/ada/instantiations/inst_q128_k64_d64_fp16.cu(+13 -0)➕
comfy_kitchen/backends/cuda/draft/attention/ada/instantiations/inst_q128_k64_d64_int8.cu(+13 -0)➕
comfy_kitchen/backends/cuda/draft/attention/ada/k64_attention_decl.cuh(+98 -0)...and 73 more files
📄 Description
Summary
Adds
comfy_kitchen.draft_attention, a DraftMap-based block-sparse self-attention operation for packed video sequences, with a full-precision eager reference and native CUDA executors for NVIDIA GPUs from SM89 onward.The implementation is adapted from
anemoi-project/anemoirevisionbcb18202a4afd006749700370634de4819f9cc19. It consolidates option validation, layout planning, backend dispatch, native availability checks, and the CUDA executor behind one public Comfy Kitchen operation.What changed
comfy_kitchen.draft_attention(...)comfy_kitchen.draft_attention_is_available(device)[89, 120)with the Ada kernel set; SM120 uses the SM120a executor.tests/test_draft_attention.pycovering the public contract, option and layout validation, dispatch, availability, eager correctness, native stages, and CUDA reference execution.Public behavior
Inputs are equal-shaped BTHD fp16/bf16 tensors with batch size one plus a packed video shape and prefix length. The default profile is Q64 with 80% sparsity and an INT8 middle phase.
The native path is selected only when the complete executor was compiled for the current CUDA device and the call satisfies its constraints. CPU, unsupported accelerators, and CUDA devices without a matching compiled executor fall through to the full-precision eager reference instead of failing dispatch.
Benchmarks
End-to-end protocol
MiniMax H3 video generation through ComfyUI, with Yusux/ComfyUI@e65ddf0 and Yusux/comfy-kitchen-anemoi@2817e13 using:
minimax_h3_fl2va_pruned_fp8_scaled.safetensors(UNet)qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors(text encoder)minimax_h3_video_vae_fp16.safetensors+minimax_h3_audio_vae_fp32.safetensors(VAEs)These measurements were collected before the Anemoi-to-Draft rename. The tables use the current Draft name for the same implementation; E2E benchmarks were not rerun after the naming-only changes.
All runs use 1344×768, 124 frames, 24 FPS, and 50 sampling steps, with the
res_multistepsampler andsimplescheduler. The three scenes are city (seed 0), ocean (seed 0), and forest (seed 1234), with identical prompts across systems. Each scene/configuration has one six-step warmup followed by one 50-step formal run on a persistent server; warmup time is excluded. Reported E2E wall time runs from prompt submission to completion and includes sampling, video/audio VAE decode, and video saving. Completion is polled every two seconds.All sparse profiles use Q64 and
start_percent=0.2. This setting is converted to a sigma threshold rather than an integer step count. In all 27 formal sparse runs, Draft attention starts after the initial 11-step dense phase. Drop denotes the configured sparsity ratio; NVFP4/INT8 percentages describe the precision split of retained sparse work, not the model weights. The attention video grid is(37, 24, 42), with 56 heads, head dimension 128, and 473–479 prefix tokens (depending on the prompt).Cross-architecture E2E: Q64, Drop80, 100% INT8
Means across the three scenes (one formal run per scene/configuration). E2E speedups below are Dense mean time divided by sparse mean time:
SM89 and SM90 use the native Ada-family INT8 executor; the mixed NVFP4 attention profiles below were tested only on SM120. PSNR is computed over decoded RGB frames against each scene's Dense output on the same GPU, then averaged across scenes. It measures output similarity, not perceptual quality or cross-GPU numerical equivalence; audio is not scored.
RTX 5090 E2E: seven Q64 sparse profiles
All seven profiles use INT8 prefix K/V and prefix queries.
At matched Drop80, NV75/I25 reduces mean wall time by 5.32 s versus pure INT8 (about 1.014× additional speedup). Drop60/70 retain more sparse work and remain slower than Drop80 INT8.
RTX 5090 Q64 preparation / mainloop breakdown
Separate operator profiling at the city attention geometry:
B=1, T=37775, H=56, D=128, video grid(37, 24, 42), prefix length 479. Values are means of three CUDA-profiler captures per configuration. These are kernel-duration sums for preparation and native attention mainloop only, not full operator wall time and not the 50-step E2E measurement. Other stages and host overhead are excluded; sums below are rounded from unrounded values.Mixed NVFP4/INT8 adds approximately 1 ms of preparation, but at matched Drop80 its mainloop saving offsets that cost: prep + mainloop falls by 6.31% for NV60/I40 and 8.94% for NV75/I25. This component-level saving is diluted in E2E by the dense-first sampling portion and work outside sparse attention.
Provenance and licensing
The migrated implementation is adapted from the Apache-2.0 Anemoi source at revision
bcb18202a4afd006749700370634de4819f9cc19. SPDX headers, Ada/Blackwell license files, Blackwell provenance, and per-file upstream attribution are preserved.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.