Skip to content

[Common] row-scaled nvfp4 path: add single-launch group fused amax - #3467

Open
cael-ling wants to merge 3 commits into
NVIDIA:mainfrom
cael-ling:pr/nvfp4-row-scaled-fused-group-amax
Open

[Common] row-scaled nvfp4 path: add single-launch group fused amax #3467
cael-ling wants to merge 3 commits into
NVIDIA:mainfrom
cael-ling:pr/nvfp4-row-scaled-fused-group-amax

Conversation

@cael-ling

@cael-ling cael-ling commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a single-kernel row/col amax pass for grouped (MoE) row-scaled NVFP4. It replaces the per-expert loop of compute_rowwise_amax + compute_columnwise_amax with one launch over a packed (sum_M, K) input, exposed as nvte_group_nvfp4_compute_amax. The kernel is the grouped generalization of #3454 - the single-tensor compute_fused_amax_kernel (same tiling / SMEM pipeline / acquire-barrier reduction). A single input TMA map covers all experts; per-expert amax vectors are selected via a prefix sum of row counts, so a 128-row chunk always lands in one expert.

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

New gtest tests/cpp/operator/test_row_scaled_nvfp4_grouped_amax.cu:

  • NVFP4GroupedRowScaledAmaxTestSuite.MatchesPerExpertOracle — grouped amax vs a CPU per-row/per-col max(|x|) reference over the same BF16 bytes, plus cross-launch determinism, across 6 expert/shape configs.
  • DISABLED_LoopVsGrouped — microbench comparing the same kernel called per-expert (loop)
    vs once (grouped).
cmake -Btests/cpp/build tests/cpp && cmake --build tests/cpp/build -j
./tests/cpp/build/operator/test_operator --gtest_filter='*NVFP4GroupedRowScaledAmax*'
./tests/cpp/build/operator/test_operator --gtest_also_run_disabled_tests --gtest_filter='*GroupedRowScaledAmaxBench*'

Performance

Same kernel called per-expert (loop) vs a single grouped launch, GB200, K=4096. Speedup is loop / grouped.

experts M=128 loop→grouped (ms) speedup M=512 loop→grouped (ms) speedup
2 0.0179 → 0.0117 1.52x 0.0180 → 0.0124 1.45x
4 0.0288 → 0.0120 2.39x 0.0271 → 0.0138 1.97x
8 0.0513 → 0.0124 4.15x 0.0514 → 0.0165 3.11x
16 0.0950 → 0.0140 6.81x 0.0960 → 0.0238 4.04x
32 0.1852 → 0.0173 10.70x 0.2009 → 0.0370 5.43x
64 0.3631 → 0.0232 15.65x 0.3960 → 0.0607 6.53x

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

Compute per-expert rowwise/columnwise amax over a packed (sum_M, K) grouped input in one kernel launch instead of one launch per expert, exposed via nvte_group_nvfp4_compute_amax and gated by NVTE_NVFP4_FUSED_AMAX. Adds a gtest that checks the result against a CPU reference and across launches.

Signed-off-by: Cael Ling <caell@nvidia.com>
@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Sep 3, 2026
@greptile-apps

greptile-apps Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds a public grouped NVFP4 amax operation that computes per-expert rowwise and columnwise maxima from a packed BF16 input using one CUDA launch.

  • Adds the grouped fused amax kernel, argument preparation, output initialization, and input-shape validation.
  • Supports independently optional rowwise and columnwise amax buffers for each expert.
  • Adds numerical, determinism, heterogeneous-buffer, and disabled benchmark coverage to the native C++ operator suite.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the trailing-column truncation is prevented by explicit alignment validation, and nullable per-expert amax buffers are guarded before every zeroing or atomic-write access.

Important Files Changed

Filename Overview
transformer_engine/common/cast/nvfp4/group_quantize_transpose_nvfp4.cuh Implements the grouped fused kernel and now validates tile alignment while safely skipping null per-expert amax buffers.
transformer_engine/common/cast/cast_grouped.cu Adds the ABI implementation that converts tensor handles and dispatches the grouped amax operation.
transformer_engine/common/include/transformer_engine/cast.h Declares and documents the packed-input and per-expert-output contract for the new C API.
tests/cpp/operator/test_row_scaled_nvfp4_grouped_amax.cu Adds reference comparisons, determinism checks, heterogeneous columnwise-buffer coverage, and an optional performance benchmark.
tests/cpp/operator/CMakeLists.txt Registers the grouped NVFP4 amax test source in the native operator test executable.

Reviews (2): Last reviewed commit: "[Common] Enforce K alignment and per-exp..." | Re-trigger Greptile

Comment thread transformer_engine/common/cast/nvfp4/group_quantize_transpose_nvfp4.cuh Outdated
@cael-ling cael-ling changed the title [Common] row-scaled nvfp4 path: add single-launch grouped fused amax [Common] row-scaled nvfp4 path: add single-launch group fused amax Sep 3, 2026
…VFP4 amax

The public entry point calls the launcher directly, bypassing the eligibility
check, so misaligned K silently dropped trailing columns and heterogeneous
per-expert amax buffers could dereference null. Add a column/split alignment
check in the launcher, take do_row/do_col as the union over experts with a
per-expert null guard in the kernel, and cover it with HeterogeneousColumnwise.

Signed-off-by: Cael Ling <caell@nvidia.com>
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.

1 participant