Repository navigation
Conversation
…all-reduces and runner In the SM107 TP4/TP8 decode target, each MoE layer's main stream ran the router GEMM, renorm_moe_routing_op, fp4_quantize, the pre-routed routed-expert runner and a torch.add of the routed and shared partials before the closing all-reduce. Three of those ops now fold into the kernels around them: - The post-attention all-reduce + RMSNorm also writes the routed experts' NVFP4 codes and scales (the workspace's out-quant variant). Its scale arithmetic now follows fp4_quantize's, so the codes and scales are the same bits. - The runner routes the fp32 router logits itself (Renormalize), replacing renorm_moe_routing_op ahead of the pre-routed runner. The router GEMM and its fp32 output are unchanged; the selected experts and their order are the same. - The closing all-reduce adds the routed and shared partials: a second input of the split-row one-shot kernel, added in fp32 and rounded once to bf16, the same bits as torch.add. The two folded collectives are one-shot only, so a step of more rows than ONE_SHOT_ROWS keeps the separate fp4_quantize and torch.add; the dense layer is unchanged. Signed-off-by: yt0428 <[email protected]>
…ainst the separate ops - comm/test_modeling_v2_moe_tail_allreduce.py: four ranks compare allreduce_add_rmsnorm_nvfp4 with the all-reduce entry plus fp4_quantize, and allreduce_add2_rmsnorm with torch.add plus the entry, bit for bit, eager from one row to ONE_SHOT_ROWS and in a replayed CUDA graph; both refuse a call above ONE_SHOT_ROWS. The quantization is also driven at global scales that put a block's scale on an e4m3 rounding midpoint and a few fp32 ulp to either side, where the order of the scale arithmetic decides the rounding. - moe/test_modeling_v2_decode_runner_routing.py: on one GPU, the runner routing the fp32 logits itself selects the same experts in the same slot order, and finalizes the same rows, as renorm_moe_routing_op ahead of the pre-routed runner, at the tp4 and tp8 expert widths, including near-ties and exact ties. Both need SM107 devices and are skipped elsewhere. Signed-off-by: yt0428 <[email protected]>
yt0428
force-pushed
the
codex/ml4-vr200-pr-moe-tail
branch
from
November 17, 2026 03:56
20a9866 to
b592ea2
Compare
yt0428
marked this pull request as ready for review
November 17, 2026 06:30
yt0428
requested review from
Wanli-Jiang,
WeiHaocheng and
litaotju
as code owners
November 17, 2026 06:30
Collaborator
Author
|
/bot skip --comment "Format check only" |
1 task
Collaborator
|
PR_Github #85381 [ skip ] triggered by Bot. Commit: |
Collaborator
|
PR_Github #85381 [ skip ] completed with state |
1 task done
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.
@coderabbitai summary
Description
In the Mistral Large 4 SM107 (VR200) TP4/TP8 decode target, each MoE layer's main stream ran five steps in series, while the shared expert ran beside it on a side stream (#22253):
renorm_moe_routing_op;fp4_quantize;torch.addof the routed and shared partials, ahead of the closing all-reduce.This PR removes three of those small kernels from the main stream by folding them into the kernels around them.
What changes
fused_quant), which was compiled but never launched before.fp4_quantize:SF = global_scale * (block_max * rcp_approx(6)). The codes and scales are therefore bit-identical tofp4_quantizeof the same bf16 norm rows.renorm_moe_routing_opfollowed by a pre-routed call.ADD_SECOND_INPUTconstexpr, compiled asfused_add2bybuild_workspace(..., add_second_input=True).torch.add.ops/comm/moe_tail_allreduce.pywraps the two folded collectives.ONE_SHOT_ROWS(=TWOSHOT_ABOVE, 3072 rows) keeps the separatefp4_quantizeandtorch.add.PrefillTarget), and the other ML4 targets (TEP, DEP, SM103).Numerics (VR200, the E3 runtime image with this source overlaid)
VR200 results
Step A/B, TP4, one node, configurations interleaved, one shared autotuner cache. The metric is the median device step time (
prevDeviceStepTimeMS) while exactly C generation requests run (DSpark K3, about 5.6K context, natural acceptance). Deltas are in ms.fp4_quantize.torch.add+ all-reduce.End-to-end six points (DSpark K3, synthetic acceptance length 2.772, 20 min per point,
stream_interval=1, one run per point), against this PR's base. The baseline ran at ccc93f2, which has the same tree as 416b15a. Step time is 2.772 / (1/ITL).Not measured
Related PRs
modeling.py; it merges cleanly with this branch.Test Coverage
tests/unittest/_torch/modeling_v2/models/mistral_large4/mistral_large_4_nvfp4__sm_107__tp4/comm/test_modeling_v2_moe_tail_allreduce.py(4 GPUs):allreduce_add_rmsnorm_nvfp4with the all-reduce entry +fp4_quantize, andallreduce_add2_rmsnormwithtorch.add+ the entry, bit for bit;ONE_SHOT_ROWS, and in a replayed CUDA graph;ONE_SHOT_ROWS..../mistral_large_4_nvfp4__sm_107__tp4/moe/test_modeling_v2_decode_runner_routing.py(1 GPU):renorm_moe_routing_op+ the pre-routed runner: the finalized rows and each slot's expert row;vr-nvl72-ts3-l11-062-c05, E3 runtime image with this branch's source):101 passed(the 4-rank test and 100 routing cases).0 mismatch(es) over 4 ranks.global_scale * block_max * (1 / 6)), the same job fails on the midpoint cases. For example, 78–160 of 12288 scales differ, and codes differ too._twoshot_row_epilogueunderEMIT_NVFP4) still uses the old order. The two-shot all-reduce does run aboveTWOSHOT_ABOVErows, but with that branch compiled out (EMIT_NVFP4=False), and no entry builds it with NVFP4 output. This PR leaves it unchanged.PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.🤖 Generated with Claude Code