Repository navigation
Conversation
Grouped GEMM requires Hopper (SM90) or Blackwell (SM10x and SM110). The C++ grouped GEMM test and the PyTorch grouped-tensor GEMM tests checked only the lower bound, so they failed on SM12x instead of skipping. The PyTorch tests now use is_module_grouped_tensor_path_supported(), and the C++ test also checks the upper bound. Signed-off-by: Alp Dener <adener@nvidia.com>
Add the kNVTEColumnwiseTransposed tensor parameter and the kNVTEGroupedColumnwiseTransposed grouped tensor parameter, with TensorWrapper and GroupedTensorWrapper accessors. They say whether FP8 block-scaling columnwise data is stored transposed, and default to true, the existing layout. Other formats ignore them. Tensor::shape() rotates the shape of columnwise-only FP8 block-scaling tensors only when their columnwise data is stored transposed. Comm+GEMM overlap tensor chunks copy the flag like the other tensor parameters. test::Tensor::set_columnwise_transposed() sets the flag and relabels the shape of the columnwise buffer. Signed-off-by: Alp Dener <adener@nvidia.com>
FP8 block-scaling quantization takes the columnwise layout from the output tensor's kNVTEColumnwiseTransposed flag: - 1D: columnwise data that is not stored transposed has the input shape and uses the existing COLUMNWISE_COMPACT option. The vector kernel selects its columnwise pass at compile time. The non-transposed pass maps lanes to consecutive columns and warps to tile rows, reduces the per-warp amaxes through shared memory, and writes data and scales with coalesced stores. Columnwise scales are the same in both layouts. - 2D: without the transposed layout, rowwise data and scales serve columnwise usage, so columnwise output buffers are rejected. The cast tests run both layouts and add an unaligned multi-tile shape. Signed-off-by: Alp Dener <adener@nvidia.com>
Grouped FP8 block-scaling quantize and dequantize follow the grouped tensor's kNVTEGroupedColumnwiseTransposed flag: - 1D quantize: the TMA kernel takes the layout as a compile-time parameter. Without the transposed layout, expert t's columnwise data is row-major (M_t, K) at the same element offset as its rowwise data, and the columnwise pass quantizes whole rows of the input tile with coalesced stores. Columnwise scales are unchanged. - 2D quantize: without the transposed layout, columnwise buffers are rejected. - Dequantize reads columnwise data in the input's layout. The grouped quantize and dequantize tests run both layouts. The quantize test adds partial 128-column blocks and empty experts. Signed-off-by: Alp Dener <adener@nvidia.com>
The FP8 block-scaling to MXFP8 scale conversions (single, multi-tensor and grouped) write MXFP8 columnwise scales when the output has columnwise data, for columnwise data that is not stored transposed: - 1D: the columnwise scales are the 1D scales of the transposed data, so the existing 1D kernels convert them on swapped dims. - 2D: the rowwise scales serve columnwise output through a tile-transposed read. An output holds one direction. Multi-tensor launches batch by scaling mode and output direction. Rowwise output is unchanged. The conversion tests add columnwise cases with an independent reference. Signed-off-by: Alp Dener <adener@nvidia.com>
Where FP8 block-scaling GEMMs are emulated with MXFP8, an operand used columnwise (A with transa=N, B with transb=T) is converted per its columnwise layout. Transposed columnwise data is relabeled as rowwise data of the transposed tensor, which flips that operand's transpose flag. Other columnwise data converts to MXFP8 columnwise data with the logical shape and keeps the caller's layout. This applies at all five emulation sites. Tensor lists must share one layout. Every tensor still has the transposed layout, so GEMMs still run TN. Signed-off-by: Alp Dener <adener@nvidia.com>
general_gemm raises NotImplementedError for FP8 block-scaling operands with a comm+GEMM overlap (Userbuffers or cuBLASMp). Signed-off-by: Alp Dener <adener@nvidia.com>
Where FP8 GEMM supports non-TN layouts, Float8BlockQuantizer stores 1D columnwise data with the logical shape, and 2D tensors have no columnwise buffers because rowwise data and scales serve columnwise usage. Hopper and SM12x keep the transposed layout. - The C++ Float8BlockQuantizer queries non-TN support once per process and sets the layout flag on every tensor wrapper it creates or updates. Python FP8 block-scaling tensors, storage and grouped tensors take a columnwise_transposed constructor argument, and their C++ wrappers take the flag from it. - Allocation (create_tensor, create_grouped_tensor, bulk allocation, inner_tensor_specs, make_grouped_tensor) follows the quantizer's layout. In-place quantization into a tensor of the other layout drops its columnwise buffers and adopts the quantizer's layout. Setting .data from another FP8 block-scaling tensor takes its layout. - size(), view(), reshape, the shape property, dequantization, update_usage(), _create_columnwise() and get_data_tensors() follow the tensor's layout. - mark_grouped_tensor marks the rowwise data and scales of 2D grouped tensors whose rowwise data serves columnwise usage. The debug scale-inverse stats read those rowwise scales. - Return from the columnwise-only aten.view dispatch instead of falling through. Tests cover columnwise-only dequantization for 1D and 2D, and the grouped and exact quantization tests follow the arch layout. Signed-off-by: Alp Dener <adener@nvidia.com>
GroupedLinear with a single grouped BF16 weight drops its cached quantized workspace when columnwise usage is needed and the workspace has no columnwise data. 2D FP8 block-scaled workspaces whose rowwise data serves columnwise usage are now kept, so the weight is no longer re-quantized every microbatch. Tests: - test_single_grouped_weight_matches_discrete_grouped_tensor_path also covers non-square weights, 1D FP8 block-scaled weights and quantized primary weights. - test_single_grouped_weight_workspace_cache covers 1D and 2D FP8 block scaling, checks that the cached workspace and its outputs are reused, and checks that a workspace cached in a no-grad forward serves a training step. Signed-off-by: Alp Dener <adener@nvidia.com>
The 1D FP8 block-scaling all-gather gathers columnwise data that is not stored transposed along dim 0, without the de-interleave of transposed data. The distributed numerics test adds FP8 block scaling to the quantized all-gather test. Signed-off-by: Alp Dener <adener@nvidia.com>
Pickles hold columnwise data in the transposed layout, which older TE versions read. Tensors that store it untransposed write transposed columnwise data and scales (from the rowwise ones for 2D). Loading converts the columnwise data to the local layout: 1D data is transposed back, and 2D tensors with rowwise data drop it. 2D columnwise data without rowwise data, and pickles loaded without CUDA, keep the transposed layout. aten.copy_ between FP8 block-scaling tensors of different layouts requantizes the destination from the dequantized source. test_pickle_compatibility checks the pickled layout against an independent dequantization and loads payloads through every reconstructor. Signed-off-by: Alp Dener <adener@nvidia.com>
Where FP8 GEMM supports non-TN layouts, FP8 block-scaling GEMMs run as MXFP8 GEMMs. general_gemm, general_grouped_gemm and general_grouped_gemm_for_grouped_tensor now use MXFP8's split-accumulator settings there: off for forward GEMMs and on for backward GEMMs. Hopper and SM12x keep split accumulation for all GEMMs. The rule relies on grad, so backward GEMM calls that can take FP8 block-scaling operands pass grad=True: GroupedLinear (module and op) dgrad and wgrad, and LayerNormMLP FC1 and FC2 wgrad. LayerNormMLP drops its FP8 block-scaling special case that passed grad=False for FC2 wgrad. general_grouped_gemm_for_grouped_tensor accepts grad=True and raises only when a bias is also given. custom_gemm picks the GEMM role from grad, so custom recipes ran LayerNormMLP FC1 wgrad as fprop and failed. The custom recipe test covers this with reference quantizers. The FP8 block-scaling grouped GEMM test also compares every case against a dequantized reference. Signed-off-by: Alp Dener <adener@nvidia.com>
Signed-off-by: Alp Dener <adener@nvidia.com>
denera
requested review from
Oleg-Goncharov,
ksivaman,
ptrendx and
timmoon10
as code owners
November 13, 2026 17:50
Contributor
[Medium impact] The changes affect FP8 block-scaling quantization, GEMMs, tensor storage, and distributed use on supported GPUs. Fix the device-specific layout choice before merging. Findings
SummaryThis PR removes unnecessary FP8 block-scaling transposes on GPUs that support non-TN GEMMs, while keeping the legacy layout on Hopper and SM 12.x.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
Q[FP8 block quantizer] --> L{Columnwise layout}
L -->|Transposed| T[Separate columnwise data]
T --> TN[TN GEMM]
L -->|Not transposed, 1D| C[Columnwise data in logical shape]
L -->|Not transposed, 2D| R[Reuse rowwise data and scales]
C --> M[Convert scales to MXFP8]
R --> M
M --> G[Keep requested GEMM layout]
Reviews (1) · Last reviewed commit: "[Docs] Describe per-architecture FP8 blo..." · Reviewed by Greptile |
8 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
BEFORE: FP8 block scaling (FP8BS) stores columnwise data as a physical transpose on every GPU, because
Hopper's FP8 GEMM only runs TN. On Blackwell, FP8BS GEMMs already run as MXFP8 GEMMs (the FP32 block
scales are converted to E8M0), and MXFP8 GEMM supports TN, NN and NT, so the transposed copy only
costs time: 1D quantization stages a transpose through shared memory, 2D quantization writes a second
full FP8 copy of every weight, distributed paths re-transpose after all-gathers, and the GEMM binding
forces every GEMM to TN to match.
AFTER: FP8BS columnwise data is laid out the same way as MXFP8 wherever FP8 GEMM supports non-TN
layouts (
nvte_is_non_tn_fp8_gemm_supported(): SM 10.x, 11.x, 13.x and newer):shape when non-TN FP8 GEMM is supported; the columnwise scales keep their shape and bytes.
way it is read, so rowwise data and scales serve columnwise usage.
transa/transband passes MXFP8 columnwise operands tocuBLASLt, as the MXFP8 recipe does.
Hopper and SM 12.x keep the transposed layout and TN GEMMs. Output values remain unchanged, bitwise
identical against
main.Type of change
Changes
Common (C++/CUDA)
TensorparameterskNVTEColumnwiseTransposedandkNVTEGroupedColumnwiseTransposedrecordwhether a tensor's columnwise quantization is stored in transposed layout (currently only useful
for FP8BS). Quantize, grouped quantize,
Tensor::shape()and the FP8BS→MXFP8 conversion read thetensor's flag to avoid frequent mutex hits on
te::cuda::current_device()when retrieving SM archinfo cached per device ID (measured non-trivial E2E impact).
non-transposed columnwise pass with coalesced stores.
columnwise usage, so the kernel writes a single copy and columnwise output buffers are rejected.
columnwise pass; grouped dequantize follows the input's layout.
transposed, and 2D rowwise scales read tile-transposed. No new APIs.
PyTorch
tensor it creates (
columnwise_transposed); storage, grouped tensors, bulk allocation and the C++bindings follow each tensor's flag. Modules work through
set_usage/update_usageunchanged. 2Dtensors allocate no columnwise buffers on non-TN GPUs.
stored transposed are relabeled to TN as before.
when non-TN FP8 GEMM is supported; FSDP2 and distributed-optimizer paths skip the post-all-gather
transpose for 2D weights.
(fast accumulation in forward, split accumulation in backward), selected by the
gradflag. Everybackward GEMM that can take FP8BS operands now passes
grad=True; the grouped-tensor GEMM acceptsgrad=Trueand rejects only the unsupported bias-gradient epilogue. Hopper andSM 12.x keep split accumulation to avoid numerical changes in existing FP8BS user code.
also carry the transposed columnwise buffers), so older Transformer Engine versions read new
pickles correctly; unpickling converts to the local layout based on runtime support for non-TN FP8
GEMM. CPU-only processes without CUDA keep the transposed layout. In-place copies between tensors
of different layouts requantize the destination.
NotImplementedError.Extending support deferred to future work.
Float8BlockScalingrecipe docstring describes the per-arch accumulation behaviour (recipe fieldsunchanged); FP8BS docs describe the per-arch layout.
Bug Fixes
te.LayerNormMLPFC1 WGRAD withcustom_gemmnow passes the correctgrad=Trueoption and workscorrectly. Previously passing
grad=Falseand thus running WGRAD as FPROP and failing.GroupedGemmTest, PyTorchtest_grouped_gemm_grouped_tensor{,_mxfp8})now skip on GPUs without grouped GEMM support (SM 12.x) instead of failing; the PyTorch tests use
is_module_grouped_tensor_path_supported().Performance (GB200, SM 10.0)
Quantize kernels (µs, BF16 → E4M3):
main→ PRmain→ PRNOTE: Per the FP8BS recipe, grouped activations are quantized with 1D blocks and grouped weights are
quantized with 2D blocks. Columnwise usage for grouped weights never set in E2E execution and
omitted from benchmarks.
Modules, fwd+bwd (µs per microbatch, BF16 params):
main→ PRte.ops.GroupedLinear, 16×2560 FC1te.ops.GroupedLinear, 64×512 FC1Known Issues
Different GEMM wrappers hardcode different choices for the
use_split_accumulatoroption,ignoring the recipe entirely but also NOT staying consistent with each other. As a temporary
work-around, this PR modifies all the forced choices to disable split accumulation in the FWD
pass and enable it in DGRAD/WGRAD whenever non-TN FP8 GEMM is supported. This makes the
MXFP8-emulated FP8BS GEMM execution on Blackwell numerically consistent with native-MXFP8 GEMM,
but the recipe is still being ignored and the E2E logic needs to be reworked. TN-layout FP8 GEMM
on Hopper and SM12x remain untouched to avoid altering numerical results for existing FP8BS users.
Checklist: