Skip to content

Add FP8 block128 compact dispatch and grouped requantization - #3919

Open
new-TonyWang wants to merge 14 commits into
NVIDIA:mainfrom
new-TonyWang:hapi-block128-dispatch-pr
Open

new-TonyWang wants to merge 14 commits into
NVIDIA:mainfrom
new-TonyWang:hapi-block128-dispatch-pr

Conversation

@new-TonyWang

@new-TonyWang new-TonyWang commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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 Float8BlockQuantizer to 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 supports SAME_BOTH_DIMS and VARYING_FIRST_DIM, including empty experts and CUDA Graph replay.

Type of change

  • New feature (non-breaking change which adds functionality)
  • Code refactoring

Changes

  • Add compact rowwise scale selection to blockwise and grouped quantization.
  • Wire Float8BlockScaling through the EP dispatch path and construct grouped receivers with device-side offsets.
  • Add a TMA-based block128 grouped requantization kernel and route it through the common grouped requantization API.
  • Add producer, numerical parity, output-mode, layout, empty-expert, and CUDA Graph tests.

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

Shape (T/H/FFN/E/K) GPUs BF16 wire (ms) FP8 blockwise wire (ms) BF16 / FP8
4096/5120/2304/384/6 8 0.730 0.781 0.93x
4096/5120/2304/384/6 16 (2 nodes) 1.148 1.058 1.09x
6144/7168/2048/384/8 8 0.952 0.864 1.10x
6144/7168/2048/384/8 16 (2 nodes) 1.800 1.405 1.28x
4096/2048/1408/64/8 8 0.688 0.665 1.03x
4096/2048/1408/64/8 16 (2 nodes) 0.764 0.819 0.93x

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.

Shape representation H Rows Requant (us) BF16 group quant (us) BF16 quant / requant
SAME_BOTH_DIMS 2048 4096 12.15 16.62 1.37x
SAME_BOTH_DIMS 4096 16384 93.99 106.09 1.13x
SAME_BOTH_DIMS 5120 32768 225.00 251.51 1.12x
SAME_BOTH_DIMS 7168 16384 160.30 178.91 1.12x
VARYING_FIRST_DIM 5120 23040 160.11 180.07 1.12x
VARYING_FIRST_DIM 7168 20736 200.68 224.10 1.12x

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:

  1. 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.

  2. 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

  • Final branch build: NVTE_FRAMEWORK=pytorch NVTE_CUDA_ARCHS=90a, NVIDIA H100.
  • Focused PyTorch suite on H100: 338 passed, covering compact/noncompact scales, 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

  • 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 where required.
  • My changes generate no new warnings attributable to this feature.
  • I have added tests that prove my feature works.
  • New focused tests pass locally with my changes.

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>
@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Nov 23, 2026
pre-commit-ci Bot and others added 5 commits November 23, 2026 07:25
@new-TonyWang
new-TonyWang marked this pull request as ready for review November 23, 2026 12:39
@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 0/5

[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

  1. P1 Test fails without NCCL EP ▶
  2. P1 Dispatch reads padding as scales ▶
  3. P1 Existing grouped scales are misread ▶
  4. P1 Blackwell parity tests always fail ▶
  5. P1 Rebuilt tensors lose compact layout ▶

Summary

Adds compact FP8 block128 dispatch and grouped receiver-side requantization.

  • Blockwise quantizers can store rowwise scales in a compact layout.
  • Expert-parallel dispatch sends compact block128 FP8 data and scales.
  • Grouped block128 FP8 inputs can be requantized for GEMM or returned as BF16.

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]
Loading

Reviews (4) · Last reviewed commit: "Require exact packed scale shape in EP d..." · Reviewed by Greptile

Comment on lines +180 to +185
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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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

Comment thread transformer_engine/pytorch/ep.py Resolved
@new-TonyWang
new-TonyWang force-pushed the hapi-block128-dispatch-pr branch from 49da935 to b7ac896 Compare November 24, 2026 07:18
Comment on lines +537 to +540
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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>
Comment on lines +12 to +15
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",
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Test fails without NCCL EP

On Hopper or newer with NVTE_WITH_NCCL_EP=0, this test runs but tex.ep_dispatch does not exist. It raises AttributeError instead of the expected RuntimeError, so the test fails on a supported build. Also skip when tex.ep_dispatch is unavailable.

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.

1 participant