Skip to content

[executorch][cuda] NVFP4 linear and embedding dispatch - #25342

Open
Gasoonjia wants to merge 11 commits into
gh/gasoonjia/217/basefrom
gh/gasoonjia/217/head
Open

Gasoonjia wants to merge 11 commits into
gh/gasoonjia/217/basefrom
gh/gasoonjia/217/head

Conversation

@Gasoonjia

@Gasoonjia Gasoonjia commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Adds eager and export-time linear/embedding dispatch for CudaNVFP4Tensor, compile-time precision and split-K selection, unit-scale integration, and a configurable prefill output dtype. Gemma CUDA weight packers accept NVFP4 tensors. The policy is fixed at export by ET_CUDA_NVFP4_ACT (auto times W4A16 against native W4A4, w4a16 forces weight-only) and ET_CUDA_NVFP4_PREFILL_OUTPUT, documented in nvfp4_dispatch. The non-Triton fallbacks honor the prefill output dtype; the linear fallback dequantizes in N chunks (chunked_dequant_linear) and the embedding fallback only the gathered rows, rejecting ids outside [0, N) with nvfp4_embedding's IndexError instead of letting indexing wrap negative ids. The Gemma packers share one NVFP4 branch. The autotuned auto prefill gets the traced M's bound like the kernels' split-K launches. The auto ops take the static activation scale as the weight's (1, 1) tensor (or None), so their mode/split-K launch key, like the kernels', sees only static versus dynamic and layers with different calibrated scales share one tuning per shape. The auto ops validate their operands and the scale once at entry; their W4A4 candidates call the unchecked launch (timing runs them on random stand-ins) and raise InvalidLaunchParam without native FP4, so tuning a program traced on SM120 on another GPU skips them instead of aborting.

PTE tests exercise serialized runtime programs, dynamic input sizes, fixed-prefill mode selection, split-K, per-output-row scales, and unit-scale behavior.

Authored with Claude Code.

Differential Revision: D132997584

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25342

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

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

NEW FAILURE - The following job has failed:

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.

@Gasoonjia

Copy link
Copy Markdown
Contributor Author

@claude /pr-review

@claude

claude Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Claude finished @Gasoonjia's task in 32m 0s —— View job


Request Changes: the new NVFP4 dispatch has no SM89 guard, makes importing quantize_op_dispatch require Triton, picks W4A4 vs W4A16 numerics by autotune timing behind undocumented env vars, and none of its new GPU tests run on any CI runner.

PR Review: #25342

Summary

This PR adds eager and export F.linear/F.embedding dispatch for CudaNVFP4Tensor. That covers autotuned W4A4 vs W4A16 and split-K, unit-scale GEMV, and an optional fp32 prefill output. It also adds NVFP4 routing in the Gemma 4 CUDA packers, plus PTE tests. The issues below need fixing or discussion before this lands.

Backward Compatibility

  • import executorch.backends.cuda.quantize_op_dispatch now requires Triton.
    • nvfp4_dispatch.py:17-28 imports nvfp4_output, nvfp4_quantized_gemm, nvfp4_tuning and quantized_gemm_family at module level.
    • Any one of those runs backends/cuda/triton/kernels/__init__.py, which eagerly imports conv/fused_moe/int4_matmul/sdpa/topk, and with them triton.
    • On the base branch, no dispatch or tensor module in this package imports Triton. int4_dispatch.py–int8_dispatch.py defer their kernel imports into the handlers. The function-level imports at :51, :74, :132 and :196 follow the same pattern, but the module-level imports defeat them.
    • CPU-only and macOS torch wheels don't ship Triton. CPU-side packing code that imports the package will fail at import there, e.g. examples/models/gemma4_31b/tests/test_cuda_packers.py:18 and quant/tests/test_pack_cuda.py:18.
    • CI won't catch this, because the only job that runs those files is on A10G, which has Triton.
    • Fix:
      • Move _MODE_*, _prefill, _decode and the triton::nvfp4_auto_* ops into nvfp4_quantized_gemm.py, next to the other triton::nvfp4_* ops.
      • Inline nvfp4_output.py into the dispatch. It contains no kernel and has a single consumer.
    • Fix this →
  • gemma4_31b:quant doesn't declare //executorch/backends/cuda:nvfp4_tensor.
    • cuda_packers.py:62 and :137 now import CudaNVFP4Tensor unconditionally at function entry.
    • Any Buck consumer of :quant that doesn't get nvfp4_tensor some other way now fails for every weight type (INT4/INT5/INT6/INT8/GGUF), not just NVFP4.
    • The new test_nvfp4_packers target declares the dep itself, which hides the gap.
    • Add the dep next to coalesced_int4_tensor in examples/models/gemma4_31b/BUCK:17-19. Fix this →

API Design

  • The default auto policy picks numerics by timing.
    • On SM120, nvfp4_auto_prefill/nvfp4_auto_decode (nvfp4_dispatch.py:87-111) let AOTI autotuning choose between W4A16 and W4A4 for each layer. W4A4 quantizes activations to FP4.
    • Accuracy therefore depends on which candidate was faster on the export machine. The choice can differ between layers, between prefill and decode, and between two exports of the same checkpoint, and the user can't see it.
    • Precision should be an explicit, deterministic choice. Default to W4A16, make W4A4 opt-in through a tensor attribute (like act_per_tensor_scale/unit_scale) or a recipe, and limit autotuning to split-K within the chosen precision.
  • Undocumented process-global env vars change numerics and output dtype at trace time.
    • ET_CUDA_NVFP4_ACT is read from os.environ inside the handler (nvfp4_dispatch.py:119).
    • ET_CUDA_NVFP4_PREFILL_OUTPUT is read behind assume_constant_result (nvfp4_output.py:17).
    • Neither is recorded on the tensor or in a compile spec, and no doc or README mentions either one.
    • The fp32-output contract is also applied unevenly:
      • The fallback at nvfp4_dispatch.py:130 ignores output_dtype, so CPU eager returns bf16 where CUDA/export returns fp32.
      • Static-small decode keeps the input dtype while prefill returns fp32, so one layer's output dtype differs between the prefill and decode methods.
      • fp32 activations reach the kernels only under this policy, and _launch_w4a16_impl (nvfp4_quantized_gemm.py:970-971) then rounds them to bf16.
    • Suggest turning both settings into tensor attributes or recipe/compile-spec options, and documenting them.
    • The one-line module docstring at nvfp4_dispatch.py:5 and the package docstring in quantize_op_dispatch/__init__.py (which still lists only INT4–INT8) should also cover NVFP4.

Infrastructure

  • None of the new GPU/PTE tests run in any CI.
    • Every new GPU test skips below SM89 (e.g. test_nvfp4_export.py:29-32, test_nvfp4_fusion.py:24-27). The W4A4, auto, unit-scale and fixed-prefill cases also skip without SM120.
    • The new fbcode test_nvfp4_dispatch target runs on subplatform = "A100" (SM80), and its PTE tests return under is_fbcode() before executing.
    • OSS runs backends/cuda/tests on A10G (SM86, .github/workflows/cuda.yml:529).
    • Only the CPU max_norm test and the packer tests actually execute. Kernel numerics, dispatch routing, split-K export and runtime execution are not checked by any automation.
    • Either add an SM89+/SM120 runner or subplatform, or state in the test plan that these tests are manual-only.
  • test_nvfp4_packers makes a backend test target depend on an example target (//executorch/examples/models/gemma4_31b:quant). It only exercises cuda_packers.py, so it belongs in examples/models/gemma4_31b/tests/test_cuda_packers.py. Fix this →

Testing

  • New paths with no coverage:
    • The _embedding success path is untested: CUDA F.embedding/nn.Embedding, the swapped-argument aten.embedding branch (nvfp4_dispatch.py:193), export/PTE, and the CPU fallback. test_embedding_bias_dispatch calls the raw nvfp4_embedding kernel, and the only test that reaches _embedding is the CPU max_norm rejection (test_nvfp4_fusion.py:33-46).
    • The default path on SM89/SM90 (auto → nvfp4_w4a16, :167-170) is never exported through F.linear with dynamic M. The dispatch PTE cases that run on those GPUs are all static M=1 (GEMV), and the auto cases skip without native FP4.
    • No test sets ET_CUDA_NVFP4_PREFILL_OUTPUT=fp32.
    • The packers' ExportableNVFP4Tensor → from_exportable branch is untested.
    • Every fixture uses register_buffer, but the packers produce an nn.Parameter, which goes through detach. Should one PTE case use a Parameter?
    • Fix this →
  • Checks that can't fail, and fixture hygiene:
    • The post-load env changes (test_nvfp4_export.py:137-146, test_nvfp4_fixed_prefill.py:88) can never fail, because nothing in the compiled .so reads ET_CUDA_NVFP4_ACT.
    • Uniform block scales (test_nvfp4_export.py:40, test_nvfp4_split_k_export.py:40) would hide block-scale indexing bugs across split-K. Use random E4M3 bytes, as test_nvfp4_unit_scale.py:36 does.
    • test_nvfp4_fixed_prefill.py:23 imports PackedLinear from another test module.
    • test_nvfp4_fixed_prefill.py:37-38/107-111 saves and restores the env by hand even though the test already takes monkeypatch.
    • test_nvfp4_unit_scale.py:145 hardcodes // 64 instead of using _MODE_STRIDE.
    • Fix this →

Performance

  • The fallbacks dequantize the whole weight.
    • _linear (nvfp4_dispatch.py:130) calls F.linear(flat, w.dequantize(x.dtype)) instead of chunked_dequant_linear (_gemm_family_dispatch.py:67). Every INT4–INT8 dispatch uses that helper, and it exists to avoid ~10 GiB of temporaries on the 262144-row lm_head.
    • _embedding (:195) dequantizes the full table just to gather a few rows. dequantize builds int64 codes plus fp32 per-element scales, which comes to ~20 GB of temporaries for a 262144×5376 table.
    • Triggers: CPU eager, and fp32 activations on CUDA outside the fp32-prefill policy. Under export, the full dequant is traced into the graph.
    • Fix this →

Code Quality

  • No SM89 gate before the Triton kernels.
    • On SM80/SM86 (A100, A10G), bf16/fp16 inputs still take the Triton branch. can_launch_triton only checks for a CUDA or fake tensor, and _has_native_fp4() == False just switches the mode to W4A16.
    • That path reaches nvfp4_gemv/nvfp4_w4a16 and nvfp4_embedding, which use tl.float8e4nv. Triton rejects that type below SM89, which is why this PR's own tests skip there.
    • The result is a Triton error during eager calls and AOTI compilation, where the code should fall back instead. That contradicts _gemm_family_dispatch.py:19 ("dispatch never raises for them").
    • Add an assume_constant_result capability ≥ (8, 9) check that takes the fallback or raises a clear error. Fix this →
  • detach/alias/t/_to_copy are registered in the dispatch module (nvfp4_dispatch.py:205-219), even though they define CudaNVFP4Tensor semantics.
    • aoti_packed_int4_tensor.py:139-151 registers the same handlers next to its class.
    • As written, ops like w.t() behave differently depending on whether quantize_op_dispatch has been imported, and the packers create nn.Parameters without importing it.
    • Fix this →
  • _has_native_fp4 (nvfp4_dispatch.py:33-35) duplicates _has_native_fp4_conversion (nvfp4_quantized_gemm.py:114-116). Is major >= 12 meant to exclude SM100/SM103 (B200/GB300) from W4A4? Fix this →
  • The NVFP4 branch is duplicated in pack_linear_for_cuda and pack_embedding_for_cuda (cuda_packers.py:70-84 and :145).
    • Neither the module docstring nor the function docstrings mention NVFP4.
    • The comment at :71-72 says the loader "pairs it by name and calls to_exportable_nvfp4_tensor itself". However, no non-test code calls to_exportable_nvfp4_tensor (defined at extension/llm/export/gguf.py:424). Does [executorch][cuda] NVFP4 fused gated GEMM and dispatch #25343 add that loader path? If not, GGUF NVFP4 always raises here.
    • Fix this →

Recommendation

Request Changes

Concrete fixes needed:

  • the missing SM89 guard, which is a hard failure on A100/A10G-class GPUs
  • the package-wide Triton import
  • the missing Buck dep
  • the full-weight dequant fallbacks

Needs discussion:

  • precision selected by timing
  • configuration through env vars

None of the new GPU tests run in CI, so none of the kernel or dispatch behavior in this PR is checked by automation.

Review steps
  • Gather PR context and diff
  • Run three independent reviewers
  • Consolidate findings
  • Fact-check findings
  • Post review

…code down so A100 CI runs the NVFP4 kernels

[ghstack-poisoned]
@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 31m 8s —— View job


Approve: nothing blocks, but two small issues remain. FP32 activations, including ones under a forced ET_CUDA_NVFP4_ACT=w4a4, fall back to a dense dequantize + matmul everywhere except prefill under the FP32 output policy. And on a device without native FP4, the autotuned W4A4 candidates crash AOTI tuning instead of being skipped.

PR Review: #25342

Summary

This PR routes F.linear/aten.linear and F.embedding/aten.embedding on CudaNVFP4Tensor to the Triton NVFP4 GEMV, W4A16, W4A4 and embedding kernels, adds NVFP4 to the Gemma 4 31B CUDA packers, and adds export and PTE tests. It also adds:

  • autotuned nvfp4_auto_prefill/nvfp4_auto_decode ops that time activation mode and split-K under ET_CUDA_NVFP4_ACT=auto
  • an FP32 prefill output policy
  • a chunked dequant fallback

Two minor issues remain and nothing blocks.

API Design

  • FP32 activations bypass the NVFP4 kernels and the ET_CUDA_NVFP4_ACT policy (backends/cuda/quantize_op_dispatch/nvfp4_dispatch.py:153-163). allowed_dtype accepts FP32 only when nvfp4_prefill_output_dtype returns FP32. The dense chunked_dequant_linear fallback is also taken before the w4a4/native checks at lines 171-176. The effects:

    • FP32 decode always goes dense. At M ≤ 4 the output policy always returns None, so FP32 decode exports a dense dequantize + FP32 matmul under either ET_CUDA_NVFP4_PREFILL_OUTPUT setting. nvfp4_gemv could run it, since it keeps FP32 math (nvfp4_quantized_gemm.py:895 and :1140-1141, and _launch_gemv_impl allocates its output in x.dtype at :833).
    • A forced w4a4 is silently ignored. With FP32 input, ET_CUDA_NVFP4_ACT=w4a4 gives dense numerics, and a device without native FP4 raises no SM120 error. The module docstring says w4a4 "forces FP4 activations (native FP4 required)", and BF16 input on such a device does raise (test_linear_policy_errors).
    • No test covers either case. Every test_linear_routing input is BF16 (backends/cuda/tests/test_nvfp4_fusion.py:131).

    Fix:

    • Send FP32 decode to the GEMV path.
    • Run the w4a4 checks before the dtype fallback, and raise when the input can't run W4A4.
    • Add FP32 rows to test_linear_routing and test_linear_policy_errors.

    Fix this →

Code Quality

  • W4A4 autotune candidates crash AOTI tuning on a device without native FP4 instead of being skipped (backends/cuda/quantize_op_dispatch/nvfp4_dispatch.py:67-70 and :89-91).

    • Why it fails:
      • _MODE_SPLITS (lines 45-47) always includes the mode-1 (W4A4) candidates, and their branches call nvfp4_w4a4.
      • nvfp4_w4a4 raises RuntimeError on devices without native FP4 (nvfp4_quantized_gemm.py:591-592).
      • _run_prepass and _time_candidates catch only InvalidLaunchParam (backends/cuda/autotune/launch_params.py:233 and :278).
    • When it happens (rare): _linear emits the auto ops only when _has_native_fp4() is true at trace time. It takes an ExportedProgram traced on SM120 and lowered on SM89/SM90, or code that calls triton::nvfp4_auto_prefill/nvfp4_auto_decode directly.
    • Fix:
      • Raise InvalidLaunchParam in both fp4 branches when not _has_native_fp4(), so tuning falls back to W4A16.
      • test_auto_bodies_forward_mode_split then needs _has_native_fp4 patched to True.
      • Drop the _check_split at line 90: _launch_w4a4_impl already runs a stricter version of it with m/n (nvfp4_quantized_gemm.py:536).

    Fix this →

Recommendation

Approve

Both issues are minor. The first affects only FP32 activations, and the second only lowering the auto ops on a device without native FP4. They can land in this PR or a follow-up.

Review steps
  • Gather PR context and diff against origin/gh/gasoonjia/217/base
  • Run three independent reviewers
  • Consolidate findings
  • Fact-check findings
  • Post review

@Gasoonjia

Copy link
Copy Markdown
Contributor Author

Thanks. Round 7:

  • W4A4 candidates without native FP4: the fp4 branches of _prefill and _decode now raise InvalidLaunchParam, so AOTI tuning skips them and picks among the W4A16 candidates; it no longer aborts. I dropped the redundant _check_split in _decode. The branches call the unchecked _launch_w4a4_impl, and the auto ops validate their operands and scale once at entry. test_auto_bodies_forward_mode_split now patches native FP4 on, and expects InvalidLaunchParam from both bodies when it is off (CPU). A CUDA test tunes nvfp4_auto_prefill with a static scale and checks that W4A4 candidates are timed only with native FP4; it runs on the A100.
  • FP32 dense fallback: I agree, but it's deferred. Sending FP32 decode to the GEMV and enforcing w4a4 before the dense fallback changes routing that the later soft-W4A8, dequant-prefill and small-M commits build on, so it needs its own change and tests.

@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 33m 46s —— View job


Approve: the NVFP4 dispatch is ready to land, with three minor test gaps left (the CPU routing tests only run in the A100 target, no case covers a forced w4a16 on native FP4, and the split-K PTE file does 36 lowerings that never reach the dispatch).

PR Review: #25342

Summary

The PR sends F.linear/aten.linear and F.embedding/aten.embedding on CudaNVFP4Tensor to the Triton NVFP4 kernels, adds the autotuned triton::nvfp4_auto_prefill/nvfp4_auto_decode ops that choose W4A16 or W4A4 and the split-K during AOTI, and makes the Gemma4-31B packers produce CudaNVFP4Tensor. Three minor issues remain, all in test placement and coverage; nothing blocks.

Infrastructure

  • The CPU routing tests only run in the A100 target (backends/cuda/tests/targets.bzl:658-665)

    • 24 cases in test_nvfp4_fusion.py never touch a GPU: test_linear_routing, test_linear_policy_errors, test_auto_bodies_forward_mode_split, test_calibrated_activation_scale_reaches_w4a4, test_auto_ops_run_their_first_candidate_outside_tuning, test_embedding_routing, and the CPU-fallback and max_norm tests.
    • Each one either runs in CPU eager or traces under FakeTensorMode, which can_launch_triton accepts on any host (_gemm_family_dispatch.py:45). _has_native_fp4 is patched in each.
    • Their only target is test_nvfp4_dispatch, a python_unittest_remote_gpu on A100. The routing and policy checks for this PR's dispatch run only when an A100 is allocated, and a CPU-only test run never reaches them.
    • This file already splits tests this way: test_nvfp4_launch_validation_cpu (python_pytest, :667-678) sits next to its remote-GPU twin (:680-694).
    • Fix: add a CPU python_pytest for test_nvfp4_fusion.py, following test_nvfp4_launch_validation_cpu. The file's @CUDA tests skip on a CPU host.

    Fix this →

Testing

  • No case covers a forced w4a16 on a native-FP4 target (backends/cuda/tests/test_nvfp4_fusion.py:90-104)

    • Every w4a16 row sets native=False. In that case nvfp4_dispatch.py:193-198 rewrites the mode to "w4a16" anyway, so these rows can't tell an explicit ET_CUDA_NVFP4_ACT=w4a16 apart from the no-FP4 fallback.
    • Trigger: a refactor that tests _has_native_fp4() instead of mode at nvfp4_dispatch.py:209 or :222 would send a forced W4A16 on SM120 to nvfp4_auto_decode/nvfp4_auto_prefill. Those ops can pick W4A4 at AOTI, overriding the explicit policy, and all ten rows still pass.
    • Fix: add ("w4a16", True, 37, False, "nvfp4_w4a16") and ("w4a16", True, 1, False, "nvfp4_gemv").

    Fix this →

  • test_nvfp4_split_k_export.py runs 36 full lowerings and never reaches the dispatch (backends/cuda/tests/test_nvfp4_split_k_export.py:46-78)

    • SplitLinear.forward calls the nvfp4_gemv/nvfp4_w4a16/nvfp4_w4a4 kernel ops directly with split_k, so nothing in nvfp4_dispatch.py runs.
    • Each of the 36 cases does its own torch.export → to_edge_transform_and_lower (AOTI compile) → PTE.
    • The 24 gemv/w4a16 cases need no native FP4. Once the SM89 skip is relaxed ([executorch][cuda] NVFP4: exact software E4M3 scale decode below SM89 #25411), they run on every pass of test_nvfp4_dispatch and of the cuda.yml system shard (.github/workflows/cuda.yml:538).
    • test_row_scale_gemv and test_row_scale_gemm (test_nvfp4_fusion.py:362-395) already cover every split in eager mode.
    • Fix: build one module per (mode, row_scales) that holds one linear per split and checks every output (6 lowerings instead of 36), or move the file to the PR that adds split_k.

    Fix this →

Recommendation

Approve. The three items are minor test gaps that can land as follow-ups; none changes an exported program.

Review steps

  • Gather the PR context, the diff against gh/gasoonjia/217/base, and the earlier review rounds
  • Run three independent reviewers
  • Consolidate their findings
  • Fact-check each finding against the code
  • Post the 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 24m 59s —— View job


Approve: nothing blocks; the new quick sweep lists use a second exhaustive-tests switch that no Buck target sets and drop W4A4 split-K PTE cases that no CI runner runs anyway, and four smaller test and docstring gaps remain.

PR Review: #25342

Summary

This PR routes F.linear/F.embedding on CudaNVFP4Tensor to the Triton NVFP4 kernels (GEMV, W4A16, W4A4 and the AOTI-timed auto ops), adds an FP32 prefill output policy, and makes the Gemma 4 31B packers produce CudaNVFP4Tensor. Nothing blocks. Three of the six minor items below come from the latest update, which made the tests use quick sweep lists by default. Points declined in earlier rounds are not repeated.

API Design

  • The module docstring says auto picks the precision "per layer" (backends/cuda/quantize_op_dispatch/nvfp4_dispatch.py:10-11).

    • The mode_split pick is cached by the decorated function, the device name, and the argument shapes, strides and dtypes (backends/cuda/autotune/launch_params.py:155-164, :342, :356-361). Every layer with the same weight shape therefore gets the same precision and split-K, as the PR description says.
    • The PR description sends users to this docstring for the policy, so it should say "per weight shape".

    Fix this →

Infrastructure

  • The NVFP4 sweeps add a second exhaustive-tests switch, and no Buck target sets it (backends/cuda/tests/targets.bzl:633-640, :658-665).

    • sweep reads ET_CUDA_NVFP4_EXHAUSTIVE_TESTS (nvfp4_test_utils.py:14, lower in the stack).
    • This directory already has EXECUTORCH_CUDA_EXHAUSTIVE_TESTS for the same purpose (test_conv_implicit_gemm.py:29-32), with the opposite convention: the Buck target sets it (targets.bzl:168), and only the OSS shards run the reduced cases.
    • Neither test_nvfp4_kernels nor test_nvfp4_dispatch sets either variable, and nothing in .github/ does at this commit. Until Add an NVFP4 GGUF solo Muse Glimmer CUDA e2e job #25437 lands, no job runs the full lists; after that, only its one OSS job does.
    • Setting the existing variable leaves the NVFP4 tests on the quick lists with no warning.
    • Fix: read EXECUTORCH_CUDA_EXHAUSTIVE_TESTS in sweep. Then either set it in env on the two A100 targets, as test_conv_implicit_gemm does, or say in the sweep comment that Buck runs the quick lists on purpose.

    Fix this →

Testing

  • The W4A4 quick list cuts PTE coverage without saving any CI time (backends/cuda/tests/test_nvfp4_split_k_export.py:55-69).

    • The quick pairs [(False, 1), (True, 8)] also apply to w4a4.
    • W4A4 is the only mode whose _reduce_partials call applies the scales and takes ROW_PTS from pts (nvfp4_quantized_gemm.py:551-570). GEMV and W4A16 always pass ROW_PTS=False there (:866-877, :1111-1122).
    • By default, then, no PTE runs W4A4 with a scalar global scale at split-K > 1 (an unfused weight), or with per-row scales at split 1 (a fused weight). The file docstring at :5 ("Run every split-K path…") no longer holds. Eager tests still cover both cases.
    • The cut saves nothing. W4A4 skips without native FP4 (:68-69), which needs SM120 or newer (nvfp4_quantized_gemm.py:197-202), and neither the A10G nor the A100 runners have it.
    • The W4A4 half of test_row_scale_gemm (test_nvfp4_fusion.py:374-378) is in the same position.
    • Fix: keep the full list for w4a4, or add (True, 1) and (False, 8) for it.

    Fix this →

  • The GEMV and row-scale GEMM quick lists stop at split 8 (backends/cuda/tests/test_nvfp4_fusion.py:363, :374).

    • _launch_gemv_impl accepts every split candidate at any K (nvfp4_quantized_gemm.py:833), so the decode tuners can pick 16 or 32.
    • SPLIT is a constexpr in the GEMV autotune key (:800), so 16 and 32 are separately compiled kernels, and no default test checks either one against a reference. test_gemv_split_k (test_nvfp4_kernels.py:316, lower in the stack) has the same [1, 8] list.
    • In test_row_scale_gemm, the k = 4224 if split == 32 branch (:379) never runs by default.
    • The sibling test_gemm_split_k keeps 32 in its quick list ([4, 32], test_nvfp4_kernels.py:301). Use [1, 32] here too, which is the same number of cases.

    Fix this →

  • The native=False branch of test_packed_modules_export_nvfp4_ops can't catch a wrong linear op (backends/cuda/tests/test_nvfp4_packers.py:88).

    • It only checks that there are two distinct triton.nvfp4_* targets.
    • That still holds if the linear lowers to nvfp4_auto_prefill or nvfp4_w4a4 instead of nvfp4_w4a16, and preventing that is the job of the fallback at nvfp4_dispatch.py:193-198.
    • Fix: assert "triton.nvfp4_w4a16.default" in nodes.

    Fix this →

  • Still open from round 7: no routing row forces w4a16 on native FP4 (backends/cuda/tests/test_nvfp4_fusion.py:90-104).

    • Every w4a16 row has native=False, where _linear rewrites the mode to w4a16 anyway (nvfp4_dispatch.py:193-198). The table therefore never checks the one case where ET_CUDA_NVFP4_ACT=w4a16 changes the routing.
    • Suppose a regression sent a forced w4a16 on SM120 to nvfp4_auto_prefill/nvfp4_auto_decode, which can pick W4A4 at AOTI time. Every row would still pass.
    • Fix: add ("w4a16", True, 37, False, "nvfp4_w4a16") and ("w4a16", True, 1, False, "nvfp4_gemv").

    Fix this →

Recommendation

Approve. All six items are minor test, CI and docstring fixes. They can land in this PR or in a follow-up.

Review steps
  • Gather PR context and diff against origin/gh/gasoonjia/217/base
  • Run three independent reviewers
  • Consolidate findings
  • Fact-check findings
  • Post review

@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 — c875a5b1 Deployed Nov 23, 2026 by Gasoonjia via upload-benchmark-results #23162
cadence — c875a5b1 Deployed Nov 23, 2026 by Gasoonjia via hifi-op-test / hifi4 #40335
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