Repository navigation
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25435
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 Cancelled Jobs, 1 Unrelated FailureAs of commit 7fae210 with merge base 9f49fe2 ( CANCELLED JOBS - The following jobs were cancelled. Please retry:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
|
@claude /pr-review |
|
Claude finished @Gasoonjia's task in 50m 24s —— View job PR Review: #25435This PR adds NVFP4 KV-cache write and attention Triton ops, a pass that lowers the write for AOTInductor, and an opt-in Muse Glimmer Detailed reviewSummaryThe PR adds:
Problems found: the Code Quality
Infrastructure
Testing
API Design
RecommendationRequest Changes These block approval:
Input validation and the Tasks
|
|
Thanks.
|
|
@claude /pr-review |
|
Claude finished @Gasoonjia's task in 29m 47s —— View job PR Review: #25435Approve: nothing blocks. The remaining items are minor: both split-K dispatch tests pass whichever kernel runs, Detailed reviewSummaryThis PR adds NVFP4 KV-cache Triton ops to the CUDA backend: a fused write (K-norm, RoPE, quantize, store) and attention that decodes K/V exactly to FP16 (split-K decode, small-query split-K, chunked prefill). It also adds
This was a static review: nothing was built or run. API Design
Testing
Code Quality
RecommendationApprove. Nothing blocks. The test fix is two assertions. The rest is one docstring line and cleanups. Tasks
|
[ghstack-poisoned]
[ghstack-poisoned]
|
CI update: the A10G Authored with Claude Code. |
|
@claude /pr-review |
|
Claude finished @Gasoonjia's task in 42m 40s —— View job Approve: nothing blocks; what remains is gaps in the NVFP4 test coverage, and the widest split-K tile lacking the non-spilling configs and accumulator prune that the BF16 kernel has. Detailed reviewSummaryThis PR adds NVFP4 KV-cache Triton ops for CUDA: a fused K-norm/RoPE/quantize write, plus split-K and prefill attention that decode K/V exactly to FP16. It also adds Testing
Performance
Code Quality
RecommendationApprove. Nothing blocks merging. The most useful follow-up is checking each config's numerics in the exhaustive job: right now the configs that job adds are tuned but never checked against the reference. |
[ghstack-poisoned]
|
Follow-up: the exhaustive switch is now the directory's existing Authored with Claude Code. |
Stack from ghstack (oldest at bottom):
Adds an NVFP4 KV cache to the CUDA backend and a
--kv-cache-dtype nvfp4option to the Muse Glimmer in-graph CUDA export.Cache layout, per layer and per K/V: E2M1 codes (two per byte) and one E4M3 scale per 16 head_dim elements, with a unit global scale (as in SGLang/flashinfer):
s = e4m3(min(amax / 6, 448)), so magnitudes above 2688 clip. That is 4.5 bits per element (72 bytes per token-head at D=128 versus 256 for BF16).Kernels (
backends/cuda/triton/kernels/nvfp4_kv.py):triton::nvfp4_kv_writeruns the scaleless K RMS-norm, interleaved RoPE, NVFP4 quantization and the cache store as one kernel straight from the K/V projection output, for global (flat) and sliding-window (ring, slot =pos % capacity) layers. It replaces the BF16index_copy_.triton::nvfp4_sdpaattends over the NVFP4 cache: split-K decode (L_q = 1), small-query split-K (2 <= L_q <= 16) and a chunked-prefill flash kernel. Every path decodes K and V exactly to FP16 in registers (E2M1 x E4M3 has at most 6 significant bits and fits FP16), converts the BF16 query to FP16, and runs Q.K^T and P.V on FP16 MMAs with FP32 accumulation. Both ops (and their fakes) validate their operands (cache dtypes/shapes, contiguousinput_pos/inv_freq(read with unit stride), power-of-two head_dim, matching batch, heads and head_dim, BF16 query, bool[B, 1, L_q, L_kv]mask,kv_lenfor causal/window,k_norm_eps>= 0 or None); thenvfp4_sdpafake is contiguous like its output. Small-query split-K needs a concrete L_q and passessdpa.py's_small_query_tile_fits(rows, tile and shared-memory caps). On a global (flat) layer, a write past the end of the cache raises in eager instead of silently losing keys. Global layers are causal and bounded by a device-sidekv_len(CUDA-graph safe). Sliding-window layers compute the ring visibility in-kernel from absolute positions -- the same visibility as the model's dense ring mask -- and sweep only aboutwindowkeys.Hardware: E4M3 conversions are native on sm_89+ and E2M1 conversions on sm_120+ (the backend's native-FP4 rule). Older GPUs use software encode/decode paths that are bit-exact with the native instructions, so all GPUs write and read the same cache bytes. Kernels take the GPU arch as an
ARCHconstexpr computed on the host, for the device Triton compiles for (so they work in Inductor's forked compile workers).LowerNVFP4KVWritePass(CUDA backend pass) splices the write op's Triton kernel in place of theauto_functionalized[_v2]node (asserting the cache arguments are not views), so AOTInductor compiles it and re-inplaces the cache-buffer mutations instead of keeping an unsupported fallback op. It traces undertriton_mutation_cache, so the Triton access analysis runs once per kernel variant rather than once per layer.Export:
--kv-cache-dtype nvfp4makescuda_source_transformations(use_nvfp4_kv_cache=True)swap every layer's cache and attention forward (source_transformations/nvfp4_kv.py). It requires the in-graph cache path (not--use-offgraph-kv-cacheor--turboquant) and the model's gainless QK norm, which bounds K for the unit global scale (the install raises without it). Sliding-window layers keep the model's ring geometry (ring_buffer_size(window, max_prefill)= window + max_prefill - 1 slots, the same as the BF16 in-graph cache), so an export chunk of at mostmax_prefillkeeps every row's window.Known limitations:
kv_len(opt-in, CUDA-graph safe) is left as a follow-up.Authored with Claude Code.
Differential Revision: D132444825