Skip to content

[executorch][cuda] NVFP4 KV cache with exact FP16 attention - #25435

Open
Gasoonjia wants to merge 10 commits into
gh/Gasoonjia/142/basefrom
gh/Gasoonjia/142/head
Open

Gasoonjia wants to merge 10 commits into
gh/Gasoonjia/142/basefrom
gh/Gasoonjia/142/head

Conversation

@Gasoonjia

@Gasoonjia Gasoonjia commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Adds an NVFP4 KV cache to the CUDA backend and a --kv-cache-dtype nvfp4 option 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_write runs 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 BF16 index_copy_.
  • triton::nvfp4_sdpa attends 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, contiguous input_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_len for causal/window, k_norm_eps >= 0 or None); the nvfp4_sdpa fake is contiguous like its output. Small-query split-K needs a concrete L_q and passes sdpa.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-side kv_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 about window keys.

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 ARCH constexpr 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 the auto_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 under triton_mutation_cache, so the Triton access analysis runs once per kernel variant rather than once per layer.

Export: --kv-cache-dtype nvfp4 makes cuda_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-cache or --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 most max_prefill keeps every row's window.

Known limitations:

  • The decode split-K chunk size follows the cache buffer length, not the live length. Sizing the split-K chunks from the device-side kv_len (opt-in, CUDA-graph safe) is left as a follow-up.
  • Not included: a variant that runs prefill Q.K^T on FP4 tensor cores (lower accuracy) and a Q4_1 KV cache.

Authored with Claude Code.

Differential Revision: D132444825

@pytorch-bot

pytorch-bot Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

🔗 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 Failure

As of commit 7fae210 with merge base 9f49fe2 (image):

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.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 22, 2026
@Gasoonjia

Copy link
Copy Markdown
Contributor Author

@claude /pr-review

@claude

claude Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Claude finished @Gasoonjia's task in 50m 24s —— View job


PR Review: #25435

This PR adds NVFP4 KV-cache write and attention Triton ops, a pass that lowers the write for AOTInductor, and an opt-in Muse Glimmer --kv-cache-dtype nvfp4 export path. I recommend Request Changes: the nvfp4_sdpa fake has a different memory layout than the real op, the kernels pick native instructions from the export host's GPU rather than the AOTI target, and no test lowers the model path through AOTI.

Detailed review

Summary

The PR adds:

  • triton::nvfp4_kv_write: fused K RMS-norm, RoPE, NVFP4 quantize and store;
  • triton::nvfp4_sdpa: split-K decode, small-query split-K and chunked prefill over the NVFP4 cache;
  • LowerNVFP4KVWritePass;
  • an NVFP4 KV cache for the Muse Glimmer CUDA export.

Problems found: the nvfp4_sdpa fake's layout differs from the real output's, ARCH comes from the export host instead of the compile target, the public ops validate no inputs, and no test goes through AOTI or the native conversion paths.

Code Quality

  • nvfp4_sdpa's fake has a different layout than the op (backends/cuda/triton/kernels/nvfp4_kv.py:995).
    • torch.empty_like(query) keeps a non-contiguous query's strides. The implementation returns a contiguous torch.empty((B, H_q, L_q, D)) (:933), and the sdpa.py fakes also allocate contiguous outputs (e.g. sdpa.py:1504).
    • The query is non-contiguous on NoPE layers: xq.transpose(1, 2) runs with no RoPE after it (examples/models/muse-glimmer/source_transformations/nvfp4_kv.py:86).
    • So at export, y.transpose(1, 2).contiguous() (:136) is a no-op, and y.reshape(B, T, -1) (:140) is recorded as a view.
    • AOTI then substitutes the implementation's contiguous output, and that view is stride-incompatible for T > 1.
    • Today only torch.sigmoid(og) * y restores a contiguous layout, because its contiguous operand comes first. A config with use_attn_o_gate=False (model/model.py:38) breaks.
    • Fix: return query.new_empty(query.shape). Fix this →
  • Question (low confidence): small-magnitude V blocks under the unit global scale.
    • With the global scale fixed at 1.0, the block scale e4m3(min(amax/6, 448)) (nvfp4_kv.py:210) is subnormal for amax < 6·2⁻⁶ ≈ 0.094. It rounds to 0 for amax ≤ 6·2⁻¹⁰ ≈ 0.0059, which zeroes the whole block.
    • In the subnormal range, the round-to-nearest scale can be ~1.5× too small. For example, amax ≈ 0.0176 gets scale 2⁻⁹, so the block maximum saturates at 6 and loses up to a third of its magnitude.
    • K is RMS-normalized before quantization; V is not. The PR description only discusses saturation at the top of the range.
    • If Muse Glimmer's V can have 16-element blocks below ~0.1, a per-head FP32 global scale (as in standard NVFP4) would avoid this.
  • LowerNVFP4KVWritePass ignores auto_functionalized_v2 view metadata (backends/cuda/passes/lower_nvfp4_kv.py:82-88).
    • The pass passes _all_bases[_<name>_base_index] straight to the kernel.
    • When a mutated arg is a view of its base (for example a cache slice), v2 also passes _<name>_* kwargs to rebuild the view. The pass drops them, so the kernel would write into the base at the wrong offsets.
    • The Muse Glimmer caller passes whole buffers, so this is latent. Assert that no view kwargs are present for the four mutated args.
  • _nvfp4_kv_write_impl's docstring says it is "registered as the op's decomposition in the CUDA backend" (nvfp4_kv.py:299-304). Nothing registers it; LowerNVFP4KVWritePass splices it in. Point the docstring at the pass.
  • Nits:
    • _load_kv_tile_bf16 returns FP16 (its docstring, nvfp4_kv.py:138); rename it.
    • nvfp4_kv.py:159 passes ARCH >= 89 inside the else of if ARCH >= 89, so the value is always False; pass False.
    • install_nvfp4_kv_cache(ring_capacity=...) is never passed by its only caller (export_solo.py:794). The documented requirement that it covers window + longest step - 1 is never checked. Drop the parameter or assert the requirement.
    • In install_nvfp4_kv_cache, int(old_bytes if old_bytes else 0) is just old_bytes, and the returned summary is unused. NVFP4KVCache.nbytes() is a helper used once, and NVFP4KVCache.length is unused.
    • install_nvfp4_kv_cache overwrites the _lenaware_attention_forward that cuda_source_transformations installs just before it (export_solo.py:788-794). A KV-cache option on cuda_source_transformations, like use_turboquant, would avoid installing a forward and then replacing it.

Infrastructure

  • ARCH comes from the export host's GPU, not the AOTI compile target (backends/cuda/triton/kernels/nvfp4_kv.py:71-75, passed at :332, :638, :896).
    • cuda_arch() reads torch.cuda.get_device_capability().
    • The CUDA backend compiles for the TORCH_CUDA_ARCH_LIST target (backends/cuda/cuda_backend.py:1210-1219, target_sm at :1252-1267) and can emit multi-arch kernels (:1536, :1563).
    • sdpa.py:84-96 already handles this case ("Match the target selected by AOTInductor rather than assuming that the export host is also the inference target").
    • As written, an SM80/86/90 variant exported on a Blackwell host contains E2M1 cvt instructions (and, for SM8x, float8e4nv conversions) that the target cannot compile or run.
    • An H100/B200 variant exported on an A100 silently ships the software paths.
    • Fix: derive ARCH from _nvcc_arch_as_compile_option(), as _cuda_compile_target_is_sm90_or_newer does. It is evaluated at trace time, so the forked-worker constraint noted at :66-69 still holds. Fix this →
    • Native E2M1 is enabled at ARCH >= 100 (:97, :167), but the existing _has_native_fp4_conversion() requires major >= 12 (nvfp4_quantized_gemm.py:247-253). SM100/103 was not among the validated GPUs (A100, RTX 5090). Use one shared rule.
    • The torch.version.hip branch that returns 0 does not make the kernels ROCm-safe, because the software decode still emits PTX mul.rn.f16x2 (:184-191).
  • test_nvfp4_kv_cache.py and test_nvfp4_kv_bitexact.py are not in KERNEL_TESTS (.github/workflows/cuda.yml:538-559). Per the comment there, they will run in the system shard, unlike the analogous test_triton_sdpa*.py and test_tq4_sdpa.py.

Testing

  • No test lowers the model path through AOTI.
    • Nothing compares install_nvfp4_kv_cache/_nvfp4_kv_attention_forward with the BF16 attention, and nothing under examples/models/muse-glimmer references NVFP4.
    • test_pass_inlines_write_kernel (backends/cuda/tests/test_nvfp4_kv_cache.py:283-316) exports a toy module with a static T=8, applies the pass, and runs ep.module() eagerly. It never goes through CudaPartitioner/AOTInductor.
    • Two claims are therefore unverified: that Inductor turns the functional write back into an in-place write of the cache buffers, and that the pass's make_fx retrace (lower_nvfp4_kv.py:98-100) works with the export's dynamic seq_len (export_solo.py:814).
    • The test makes a single call and never compares the buffers, or a second call that reads them, with eager. So len(mutated) == 4 does not show that the writes reach the right buffers.
    • Add a small-config Muse Glimmer test that lowers with kv_cache_dtype="nvfp4", runs prefill and then decode, and compares against the BF16 export within a quantization tolerance.
  • CI only runs the software conversion paths.
    • The Buck targets run on A100 (SM80, backends/cuda/tests/targets.bzl) and the OSS job on A10G (SM86, cuda.yml:529), so native E4M3 (ARCH >= 89) and native E2M1 (ARCH >= 100) never run in CI.
    • The manual runs (A100, RTX 5090) covered all-software and all-native. They did not cover the mixed SM89–99 case (native E4M3 with software E2M1: L4, L40S, H100), so the docstring's "passing on two GPUs proves" (test_nvfp4_kv_bitexact.py:11) does not hold for it.
    • Each check already takes ARCH as a parameter. Sweep ARCH over {80, 89, 100}, up to the device's capability, so a single run on a new GPU checks every path against the reference.
  • The prefill kernel is never tested at the lengths the export sends it.
    • Eager calls with a concrete L_q <= 16 take split-K, so _nvfp4_prefill_kernel only ever sees L_q >= 512 (test_nvfp4_kv_cache.py:185-188, :233-241).
    • In the export, seq_len is dynamic in [5, max_prefill] and statically_known_true(L_q <= 16) is false. Every prefill chunk, including chunks of 5–16 tokens, runs the prefill kernel.
    • The dispatch boundaries L_q = 2 and L_q = 17 are untested too.
    • Call _launch_nvfp4_prefill directly with small L_q values and with values that are not tile multiples.
  • The assertions are too coarse to catch localized bugs.
    • Every attention check is one whole-tensor Frobenius ratio, rel(out, ref) < 1e-2 (test_nvfp4_kv_cache.py:175, :212, :218, :222). The expected error is ~1e-3 (BF16 output rounding against exact K/V), so about a dozen completely wrong rows out of the 131072 in an L_q = 4096 case still pass. Bugs in tail tiles, mask boundaries or the split-K merge would show up exactly like that. Add a per-row max-error bound.
    • The tile-decode check gives every D/16 group in a row the same scale (test_nvfp4_kv_bitexact.py:147-149). A wrong byte-to-scale mapping, including in the SF_GATHER half // 8 path, therefore passes. Use a distinct scale per group.
  • The SHA-256 fixture is brittle and gives no diagnostics (test_nvfp4_kv_bitexact.py:229-243, :283-291).
    • The digests depend on the exact bits of CPU randn/logspace output.
    • They also depend on the K path's non-IEEE math: 1.0 / tl.sqrt, tl.cos/tl.sin, and FMA contraction of ke * c - ko * s (nvfp4_kv.py:265-276).
    • A PyTorch, Triton or ptxas upgrade can change the digests with no kernel regression, and a failure only shows a different hash.
    • Build the inputs from a deterministic integer pattern, and report the first rows that differ on a mismatch.

API Design

  • k_norm_eps=-1.0 is a sentinel that switches K-norm on or off (nvfp4_kv.py:297, :330, :351).

    • K-norm only runs when k_norm_eps > 0, so eps=0.0 silently disables it.
    • The sentinel is repeated in the pass (lower_nvfp4_kv.py:96) and in the caller (source_transformations/nvfp4_kv.py:106).
    • Use Optional[float] = None with NORM_K=k_norm_eps is not None. Fix this →
  • The public ops validate none of their inputs. nvfp4_kv_write and nvfp4_sdpa do not check:

    • that the caches are uint8;
    • the D/2 and D/16 last dimensions;
    • that H_kv and D agree between k, v, the query and the caches;
    • batch size or contiguity;
    • H_q % H_kv == 0;
    • that the query is BF16, as documented.

    Consequences:

    • The write kernel computes row offsets as (b * H + h) * L + slot, from k's batch and k_q.shape[2] (nvfp4_kv.py:259). A k batch larger than the cache's (NVFP4KVCache allocates batch 1), or a sliced or non-contiguous cache, writes out of bounds or into the wrong rows with no error.
    • The prefill kernel stores acc.to(tl.bfloat16) (:836) whatever query.dtype is. An FP16/FP32 query is rounded through BF16 on prefill but not on decode.

    sdpa.py validates in both the op and its fake (_validate_sdpa_inputs at :991/:1338, _validate_qkv_shapes at :233/:1502); do the same here.

Recommendation

Request Changes

These block approval:

  • the nvfp4_sdpa fake's layout: a one-line fix for a latent AOTI failure;
  • selecting ARCH from the compile target: without it, cross-target and multi-arch exports compile the wrong instruction set;
  • a test that lowers the Muse Glimmer NVFP4 path through CudaPartitioner/AOTI with dynamic seq_len and checks prefill and decode against BF16.

Input validation and the k_norm_eps signature should change before other callers adopt these ops. The rest can be follow-ups.

Tasks
  • Gather PR context and diff
  • Run three independent reviews
  • Consolidate findings
  • Fact-check findings
  • Post final review

@Gasoonjia

Copy link
Copy Markdown
Contributor Author

Thanks.

  • New test_masked_split_k_widest_tile: a masked L_q 16 step at 16:1 GQA asserts _launch_nvfp4_splitk ran, on its widest tile (BLOCK_M 256, the packed-decode shape).
  • test_global_small_query now checks the real unmasked boundary: L_q 2/4/8 take split-K and L_q 9 takes the prefill kernel.
  • Both pass on the RTX 5090 and A100.

@Gasoonjia

Copy link
Copy Markdown
Contributor Author

@claude /pr-review

@claude

claude Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Claude finished @Gasoonjia's task in 29m 47s —— View job


PR Review: #25435

Approve: nothing blocks. The remaining items are minor: both split-K dispatch tests pass whichever kernel runs, nvfp4_sdpa doesn't document that the query must fit in FP16, and there are three nits.

Detailed review

Summary

This 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 LowerNVFP4KVWritePass for AOTI and the Muse Glimmer --kv-cache-dtype nvfp4 export path. Nothing blocks. The findings are:

  • two dispatch tests that can't fail on the dispatch change they target;
  • an undocumented range limit on the query;
  • three nits.

This was a static review: nothing was built or run.

API Design

  • nvfp4_sdpa doesn't state that the query must fit in FP16 (backends/cuda/triton/kernels/nvfp4_kv.py:550-555, :819-824; docstring :993-1005).
    • Both kernels load the BF16 query and convert it to FP16 before any scaling.
    • BF16 values inside FP16's range convert exactly. Any |q| > 65504 becomes inf, and the output turns into NaN. Nothing checks or documents this limit.
    • Muse Glimmer is safe, because Q is RMS-normed before RoPE. Callers of the public op that don't normalize Q are not.
    • Fix: state the bound in the docstring. Fix this →

Testing

  • The split-K dispatch tests pass whichever kernel runs (backends/cuda/tests/test_nvfp4_kv_cache.py:196-202, :267-274).
    • test_masked_split_k_widest_tile asserts launcher.call_count >= 1. _sliding(9000, 16) makes three nvfp4_sdpa calls, each with 256 rows at head_dim 128:

      • The dense-mask call (:242) and the window-plus-mask call (:252) take split-K, because _small_query_tile_fits(256, 128, True) holds.
      • The unmasked in-kernel-window call (:247) takes the prefill kernel, because 256 × 128 is larger than _SMALL_QUERY_MAX_UNMASKED_TILE (sdpa.py:89).

      The count should therefore be exactly 2. With >= 1, the test still passes if a dispatch change sends one of the two masked calls, for example the windowed one, to prefill.

    • test_global_small_query only compares outputs against the reference, and both kernels give the same result.

      • Its comment, and the latest reply, describe a boundary: L_q 2–8 take split-K and L_q 9 takes prefill. Nothing asserts it.
      • Suppose _small_query_tile_fits or the dispatch at nvfp4_kv.py:1023-1028 changed to send every L_q > 1 to prefill. No test would fail. Causal small-query split-K would also lose its only coverage, since this is the only test that runs split-K with MASK_IS_CAUSAL at L_q > 1.
    • Fix:

      • Use assertEqual(launcher.call_count, 2).
      • In test_global_small_query, wrap both launchers with the same mock.patch.object(..., wraps=...).

      Fix this →

Code Quality

  • Nits:
    • examples/models/muse-glimmer/source_transformations/nvfp4_kv.py:117: the else None can never run, because install_nvfp4_kv_cache raises unless k_norm is a RMSNormNoWeight (:159-160). Pass self.k_norm.eps directly.
    • n_tot in _check_e2m1_encode (backends/cuda/tests/test_nvfp4_kv_bitexact.py:103, :113) is never read.
    • nvfp4_kv_dequantize_reference (backends/cuda/triton/kernels/nvfp4_kv.py:1077-1107) is a test-only helper inside a kernel module. No other module in backends/cuda/triton/kernels/ has one. Its only user is test_nvfp4_kv_cache.py, so move it there, next to ref_quant.
    • Fix this →

Recommendation

Approve. Nothing blocks. The test fix is two assertions. The rest is one docstring line and cleanups.

Tasks
  • Gather PR context and author replies
  • Run three independent reviews
  • Consolidate findings
  • Fact-check findings against the code
  • Post review

@Gasoonjia

Copy link
Copy Markdown
Contributor Author

CI update: the A10G unittest-cuda (system) job hit the 2-hour limit on the top of this stack (NVFP4 tests were ~60 min on A100, more on A10G). This PR's tests now run representative cases by default via sweep(full, quick) in nvfp4_test_utils; the full lists run with ET_CUDA_NVFP4_EXHAUSTIVE_TESTS=1, which the new unittest-cuda-nvfp4-exhaustive job in #25437 sets. No kernel or dispatch code changed in this update. Whole-stack NVFP4 test time on A100: 3582 s -> 752 s.

Authored with Claude Code.

@Gasoonjia

Copy link
Copy Markdown
Contributor Author

@claude /pr-review

@claude

claude Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

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 review

Summary

This 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 LowerNVFP4KVWritePass and Muse Glimmer's --kv-cache-dtype nvfp4 export path. I found no blocking issues. This is a static review: nothing was run, because the runner has no torch or GPU.

Testing

  • Exhaustive mode doesn't check every config's numerics (backends/cuda/tests/test_nvfp4_kv_cache.py:29-31). The comment says all configs run with ET_CUDA_NVFP4_EXHAUSTIVE_TESTS=1. Triton's autotuner does benchmark every config for a key, but it returns the output of the fastest one only. So in both modes each test checks a single config per key. The exhaustive job adds the other 7 split-K and 7 prefill configs to tuning, not to the numerics checks. An export on another GPU can then pick a config, such as BLOCK_N 256 or num_stages 3, whose tail and mask handling no test has compared against the reference. To fix it, in exhaustive mode run one shape per path with each config pinned in turn (kernel.configs = [c]; kernel.cache.clear()), skipping configs that fail to compile as test_autotune_inputs.py:223-233 does. Otherwise, reword the comment. Fix this →
  • The routing assertions are still loose (open from the last round). test_masked_split_k_widest_tile (:302) asserts call_count >= 1. With keep=0.5, both masked nvfp4_sdpa calls in _sliding (:269, :279) route to split-K, because _small_query_tile_fits(256, 128, True) holds. The test would still pass if either call fell back to the prefill kernel, so assert == 2. test_global_small_query (:221-228) still asserts none of the routing its comment describes (L_q 2/4/8 take split-K, 9 takes prefill). Wrapping _launch_nvfp4_splitk and _launch_nvfp4_prefill the same way would pin it. Fix this →

Performance

  • The widest masked split-K tile has no config that both avoids register spills and is known to fit in shared memory (backends/cuda/triton/kernels/nvfp4_kv.py:460-474; still open).

    • The kernel is routed through _small_query_tile_fits. Its caps were measured against the configs that _small_query_splitk_prune keeps (sdpa.py:86-88), but this kernel has no such prune.
    • The widest tile is BLOCK_M 256, the packed-decode shape (masked L_q 9-16 at 16:1 GQA, D 128). At that size, 7 of the kernel's 9 configs (the 2- and 4-warp ones) hold 256-512 FP32 accumulators per thread. That is 2-4× the 128 the prune allows.
    • Only BLOCK_N 128 and 256 at 8 warps stay under that limit. Meanwhile setUpModule keeps BLOCK_N 32 because "the small BLOCK_N fits the widest split-K tile".
    • So adding the prune alone could leave no config that fits the 99 KB of shared memory on SM86/89/120. Add the BLOCK_N 32/64 num_warps=8 configs from sdpa.py:2023-2024 along with the prune, and keep one of them in the quick subset.
    • Low confidence on the shared-memory part: I did not compile the NVFP4 8-warp configs to check their footprint.

    Fix this →

Code Quality

  • examples/models/muse-glimmer/tests/test_cuda_pipeline.py:409 uses a bare assert inside a TestCase. Python strips it under -O, and on failure it doesn't say which layer. Use self.assertIsInstance per layer, as :439-440 does. Fix this →

Recommendation

Approve. 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.

@Gasoonjia

Copy link
Copy Markdown
Contributor Author

Follow-up: the exhaustive switch is now the directory's existing EXECUTORCH_CUDA_EXHAUSTIVE_TESTS (as in test_conv_implicit_gemm.py) instead of a new ET_CUDA_NVFP4_EXHAUSTIVE_TESTS, in code, the commit message and #25437's job.

Authored with Claude Code.

This branch was successfully deployed

1 active and 1 inactive deployments
upload-benchmark-results — 7fae210f Deployed Nov 23, 2026 by Gasoonjia via upload-benchmark-results #23177
cadence — 7fae210f Deployed Nov 23, 2026 by Gasoonjia via hifi-op-test / hifi4 #40350
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant