Skip to content

[PyTorch] Compare only computed NVFP4 RHT column-wise scales on SM12x - #3930

Closed
rlaope wants to merge 1 commit into
NVIDIA:mainfrom
rlaope:sm12x-rht-exact-scale-padding
Closed

rlaope wants to merge 1 commit into
NVIDIA:mainfrom
rlaope:sm12x-rht-exact-scale-padding

Conversation

@rlaope

@rlaope rlaope commented Nov 24, 2026

Copy link
Copy Markdown

Description

tests/pytorch/nvfp4/test_nvfp4_rht_quantize_exact.py fails 32 of 300 cases on SM 12.0 at main. The failing cases are test_rht_with_quantization_block_tiling_versus_reference and test_nvfp4_quantization_noncontiguous_inputs with columnwise_only or both_directions at shapes whose column-wise scale tensor is padded (256x272, 304x304, 8192x11328, 32x128). Only the column-wise scale comparison fails:

torch.testing.assert_close(sx_t_valid, sx_t_ref, atol=0.0, rtol=0.0)
AssertionError: Tensor-likes are not equal!
Mismatched elements: 1786 / 6144 (29.1%)
Greatest absolute difference: 250 at index (374, 14)

The data, amax and the computed scales all match bit for bit. On SM 12.0/12.1 the test takes the column-wise reference from TE's unfused kernel (NVTE_NVFP4_DISABLE_RHT_CAST_FUSION=1, added in #3300). For a 256x272 input that tensor is padded to (384, 16), while the reference quantizer's scales are (272, 16). The test slices the kernel under test to the reference shape (sx_t[: ref_sx_t_shape[0], : ref_sx_t_shape[1]]), but it takes ref_sx_t_shape from the padded native tensor, so the comparison includes padding. The padding is not initialized. In two back-to-back calls on the same input it held 0 and then 1791 nonzero bytes in the fused output, and 1791 and then 1784 in the unfused output.

This PR slices the native reference to the reference quantizer's scale shape. It changes the test only.

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

  • tests/pytorch/nvfp4/test_nvfp4_rht_quantize_exact.py: in the SM12x branch, slice native._columnwise_scale_inv to the shape of x_nvfp4_ref.scale_t before comparing.

Testing

RTX PRO 6000 Blackwell Max-Q (SM 12.0), driver 590.48.01, TE main at a6393d0 built with NVTE_CUDA_ARCHS=120, CUDA 13.0, torch 2.14.1+cu130. Same library for both runs. Only the test file differs.

pytest -p no:randomly tests/pytorch/nvfp4/test_nvfp4_rht_quantize_exact.py, three runs each:

result
main 32 failed, 268 passed (3 of 3 runs)
this PR 300 passed (3 of 3 runs)

Other architectures are unaffected because they do not take this branch. Not run: SM 12.1.

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

On SM 12.0/12.1 the exact RHT test takes the column-wise reference from
TE's unfused kernel, including the padded scale rows and columns that
the reference quantizer does not compute. That padding is not
initialized, so the test failed whenever the column-wise scale tensor is
padded (e.g. 256x272, 304x304, 32x128).

Slice the native reference to the shape of the reference quantizer's
scales, as the test already does for the kernel under test.

Signed-off-by: rlaope <105429536+rlaope@users.noreply.github.com>
@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Nov 24, 2026
@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] This test-only change appears safe to merge.

Summary

Fixes the SM12x NVFP4 RHT test by comparing only computed column-wise scales.

  • The SM 12x reference compares only computed transpose scales.

No actionable issues found. GPU tests were not run during this review.

Reviews (1) · Last reviewed commit: "[PyTorch] Compare only computed NVFP4 RH..." · Reviewed by Greptile

@pggPL pggPL mentioned this pull request Nov 24, 2026
8 of 13 tasks
@pggPL

pggPL commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Thank you for the contribution! This fix has been included in #3935 (with original commit authorship preserved) so we can run CI and land several small community fixes together. Closing this PR in favor of #3935.

@pggPL pggPL closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution PRs from external contributor outside the core maintainers, representing community-driven work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants