Skip to content

[Core] Compute grouped NVFP4 RHT member offsets in 64 bits - #3977

Open
ArchanaChetan07 wants to merge 1 commit into
NVIDIA:mainfrom
ArchanaChetan07:fix/grouped-hadamard-int64-offset
Open

ArchanaChetan07 wants to merge 1 commit into
NVIDIA:mainfrom
ArchanaChetan07:fix/grouped-hadamard-int64-offset

Conversation

@ArchanaChetan07

Copy link
Copy Markdown
Contributor

Description

The graph-safe grouped row/column RHT cast fusion (graph_safe_group_row_cast_col_hadamard_transform_cast_fusion.cu) finds the member tensor of each N tile from the element offset of the tile's first row, row * M. That product was computed in 32 bits:

  • per-tile lookups (column-wise RHT epilogue and row-wise quantization epilogue): int * int, overflowing from 2^31 elements on. get_current_tensor_id then searched past every member offset and returned the last member, so rows from element 2^31 up to the start of the last member were quantized with the last member's amax;
  • initial lookups: uint32_t arithmetic, wrapping at 2^32 (overwritten by the per-tile lookup today, but wrong for the same reason).

This PR applies the fix proposed by @HuiyingLi in the issue (verified there on GB300 up to just below 2^32 elements): it forms the offset as size_t (the type get_current_tensor_id already takes) at the two per-tile sites, extends it to the two initial lookups for consistency, and adds a regression test.

Out of scope: the separate limit above 2^32 elements reported in the issue, which also affects the non-grouped path and te.Linear and so lies outside this kernel.

Fixes #3971

Type of change

  • Documentation change
  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change
  • Infra/Build change
  • Code refactoring

Changes

  • Compute the element offset of a tile row as static_cast<size_t>(row) * M at the four get_current_tensor_id call sites.
  • Add test_grouped_tensor_nvfp4_above_int32_elements to tests/pytorch/nvfp4/test_nvfp4_group_quantize_graph_safe.py: a 270,336 × 8,192 BF16 input split [131072, 139136, 128] with member scales [4, 0.25, 1], so the middle member spans element 2^31 and is followed by a member with a different amax. Every member must match quantizing it alone, bit for bit (amax, data and scales, rowwise and columnwise). Skips with less than 16 GiB free.

Validation

  • Logic: a host emulation of the per-tile lookup on the issue's MoE shape (32 × 45,056 rows, hidden 2,688; 3.9e9 elements) assigns 41.5% of rows to the wrong member with the old arithmetic (matching the issue's 41%) and 0% with the fix.
  • Build: the TU compiles for sm_100a with CUDA 13.0 (nvcc -O3 --expt-relaxed-constexpr), no warnings.
  • Performance: across all 24 kernel instantiations, register usage is unchanged (128 regs each, __launch_bounds__(512, 1)). SASS grows by ~26 instructions per instantiation (73,696 → 74,312 total), from the wide multiply and 64-bit compare in the once-per-tile member lookup, outside the quantization inner loop.
  • Not yet run: the new test and the existing tests/pytorch/nvfp4 suite on a Blackwell GPU (TODO before marking ready).

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas — N/A (one cast per site; the test docstring explains the case)
  • I have made corresponding changes to the documentation — N/A
  • 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 — pending Blackwell run

🤖 Generated with Claude Code

The graph-safe grouped row/column RHT cast fusion finds the member of
each N tile from the element offset of the tile's first row,
`row * M`. The per-tile lookup multiplied two ints, so from 2**31
elements on the offset overflowed, the member search ran past every
offset, and rows from element 2**31 to the start of the last member
were quantized with the last member's amax (rowwise and columnwise).
The initial lookup multiplied in 32-bit unsigned arithmetic and
wrapped at 2**32.

Form the offset as size_t, the type get_current_tensor_id takes, at all
four lookups. Register usage of the kernel is unchanged.

Add a grouped quantization test whose middle member spans element 2**31
and is followed by a member with a different scale; every member must
match quantizing it alone, bit for bit.

Fixes NVIDIA#3971.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: ArchanaChetan07 <apatil@sandiego.edu>
@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Dec 1, 2026
@ArchanaChetan07
ArchanaChetan07 marked this pull request as ready for review December 1, 2026 20:55
@greptile-apps

greptile-apps Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Computes grouped NVFP4 member offsets in 64 bits at all four RHT quantization lookups.

  • Grouped NVFP4 quantization keeps tile lookups correct past 2^31 elements.

ArchanaChetan07 explicitly deferred the separate limit above 2**32 elements because it also affects non-grouped quantization and te.Linear.

Reviews (1) · Last reviewed commit: "[Core] Compute grouped NVFP4 RHT member ..." · Reviewed by Greptile

This branch has not been deployed

No deployments
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.

[Bug] Grouped NVFP4 quantization uses the last member's amax above 2^31 elements (int overflow of the element offset)

1 participant