Repository navigation
Add FP8 block128 compact dispatch and grouped requantization - #3919
new-TonyWang wants to merge 14 commits into
Conversation
Signed-off-by: tttony <864832769@qq.com>
Signed-off-by: tttony <864832769@qq.com>
Signed-off-by: tttony <864832769@qq.com>
Signed-off-by: tttony <864832769@qq.com>
Signed-off-by: tttony <864832769@qq.com>
Signed-off-by: tttony <864832769@qq.com>
Signed-off-by: tttony <864832769@qq.com>
for more information, see https://pre-commit.ci
Signed-off-by: tttony <864832769@qq.com>
Signed-off-by: tttony <864832769@qq.com>
for more information, see https://pre-commit.ci
Signed-off-by: tttony <864832769@qq.com>
[Medium impact] The new behavior affects block128 FP8 expert dispatch and grouped requantization workflows. Do not merge yet: scale-layout errors, compact tensor rebuilds, and supported test configurations remain broken. Findings
SummaryAdds compact FP8 block128 dispatch and grouped receiver-side requantization.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[BF16 tokens] --> B[Compact block128 quantization]
B --> C[FP8 data and FP32 scales]
C --> D[Expert dispatch]
D --> E[Grouped receiver]
E --> F[Grouped requantization]
F --> G[GEMM-ready scales]
F --> H[Optional columnwise FP8]
F --> I[Optional BF16 output]
Reviews (4) · Last reviewed commit: "Require exact packed scale shape in EP d..." · Reviewed by Greptile |
| NVTE_CHECK(send_cols >= sc_cols && recv_cols >= sc_cols, | ||
| "send/recv scale cols must cover logical scale cols"); | ||
| NVTE_CHECK(static_cast<size_t>(send_scale.numel()) >= send_rows * sc_cols, | ||
| "send scale numel must cover rows * cols"); | ||
| NVTE_CHECK(static_cast<size_t>(recv_scale.numel()) >= recv_rows * sc_cols, | ||
| "recv scale numel must cover rows * cols"); |
There was a problem hiding this comment.
Dispatch reads padding as scales
check_block_scale_pair() now accepts wider scale rows, but the dispatch wrappers still describe each FP32 row as exactly H / 128 elements. A contiguous scale matrix shaped [T, 36] with H=4096 passes these checks, then dispatch reads rows at a stride of 32 instead of 36. Padding from one row becomes scale data for the next, silently changing dispatched values.
Require the exact packed width and row count, or carry the real row stride through the transport.
Knowledge Base Used: Native GEMM and quantization kernels
49da935 to
b7ac896
Compare
| const bool compact_scale_layout = !input.with_gemm_swizzled_scales; | ||
| const size_t row_scale_cols = compact_scale_layout && first_logical_dim != 0 | ||
| ? input.scale_inv.numel() / first_logical_dim | ||
| : blocks; |
There was a problem hiding this comment.
Existing grouped scales are misread
group_quantize stores block128 scales as [hidden / 128, expert_rows] within each expert and sets _with_gemm_swizzled_scales=False. This code treats that flag as proof of row-major wire scales instead.
Passing that existing GroupedTensor to GroupedLinear now rearranges valid scales incorrectly whenever the hidden dimension has multiple blocks, changing GEMM results. Track the wire layout separately while preserving the existing grouped layout.
Knowledge Base Used: Native GEMM and quantization kernels
| ("varying", [0, 128, 0, 256, 0]), | ||
| ], | ||
| ) | ||
| @pytest.mark.parametrize("power_of_two", [False, True]) |
There was a problem hiding this comment.
Blackwell parity tests always fail
This test runs on Blackwell but includes power_of_two=False. Its first group_quantize call rejects that setting on SM100 and newer, so those cases fail before testing requantization. Since this file is now in the L0 suite, it adds guaranteed failures on those GPUs.
Restrict non-power-of-two cases to Hopper, or skip only those unsupported combinations.
- Store rowwise scale layout in storage and dequantize compact scales - Preserve layout through quantizer value-key rebuild and C++ construction - Restore unified prepare_and_dispatch custom-op call Signed-off-by: tttony <864832769@qq.com>
| instance._rowwise_scale_inv = rowwise_scale_inv | ||
| instance._columnwise_scale_inv = columnwise_scale_inv | ||
| instance._is_2D_scaled = is_2D_scaled | ||
| instance._rowwise_scale_layout = rowwise_scale_layout |
There was a problem hiding this comment.
Rebuilt tensors lose compact layout
The new _rowwise_scale_layout field defaults to GEMM-ready, but the full tensor's view, reshape, and pickle rebuilds never pass it. Viewing a compact [256, 4096] tensor as [2, 128, 4096] keeps its compact scales but resets the layout flag. Calling dequantize() on the result then takes the GEMM-ready path and raises during reshape.
Pass the layout through these rebuilds, as the storage-only view() now does.
Knowledge Base Used: PyTorch tensor and operator abstractions
Signed-off-by: tttony <864832769@qq.com>
| pytestmark = pytest.mark.skipif( | ||
| not torch.cuda.is_available() or torch.cuda.get_device_capability()[0] < 9, | ||
| reason="EP block scaling requires Hopper or newer", | ||
| ) |
There was a problem hiding this comment.
Description
Add FP8 block128 expert-parallel dispatch using compact rowwise wire scales and grouped receiver-side requantization for SM90. This addresses the Transformer Engine prerequisites discussed in NVIDIA/Megatron-LM#8675.
The sender uses the native
Float8BlockQuantizerto emit compact[rows, hidden / 128]scales without allocating unused columnwise storage. The receiver converts compact scales to the grouped GEMM-ready layout and can produce columnwise operands or BF16 dequantized output. The implementation supportsSAME_BOTH_DIMSandVARYING_FIRST_DIM, including empty experts and CUDA Graph replay.Type of change
Changes
Float8BlockScalingthrough the EP dispatch path and construct grouped receivers with device-side offsets.Dispatch and requant performance
Measured on NVIDIA H100 80GB (SM90) with PyTorch 2.11.0+cu130 and cuBLASLt 13.8.2. All cases use FP8 grouped GEMM, balanced routing, and no shared experts; only the forward dispatch wire dtype differs. Three warmups and ten measured iterations; the tables report the median of the slowest rank's caller-stream dispatch interval. These are end-to-end dispatch-phase measurements, not isolated communication-kernel timings.
Dispatch
Receiver requantization
CUDA Graph timing on one H100; median of seven batches of 50 replays after warmup. The requant path converts compact FP8 rowwise input to grouped GEMM-ready rowwise scales and columnwise FP8 data. The baseline directly quantizes the same BF16 source with
group_quantize.Observed NCCL-EP performance limitations
The FP8 wire reduces dispatch traffic, but that reduction does not translate proportionally into end-to-end MoE speedup. We observed the following two NCCL-EP integration limitations:
Shared-expert overlap is constrained by host serialization and CUDA connection scheduling. FP8 receiver-carrier construction and its associated metadata preparation consume a substantial part of the host dispatch window, delaying submission of shared-expert work. With the Megatron default
CUDA_DEVICE_MAX_CONNECTIONS=1, independent streams also do not provide reliable communication/compute overlap. Increasing the connection count improved selected experiments, but we do not treat that as a production solution because it changes the default execution configuration. Consequently, receiver-side host work remains on the critical path and limits dispatch/shared-FC1 overlap under the default global CUDA setting.Small-kernel and metadata overhead offsets part of the communication saving. The receiver still performs token-count prefix sums and scaling for tensor offsets, grouped-carrier metadata construction, and compact-to-GEMM-ready scale/data preparation. Several of these steps launch short kernels whose latency is largely independent of the FP8/BF16 payload size. BF16 also pays the common grouped-carrier cost, so we do not attribute all of it to FP8; the incremental costs are scale handling, layout conversion, and requantization. The fused requant kernel itself is now faster than direct BF16 group quantization in the table above, while the remaining small operations still contribute fixed launch and host-side overhead to the end-to-end path.
For example, in the two-node Kimi-shaped case, dispatch improves from 1.800 ms to 1.405 ms while complete forward improves from 9.159 ms to 8.702 ms. Thus the dispatch saving is real, but it is only about 5% of the complete forward. We are reporting this explicitly to avoid presenting reduced wire traffic as equivalent end-to-end acceleration.
Validation
NVTE_FRAMEWORK=pytorch NVTE_CUDA_ARCHS=90a, NVIDIA H100.SAME_BOTH_DIMS/VARYING_FIRST_DIM, columnwise and dequantized outputs, empty experts, and CUDA Graph replay.git diff --check: passed.qa/L0_license/test.sh: passed.Checklist