Skip to content

[executorch][cuda] NVFP4 packed tensor and metadata - #25339

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

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

Conversation

@Gasoonjia

@Gasoonjia Gasoonjia commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Adds CudaNVFP4Tensor for byte-packed E2M1 weights and N-major K16 E4M3 block scales. Supports scalar or per-output-row global scales, lossless output-channel fusion, device/dtype conversion, and serializable unit-scale metadata.

The portable fuse_along_output still rejects NVFP4 weights with differing global scales; CUDA fuses those after packing with CudaNVFP4Tensor.fuse_along_output, which keeps one global scale per output row. unit_scale asserts that the global scale is 1 (the multiply can be skipped) and that every scale byte is a non-negative finite E4M3 value (each E2M1 x E4M3 product is exact in BF16); from_exportable sets it. A scalar global scale is stored as a 2-D (1, 1) tensor: Inductor inlines 1-D constants of up to 8 elements as fill kernels that run on every call, which end-to-end profiling of Muse Glimmer showed as one extra kernel per NVFP4 weight per decode token. The optional static activation scale (act_per_tensor_scale) is a float32 (1, 1) tensor field rather than a Python float, so kernels read it from memory and layers with different calibrated scales share one compiled kernel and one tuning per shape; the constructor takes a Python number or a one-element float32 tensor on the weight's device and rejects non-finite or non-positive values: a number is checked on the host against the normal float32 range (so meta and fake weights are checked and nothing is read back from the device), a real tensor's value on construction (fake and meta tensors carry none). Its value keeps the portable input_scale convention, amax / (6 * 448), and None means dynamic per-row scaling. The constructor rejects a non-float32 global scale, a non-floating output dtype and fields on different devices; dequantize reuses torchao's FP4 unpacking. test_nvfp4_tensor.py is CPU-only and is now collected by the CPU pytest job.

CPU tests cover the packed layout, validation, dequantization against the portable reference, fusion, fake-tensor reconstruction, and serialization.

Authored with Claude Code.

Differential Revision: D131418679

[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/25339

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

❌ 1 Cancelled Job, 1 Pending

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

CANCELLED JOB - The following job was cancelled. Please retry:

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 20m 29s —— View job


No confirmed bugs in the new CudaNVFP4Tensor, but its fusion path contradicts the documented shared fuse_along_output contract, unit_scale is an undocumented and unvalidated flag, and from_exportable is never checked numerically against the portable reference — Needs Discussion.

Detailed review

PR Review: #25339

Summary

Adds CudaNVFP4Tensor (byte-packed E2M1 weights with N-major K16 E4M3 scales and a scalar or per-row global scale), plus conversion from ExportableNVFP4Tensor, output-channel fusion and CPU tests. No functional bug was confirmed. The main problems are a second fusion API whose rules contradict the shared one, an undocumented and unvalidated unit_scale contract, and test inputs that cannot catch a layout error in from_exportable. The upstack consumers (#25340+) are not in this checkout, and Python could not be run here, so every finding comes from reading the code.

API Design

  • A second fuser whose rules contradict the shared one — backends/cuda/nvfp4_tensor.py:84-119. extension/llm/export/quant/convert.py:fuse_along_output already fuses ExportableNVFP4Tensor and documents that fusion "happens once on the portable form before backend packing", with "no backend-specific concat needed" (convert.py:27-30, 94-96). It rejects differing per_tensor_scale (convert.py:153, 184-192). This PR adds a same-named, CUDA-only fuser on the packed form that accepts them. Trigger: gate/up quantized with the default ExportableNVFP4Config(use_per_tensor_scale=True) get distinct amax-derived global scales. The existing loader (examples/models/muse-glimmer/loaders/checkpoint_loader.py:354-360) calls the shared fuser, catches the ValueError and keeps the projections separate. So the new lossless path is reachable only by callers that know to skip the shared fuser and fuse after from_exportable. Please say which path the CUDA loader will take and update the convert.py docstrings to match. Moving per-row global scales into the portable form instead would also need torchao::dequantize_nvfp4 to accept an (N, 1, 1) global scale (extension/llm/export/nvfp4.py:60 multiplies a scalar).
  • unit_scale is a trusted flag with an undocumented, unchecked invariant — nvfp4_tensor.py:29, 59, 66-73, 118. Its meaning exists only as the expression in from_exportable: global scale == 1 and every block-scale byte < 0x7F (non-negative, non-NaN E4M3). The name conveys only the first half. __new__ accepts any value, so CudaNVFP4Tensor(q, s, torch.tensor([0.5]), unit_scale=True) constructs fine, and to() and fusion pass it along. An upstack kernel that skips the global-scale multiply on this flag would therefore silently return wrong values. Conversely, identical weights get False when constructed directly or converted while meta/fake, so the kernel path depends on how the tensor was built. Document the invariant on the class, and compute or validate it in __new__ for materialized data, trusting the passed value only for meta/fake reconstruction. The consumer is upstack and was not reviewed. Fix this →

Infrastructure

  • The CPU-only test runs only on a GPU runner in OSS, and not when the format it converts from changes — backends/cuda/tests/test_nvfp4_tensor.py. It is not in pytest.ini testpaths (only backends/cuda/tests/test_remap_pte_devices.py is, line 92). OSS therefore runs it only in the unittest-cuda system shard, on an A10G after a full CUDA build (.github/workflows/cuda.yml:538-539, 647). Neither that workflow's pull_request.paths (cuda.yml:24) nor the job condition (cuda.yml:500-515) covers extension/llm/export/**. A PR that changes ExportableNVFP4Tensor, whose layout from_exportable reinterprets, won't run this test before merge. Add the test to pytest.ini next to test_remap_pte_devices.py. Fix this →

Testing

  • from_exportable and the multi-block scale mapping are never checked against the reference — nvfp4_test_utils.py:25-32, test_nvfp4_tensor.py:93-124.

    • portable_weight uses all-zero uint32 qdata and one repeated scale byte, so every from_exportable test dequantizes to zeros.
    • test_dequantize_low_nibble_first uses K=16 (one block per row) with scale byte 56 (=1.0), and compares against a copy of the class's own LUT.
    • The multi-block fusion tests only compare dequantize() with itself.

    As a result, a wrong uint32→uint8 byte order, nibble order or K-major scale read would pass every test. Quantize a random bf16 nn.Linear with ExportableNVFP4Config (with and without use_per_tensor_scale) and assert torch.equal(CudaNVFP4Tensor.from_exportable(w).dequantize(), w.dequantize()). Fix this →

  • Tests bypass the constructor and skip the rejection paths.

    • test_nvfp4_tensor.py:22, 38, 42 assign per_tensor_scale / act_per_tensor_scale on already-built tensors. This skips __new__'s validation and normalization, so per-row-scale fusion inputs never go through the public constructor. Build new tensors instead.
    • shards() reseeds the global RNG (nvfp4_test_utils.py:11). Use a local torch.Generator.
    • Missing cases:
      • fusion rejection for mismatched K/dtype/device, an empty list, or a non-NVFP4 input;
      • the K % 16 rejection (half_k % 8);
      • to(device), although the description claims device conversion (to("meta") works on CPU);
      • unit-scale inference with mixed scale bytes, since uniform torch.full bytes can't tell torch.all from torch.any.

    Fix this →

Performance

  • dequantize reimplements the reference decode with an (N, K) int64 index — nvfp4_tensor.py:121-147. .long() (line 123) materializes an int64 index for the LUT gather. That is 8 B per element, about 5 GB for a 151936×4096 embedding. The LUT is also copied into the test (test_nvfp4_tensor.py:100-119). The neighbouring CudaCoalescedInt4Tensor.dequantize is documented as serving the tied lm_head / token embedding (coalesced_int4_tensor.py:218-219), so this path can see vocab-sized weights. Call the portable op instead: torch.ops.torchao.dequantize_nvfp4(self.qdata.view(torch.uint32), self.scale, self.per_tensor_scale.reshape(-1, 1, 1), self.block_size, output_dtype=...). It broadcasts an (N, 1, 1) global scale against its (M, K/16, 1) block scales (extension/llm/export/nvfp4.py:57-61), which makes the CUDA reference identical to the portable one by construction. I checked this by reading only, not by running it. Fix this →

Code Quality

  • Validation gaps — nvfp4_tensor.py:31-46, 63.

    • __new__ doesn't check that scale / per_tensor_scale are on qdata.device. The wrapper takes its device from qdata only, and lines 43-45 say per_tensor_scale becomes a Triton device pointer. As a result CudaNVFP4Tensor(q.cuda(), s.cuda(), torch.tensor([0.25])) is accepted, and fusion compares only w.device.
    • It doesn't check that per_tensor_scale is float32; torch.cat at line 110 silently promotes mixed dtypes.
    • It doesn't check that orig_dtype is a floating dtype; only to() does.
    • from_exportable doesn't check its input type, unlike AotiPackedInt4Tensor.from_intx_unpacked_to_int8_tensor (aoti_packed_int4_tensor.py:50-54). torchao's own NVFP4Tensor with per_tensor_scale=None fails at line 71 with an unrelated TypeError.

    Fix this →

  • Fusion depends on tensor values (low confidence, not run) — nvfp4_tensor.py:106-108. torch.equal chooses between a scalar and a per-row global scale. It is a data-dependent op, so fusing meta/fake weights, which from_exportable explicitly supports, will likely raise. Ignore this if fusion only ever runs on materialized weights.

  • Test style doesn't match the directory — backends/cuda/tests/targets.bzl:2, 617-621. This is the only python_pytest target in the file, with a load added just for it. test_nvfp4_tensor.py is also one of only two of the 55 backends/cuda/tests/test_*.py files that don't use unittest. Use unittest.TestCase with python_unittest, like the rest of the file.

Recommendation

Needs Discussion

No bug is confirmed. Two contracts should be settled before the upstack kernels depend on them: the fusion design (which fuser the CUDA loader uses, given that this PR contradicts the convert.py contract) and unit_scale. The from_exportable reference test and the pytest.ini entry are cheap and should land with this PR.


  • Gather context (diff, changed files, CLAUDE.md)
  • Run independent reviewer panel (3 reviewers)
  • Consolidate findings
  • Fact-check findings
  • Post final review

…code down so A100 CI runs the NVFP4 kernels

[ghstack-poisoned]
@Gasoonjia

Copy link
Copy Markdown
Contributor Author

Thanks. Round 6:

  • __new__ now checks tensor activation scales as well as Python numbers. A tensor must be a one-element float32 tensor on the weight's device; it is no longer silently cast or moved. A number is converted to float32 first, so 1e39 becomes inf and is rejected. On any real (non-fake, non-meta) tensor, the value must be finite and positive; fake and meta tensors are skipped because they carry no values.
  • Tests add tensor 0, -1, inf and nan, an overflowing float, a bfloat16 tensor and a meta tensor.
  • New test_from_exportable_carries_activation_scale: a portable weight's scale arrives as a float32 (1, 1) tensor, and a portable act_per_tensor_scale=0.0 is rejected at packing.

@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 27m 15s —— View job


Nothing blocks. Three minor problems remain: the round-6 check validates a Python-number activation scale only after moving it to the weight's device (so meta and fake weights skip the check and CUDA weights sync), the class docstring no longer defines that scale's value convention, and no test reaches the check's meta branch. Approve.

Detailed review

PR Review: #25339

Summary

Adds CudaNVFP4Tensor, with from_exportable, output-channel fusion and CPU tests. The tensor holds byte-packed E2M1 weights, N-major K16 E4M3 scales, a scalar (1, 1) or per-row (N,) global scale, and an optional float32 (1, 1) activation scale. Nothing blocks, but three minor problems remain:

  • the round-6 check validates a Python-number activation scale only after turning it into a device tensor;
  • round 5 removed the docstring's definition of that scale's value;
  • the check's meta branch, and a few older branches, have no test.

The upstack consumers (#25340+) and the torch/torchao sources are not in this checkout, and Python couldn't be run here. Every finding comes from reading the code.

Code Quality

  • A Python-number activation scale is validated only after it becomes a device tensor (backends/cuda/nvfp4_tensor.py:70-92).

    • The usual input is a host float. ExportableNVFP4Tensor stores the scale as a Python float (extension/llm/export/nvfp4.py:105-110), and from_exportable passes it through (nvfp4_tensor.py:129).
    • Meta and fake weights skip the check. Line 73 first puts the number on qdata.device, then lines 84-88 skip meta and fake tensors. The value was known on the host all along.
      • So from_exportable succeeds on a meta portable weight with act_per_tensor_scale=0.0 (or -1.0 or nan). On CPU, the same weight is rejected (test_from_exportable_carries_activation_scale).
      • The same happens under FakeTensorMode, where the tests already call from_exportable (test_unit_scale_metadata_survives_fake_to_fusion_and_serialization).
    • CUDA weights sync on construction. When an activation scale is present, line 87 does a blocking device-to-host read. This happens in from_exportable, which copies a host float to the GPU only to read it back, and in every to() that lands on CUDA (line 192). The reason given for keeping unit_scale trusted was that checking it "would add a device sync and cannot run during fake reconstruction". This check has both drawbacks.
    • Fix: check a Python number on the host before line 73, after rounding it to float32 so 1e39 still fails. That covers the in-tree producer on every device and in every mode, with no sync. For tensor inputs, either read values only where that needs no sync (CPU, not fake), or keep the sync deliberately, knowing it is the cost that ruled out checking unit_scale.

    Fix this →

API Design

  • The class docstring no longer says what the activation scale's value means (backends/cuda/nvfp4_tensor.py:21-23).

    • Round 5 replaced "act_per_tensor_scale keeps its ExportableNVFP4Tensor meaning" with a sentence that gives only the scale's shape and dtype, and why it is a tensor.
    • The convention now lives only in the portable docstring (extension/llm/export/nvfp4.py:75-80). There the value is the ModelOpt/GGUF input_scale, amax / (6 * 448), and None means activations are scaled dynamically per row.
    • "Activation global scale" alone is ambiguous: FlashInfer- and vLLM-style quantize kernels take the reciprocal, 6 * 448 / amax, as their global scale.
    • Nothing in this PR reads the field (dequantize ignores it). An upstack kernel that assumed the other convention would compute wrong activations, and nothing here would catch it.

    Restore the cross-reference, or state the convention and what None means. Fix this →

Testing

  • No test covers the meta branch of the activation-scale check, or to() moving the scale (backends/cuda/tests/test_nvfp4_tensor.py:92-97, 140).

    • test_to_meta_keeps_layout uses weight(), which has no activation scale.
    • The meta case in test_invalid_activation_scale_rejected (line 140) puts only the scale on meta. The device check (nvfp4_tensor.py:74-82) rejects it before the meta guard (nvfp4_tensor.py:85) is reached.
    • So the suite would stay green if act.device.type != "meta" and were deleted from that guard. Yet w.to("meta") on a weight with an activation scale would then fail with a RuntimeError from bool() on a meta tensor.
    • Still untested from earlier rounds:
      • the device check in fusion (nvfp4_tensor.py:147);
      • the scale half of the device check (nvfp4_tensor.py:68);
      • a save/load or fake round trip of a per-row (N,) per_tensor_scale.

    Fix this →

Recommendation

Approve

Nothing blocks. The host-side number check is a few lines and finishes the round-6 change. The docstring clause pins the convention down before upstack kernels depend on it.


  • Gather context (diff, changed files, CLAUDE.md)
  • Run independent reviewer panel (3 reviewers)
  • Consolidate findings
  • Fact-check findings
  • Post final review

@Gasoonjia

Copy link
Copy Markdown
Contributor Author

Thanks. Round 7:

  • A Python-number activation scale is checked on the host before it is placed on the device. It must fall in the normal float32 range, so 0, negatives, NaN, inf and 1e39 are rejected. This works for meta and fake weights and needs no device read. A tensor scale keeps the shape/dtype/device checks, and its value is checked when it is a real tensor. I moved the check into a small _act_scale_tensor helper, which keeps __new__ under the complexity limit.
  • The class docstring states the convention again: the ModelOpt/GGUF input_scale, amax / (6 * 448), not its reciprocal; None means dynamic per-row scaling.
  • New test for meta and fake weights. to("meta") moves the scale. A zero meta tensor is accepted because it carries no value. A number is still checked for meta and fake weights, and a meta portable weight with scale 0.0 is rejected by from_exportable.

@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 21m 23s —— View job


Nothing blocks. The only new problems are in the round-7 _act_scale_tensor helper and are minor: it accepts subnormal tensor scales that it rejects as numbers, and (low confidence) it builds a real scale tensor for a fake weight when no FakeTensorMode is active. Two device checks also still have no test. Approve.

Detailed review

PR Review: #25339

Summary

Adds CudaNVFP4Tensor, plus from_exportable, output-channel fusion and CPU tests. The tensor holds:

  • byte-packed E2M1 weights;
  • N-major K16 E4M3 scales;
  • a scalar (1, 1) or per-row (N,) global scale;
  • an optional float32 (1, 1) activation scale.

No functional bug was found. The remaining problems are all minor:

  • _act_scale_tensor, added in round 7, applies a different value rule to numbers than to tensors;
  • its number branch may create a real tensor inside a fake weight (low confidence);
  • two device checks have no test.

The upstack consumers (#25340+) and the torch/torchao sources are not in this checkout, and Python couldn't be run here. Every finding comes from reading the code.

Code Quality

  • Numbers and tensors get different value rules (backends/cuda/nvfp4_tensor.py:18-19 vs 30-35).

    • Numbers: they must be a normal float32 (f32.tiny <= act <= f32.max), as the round-7 reply says.
    • Tensors: they only need isfinite(act) & (act > 0), so positive subnormals pass.
    • Example: act_per_tensor_scale=1e-40 raises "must be finite and positive", which is wrong because the value is positive. torch.tensor([1e-40]) is accepted.
    • Test gap: no real calibration produces a scale that small, so this only affects consistency. test_invalid_activation_scale_rejected has no subnormal case, so changing either bound breaks no test.
    • Fix: in the tensor branch, check torch.isfinite(act) & (act >= f32.tiny), and make both error messages name the real rule.

    Fix this →

  • The number branch may create a real tensor inside a fake weight (backends/cuda/nvfp4_tensor.py:23). Low confidence; not run.

    • Why: torch.tensor(act, dtype=torch.float32, device=device) takes no tensor argument, so it returns a fake tensor only while a FakeTensorMode is active.
    • Who hits it: ExportableNVFP4Tensor stores the activation scale as a Python float (extension/llm/export/nvfp4.py:105-110), so from_exportable always takes this branch.
    • Trigger: fake a portable weight with mode.from_tensor(w), then call from_exportable outside with mode:. Every other op in from_exportable and __new__ still works there, because a fake tensor dispatches to its own mode.
    • Result: fake qdata/scale/per_tensor_scale next to a real act_per_tensor_scale. torch's is_fake fails its "got mixed fake and real tensors!" assertion on such a wrapper.
    • Test gap: the round-7 test builds fake weights only inside with mode:, and only checks that bad values are rejected (backends/cuda/tests/test_nvfp4_tensor.py:111-114).
    • Fix: pass qdata to the helper and build the tensor with qdata.new_full((1, 1), act, dtype=torch.float32). That is real, meta or fake, matching qdata.

    Fix this →

Testing

  • Two device checks still have no test (raised in earlier rounds, no reply yet).

    • The checks: the scale half of the constructor's device check (backends/cuda/nvfp4_tensor.py:97), and the device check in fusion (:155).
    • Current tests: the device case in test_invalid_layout_rejected moves only per_tensor_scale (backends/cuda/tests/test_nvfp4_tensor.py:308-309). test_fusion_rejects_incompatible_weights (lines 79-89) has no device case. Either check can be deleted and the suite stays green.
    • Fix: both can be tested on CPU, with s = s.to("meta") and fuse_along_output([a, a.to("meta")]).

    Fix this →

Recommendation

Approve

Nothing blocks. Each _act_scale_tensor fix is a line or two, and the missing tests are cheap to add.


  • Gather context (diff, changed files, CLAUDE.md)
  • Run independent reviewer panel (3 reviewers)
  • Consolidate findings
  • Fact-check findings
  • Post final 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 20m 17s —— View job


Nothing blocks. The one new problem is in the latest commit: its sweep helper reads a new ET_CUDA_NVFP4_EXHAUSTIVE_TESTS switch, but this directory already uses EXECUTORCH_CUDA_EXHAUSTIVE_TESTS for the same purpose, and no test in this PR calls sweep. Three minor items from round 7 are still open, with no reply. Approve.

Detailed review

PR Review: #25339

Summary

Adds CudaNVFP4Tensor, with from_exportable, output-channel fusion and CPU tests. The tensor holds byte-packed E2M1 weights, N-major K16 E4M3 scales, a (1, 1) or per-row (N,) global scale and an optional (1, 1) activation scale.

Since the last review, only backends/cuda/tests/nvfp4_test_utils.py changed: 9396ed7 adds EXHAUSTIVE and sweep. I found no functional bug. The remaining problems are all minor:

  • the new sweep switch duplicates one this directory already has, and nothing in this PR uses it;
  • two _act_scale_tensor items and two untested device checks from round 7 are still open, with no reply.

The upstack PRs (#25340+, including the #25437 CI job) and the torch/torchao sources are not in this checkout. Python couldn't be run here, so every finding comes from reading the code.

Code Quality

  • Numbers and tensors get different activation-scale ranges (raised last round, no reply), at backends/cuda/nvfp4_tensor.py:19 vs :30-35.

    • A number must be a normal float32. A tensor only needs to be finite and positive.
    • So act_per_tensor_scale=1e-40 raises "must be finite and positive" even though it is both, while torch.tensor([1e-40]) is accepted.
    • Fix: check act >= torch.finfo(torch.float32).tiny in the tensor branch too, and make both error messages state the actual rule.

    Fix this →

  • A number scale on fake weights becomes a real tensor outside FakeTensorMode (low confidence, not run; raised last round, no reply), at backends/cuda/nvfp4_tensor.py:23.

    • Cause: torch.tensor(act, ..., device=device) takes no tensor argument, so it returns a fake tensor only while a mode is active.
    • Who hits it: from_exportable always takes this branch, because ExportableNVFP4Tensor stores the scale as a Python float (extension/llm/export/nvfp4.py:105-110).
    • Result: calling from_exportable(mode.from_tensor(w)) outside with mode: puts a real activation scale next to fake qdata/scale/per_tensor_scale. torch's is_fake rejects that wrapper with "got mixed fake and real tensors!".
    • Test gap: the only fake case in the tests runs inside the mode, and only with a value that is rejected (backends/cuda/tests/test_nvfp4_tensor.py:111-114).
    • Fix: qdata.new_full((1, 1), act, dtype=torch.float32) follows qdata, whether it is real, meta or fake.

    Fix this →

Infrastructure

  • sweep adds a second switch for the full test sweeps, at backends/cuda/tests/nvfp4_test_utils.py:11-17.

    • Existing switch: this directory already has one, for the same reason. test_conv_implicit_gemm.py:29-32 reads EXECUTORCH_CUDA_EXHAUSTIVE_TESTS because "the OSS CI's CUDA shards have no time for the full sweeps". Its A100 Buck target sets that variable (backends/cuda/tests/targets.bzl:168).
    • Consequence: once upstack tests call sweep, setting the existing variable gives only the quick NVFP4 lists. No Buck target or workflow in this checkout sets ET_CUDA_NVFP4_EXHAUSTIVE_TESTS. So unless the upstack NVFP4 Buck targets add an env entry for it, internal A100 runs also get only the quick lists. I couldn't check this, because those targets are upstack.
    • Unused in this PR: no test here calls sweep or reads EXHAUSTIVE; test_nvfp4_tensor.py:13-16 imports only portable_weight and shards. So the latest comment's "This PR's tests now run representative cases by default via sweep" doesn't apply to this PR.
    • Fix: read EXECUTORCH_CUDA_EXHAUSTIVE_TESTS instead. Set it from Add an NVFP4 GGUF solo Muse Glimmer CUDA e2e job #25437 and from the upstack A100 Buck targets, the way test_conv_implicit_gemm does. Add the helper in the first PR that calls it.

    Fix this →

Testing

  • Two device checks still have no test (raised last round, no reply): the scale half of the check at backends/cuda/nvfp4_tensor.py:97, and the fusion check at :155.

    • The device case in test_invalid_layout_rejected moves only per_tensor_scale (backends/cuda/tests/test_nvfp4_tensor.py:308-309). test_fusion_rejects_incompatible_weights (lines 79-89) has no device case. Either check could be deleted and the suite would stay green.
    • Both can be tested on CPU, with s = s.to("meta") and fuse_along_output([a, a.to("meta")]).

    Fix this →

Recommendation

Approve

Nothing blocks. Settle the switch name before the upstack tests and the #25437 job depend on it. Each round-7 item is a fix of a line or two.


  • Gather context (diff, changed files, CLAUDE.md)
  • Run independent reviewer panel (3 reviewers)
  • Consolidate findings
  • Fact-check findings
  • Post final review

@Gasoonjia

Copy link
Copy Markdown
Contributor Author

Moved. sweep/EXHAUSTIVE no longer land here: nvfp4_test_utils.py in this PR is back to the shared weight helpers, and the helper now arrives in #25341 with its first user (test_nvfp4_kernels.py split-K sweeps). It also reads the existing EXECUTORCH_CUDA_EXHAUSTIVE_TESTS switch now, not a new variable. The note is gone from this commit message.

Authored with Claude Code.

This branch was successfully deployed

1 active and 1 inactive deployments
upload-benchmark-results — f3a104fe Deployed Nov 23, 2026 by Gasoonjia via upload-benchmark-results #23163
cadence — f3a104fe Deployed Nov 23, 2026 by Gasoonjia via hifi-op-test / hifi4 #40336
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