Repository navigation
[TRTLLM-17515][feat] modeling_v2: GLM-5.3-Flash NVFP4 target with one-model MTP in the forward - #21335
Closed
zhaoyangwang-nvidia wants to merge 13 commits into
Closed
[TRTLLM-17515][feat] modeling_v2: GLM-5.3-Flash NVFP4 target with one-model MTP in the forward#21335zhaoyangwang-nvidia wants to merge 13 commits into
zhaoyangwang-nvidia wants to merge 13 commits into
Conversation
…TP in the forward Add the glm5_next modeling_v2 family and its first target, glm_5_3_flash_nvfp4__sm_100__default: the built-in GLM-5.3-Flash text model copied as the generic path, routed for the NVFP4 checkpoint on sm100 without pipeline or context parallelism. One-model MTP-Eagle runs inside the target's forward (Glm5NextMtpStep): verify logits, strict acceptance (greedy or plain sampling), the KDA accepted-count commit and the K-step draft chain, returning the dict the speculative sampler reads. No speculative worker is built. Routing and the constructor refuse the speculative features the step does not compute. TLLM_GLM5_NEXT_MTP_STOCK_WORKER=1 runs the same drafter on the stock MTP-Eagle worker for A/B measurement. Tests: routing (CPU), the in-model step against the stock MTP-Eagle worker on synthetic batches (B200), and the GSM8K accuracy gate. Measured on 4x B200 TP4/EP4, MTP 3: GSM8K 92.95/92.72 (built-in 92.72/92.65), acceptance length and throughput level with the built-in model and the stock worker. Signed-off-by: ZhaoyangWang <[email protected]>
…selection in the MTP step Select the verified target tokens and the MTP draft tokens on the vocab-sharded LM head output instead of gathering full-vocab logits: each rank takes the argmax of its shard and the ranks exchange (index, max) pairs through one NCCL all-reduce. Greedy verification returns logits_vocab_shard=True; non-greedy requests still gather logits and sample as before. The pair exchange uses an explicit NCCL all-reduce so every rank takes the same collective path during warmup autotuning. Forced-acceptance A/B (TP4/EP4, 4xB200, ABAB): geometric-mean TPOT 0.9885x over 8 points; no point slower beyond noise. Signed-off-by: ZhaoyangWang <[email protected]>
…nd head only on drafting rows In the first MTP draft step the attention still runs on every verify row (it writes the MTP layer's KV for all of them), but the MoE, the head norm and the draft head now run only on each request's drafting row (its last accepted position) instead of on all K+1 rows followed by a gather. Forced-acceptance A/B on top of the vocab-parallel change (TP4/EP4, 4xB200, ABAB x3): geometric-mean TPOT 0.9900x over 8 points, no point slower beyond noise (an earlier 2-rep round on the previous base: 0.9904x). Signed-off-by: ZhaoyangWang <[email protected]>
…ts in the MTP layer The checkpoint keeps the MTP layer's 288 routed experts in BF16, which on sm100 fall back to the unquantized CUTLASS MoE: the only BF16 path that takes the clamped SwiGLU, and one that reads twice the weight bytes of FP8. The draft step's MoE runs on a handful of rows per request and is weight-bandwidth bound. Build those experts as FP8_BLOCK_SCALES (128x128 tiles, FP32 dequant scales) and quantize the BF16 checkpoint weights on the device as they load. This selects the TRTLLM-Gen FP8 block-scale MoE, which supports the clamp, the DeepSeek-V3 routing and EP. The model overrides the module list the quantization-exclusion pass walks, so the pass does not reset the experts it just quantized. The main layers' NVFP4 experts and the shared experts are unchanged. Only draft tokens are affected; the target verifies every one. Forced-acceptance A/B (TP4/EP4, 4xB200, ABAB): geometric-mean TPOT 0.9739x over 8 points, 6 faster beyond noise, none slower. ShareGPT acceptance length (c=16, real acceptance): 3.431 -> 3.450. Signed-off-by: ZhaoyangWang <[email protected]>
… step 0's indexer selection The checkpoint sets index_share_for_mtp_iteration. Draft step 0 scores and selects pools as before and keeps each request's selection at its drafting row (a context's last row, a generation request's last accepted one); steps 1..K-1 skip the indexer's query projection, scoring and top-k and attend to that selection plus every position appended since. kpool_expand takes the tail_extra this needs (the tail starts at the pool holding position kv_len - 1 - tail_extra, so pools completed during the chain stay visible); the default 0 keeps every other caller unchanged. With at most select_k complete pools step 0 selects all of them, so the attended set equals a fresh selection. Forced-acceptance A/B on its own (TP4/EP4, 4xB200, ABAB, 1K/8K contexts): geometric-mean TPOT 0.9969x, every point within noise; the saving grows with the number of pools. ShareGPT acceptance length 3.462 -> 3.434. Signed-off-by: ZhaoyangWang <[email protected]>
…all-reduces with residual add and RMSNorm Under TP the MTP layer's attention and MoE outputs are each reduced, added to the residual and normalized. Both reductions now run as one RESIDUAL_RMS_NORM fused collective (Glm5NextAllReduce.residual_rms_norm): the attention's with post_attention_layernorm, the MoE's with the shared head norm. In draft step 0 the drafting rows are picked before the reduction, so it moves only those. Strategies without a fused kernel run the add and the norm after the reduction. Forced-acceptance A/B on its own (TP4/EP4, 4xB200, ABAB): geometric-mean TPOT 0.9950x. ShareGPT acceptance length 3.474 -> 3.451. Signed-off-by: ZhaoyangWang <[email protected]>
… its eh_proj input chunk eh_proj is row-parallel over [enorm(embed) | hnorm(hidden)], so each rank consumes one chunk of the concatenation. Build only the half (or halves) that chunk covers instead of both normalized halves and their concatenation. The values are unchanged. Forced-acceptance A/B on its own (TP4/EP4, 4xB200, ABAB): geometric-mean TPOT 0.9865x, mostly from the noisiest point (8K context, c=8); about 0.996x without it. Signed-off-by: ZhaoyangWang <[email protected]>
zhaoyangwang-nvidia
force-pushed
the
zhaoyang/trtllm-17515-glm53-flash-mv2-mtp
branch
from
November 3, 2026 03:39
10dd5f7 to
8139ac8
Compare
… through TPKeyExchange The verify and draft heads' greedy token selection exchanged (value, index) pairs with an NCCL all-reduce (local argmax, NCCL ring, pair reduction: three launches per head). With peer memory, take the tokens from TPKeyExchange.argmax_logits instead: local first maximum, orderable key and the TP group's maximum in one launch on its own peer buffers and epoch channels, so it never shares the Lamport all-reduce workspace. Same tokens as torch.argmax over the gathered vocabulary (lowest index on ties); NCCL stays the fallback without peer memory or beyond 4096 rows. ABAB (forced acceptance 2.4, 4x B200, TP4/EP4, MTP 3): TPOT geomean 0.9927; c=1 0.986 (isl1k) / 0.987 (isl8k) beyond noise, other points within noise. Acceptance length ShareGPT c=16 3.426 -> 3.370 (within the 2% tolerance; tokens are identical by construction). glm5_next unit tests: 147 passed. Signed-off-by: ZhaoyangWang <[email protected]>
…input embedding and draft step-0 setup Two chains of small launches in every speculative step become one kernel each (new model-local kernels.py): * embed_rms_norm_columns: the MTP layer's token embedding (with the stock embedding's zeroing of out-of-range ids), its enorm RMSNorm (fp32, x * rsqrt(mean(x^2) + eps) * w as the flashinfer norm) and the column slice this rank's row-parallel eh_proj consumes -- about ten launches per draft step before. * drafting_rows: in a generation-only step (every captured one) draft step 0 takes the accepted-token columns as a view and each request's drafting row from one launch, instead of the cumsum / cat / index arithmetic of the general (context + generation) path, which stays for mixed steps. ABAB, 4 repetitions (forced acceptance 2.4, 4x B200, TP4/EP4, MTP 3): TPOT isl1k c=1 0.986, isl8k c=1 0.987 (beyond noise), c=4 / c=8 within noise; geomean 0.9882. Separately each was within noise (0.997 / 0.994 at c=1). Acceptance length ShareGPT c=16 3.431 -> 3.391 (within tolerance). glm5_next unit tests: 176 passed (adds test_mtp_kernels.py, listed in l0_b200). Signed-off-by: ZhaoyangWang <[email protected]>
…x + TP exchange for few-row heads New op trtllm::lm_head_argmax (cpp/tensorrt_llm/kernels/lmHeadArgmax): the greedy tokens of an LM head of up to 8 rows over the tensor-parallel group's vocabulary in one launch. Each CTA streams its range of this rank's vocabulary shard with cp.async.bulk into a shared-memory ring (a producer warp, L2 evict-first), runs m16n8k16 MMAs with the rows as the token columns on eight consumer warps, and folds every tile's logits into per-row argmax keys in registers: no logits are stored, no split-K reduction, no separate argmax. The last CTA reduces the CTAs' keys and exchanges them with the other ranks through peer-mapped buffers (three rotating epochs), so every rank writes the same token (torch.argmax order: lowest index on ties). SM90+, greedy only; the kernel follows glm5-serve's head_keys. The GLM-5.3-Flash target uses it for the draft heads and, for a greedy batch of few verify rows, for the verify head too: the forward then computes no verify logits and returns logits=None (the speculative sampler reads only the tokens; the engine skips logits post-processing, and this target declines guided decoding). Larger batches and sampled batches keep the logits path. The exchange buffers come from _PeerBuffers at construction (collective); without the op, SM90 or peer memory the head logs why and keeps its path. Correctness: GSM8K at max batch 2 (every step's verify head fused) 92.95 vs 93.06 base (within the 0.7 stderr; the fused head compares fp32 sums where the logits path compares bf16 logits); acceptance length ShareGPT c=16 3.476 -> 3.408 (within tolerance); unit tests in tests/unittest/_torch/kernels/parallel/test_lm_head_argmax.py. Performance: in a c=1 decode iteration (5.58 ms) the four heads take 53-56 us each against about 60-65 us for the cuBLAS GEMM + split-K reduce + key exchange; ABAB TPOT 0.999 / 0.997 at concurrency 1, within noise. Signed-off-by: ZhaoyangWang <[email protected]>
1 task done
Signed-off-by: ZhaoyangWang <[email protected]>
Merged
1 task done
Signed-off-by: ZhaoyangWang <[email protected]>
zhaoyangwang-nvidia
force-pushed
the
zhaoyang/trtllm-17515-glm53-flash-mv2-mtp
branch
from
November 6, 2026 09:24
7511522 to
ca0c404
Compare
Signed-off-by: ZhaoyangWang <[email protected]>
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
GLM-5.3-Flash (
Glm5NextForConditionalGeneration) gets its first modeling_v2 target, and its one-model MTP speculative decoding moves into the model's own forward: no speculative worker is built.Target. New
glm5_nextfamily withglm_5_3_flash_nvfp4__sm_100__default: the built-in GLM-5.3-Flash text model (modeling_glm5_next.py) copied as the generic path, routed for the NVFP4 checkpoint on sm100 without pipeline or context parallelism. Like the Kimi K3 targets it runs the built-in forward rather than aPrefillTarget/DecodeTargetsplit; the claims test's exemption becomes a named set of such families.MTP in the forward. The causal LM builds its own drafter (the checkpoint's MTP layer with the target's LM head and embedding) and runs the whole speculative step inside its forward (
Glm5NextMtpStep):update_mamba_states; the next verify replays accepted drafts);The engine side is unchanged: input packing,
SpecSampler, KV rewind and graph capture see the same contract as with the stock MTP-Eagle worker. Routing and the constructor refuse what the step does not compute (rejection sampling, relaxed acceptance, penalties, SA, dynamic trees, vanilla MTP, a separate draft checkpoint, draft-length schedules); guided decoding is declined.TLLM_GLM5_NEXT_MTP_STOCK_WORKER=1runs the same drafter on the stock worker for A/B measurement.This is the first step of moving speculative decoding into modeling_v2 targets so it can be specialized and fused with the model; the step computes what the stock worker computes, and kernel-level optimizations of the speculative path will follow in this PR as separate commits, each measured against this one.
Measured (4x B200, TP4/EP4, NVFP4, MTP 3; built-in modeling vs this target with the stock worker vs this target with the in-model step):
Speculative-path optimizations (one commit each, measured by ABAB against its parent: forced acceptance 2.4, random 1K/1K and 8K/512 at concurrency 1/8/64, TPOT geometric mean; acceptance length checked on ShareGPT with natural acceptance):
0fb9c7f232f74745d634bf6662708b4550582547index_share_for_mtp_iteration)4ddf42ece38139ac8e52eh_projinput chunkc60eaf9eabTPKeyExchange(one launch: local maximum, key, group maximum)1038ad72dfenorm+ column slice and the generation-only draft step 0 setup as one Triton kernel each69cf71d80ftrtllm::lm_head_argmax: an LM head of up to 8 rows, its argmax and the TP group's maximum in one kernel (logits never stored); used by the draft heads and, for greedy batches of few verify rows, the verify head (the forward then returns no logits)Against the stock MTP-Eagle worker on the same target (
1bfc6e33dewithTLLM_GLM5_NEXT_MTP_STOCK_WORKER=1),1038ad72dfis 5.2% (ShareGPT) / 5.6% (random 1K/1K) faster in output throughput per GPU (geomean over concurrency 1-64, natural acceptance) at the same acceptance length. Through8139ac8e52the in-model step is 3.3% faster than the first commit (TPOT geomean, computelab; 3.9% on a second cluster) at the same GSM8K and acceptance length; the last two commits add about 2% at concurrency 1. Speculative decoding is now 10-16% of a decode iteration (concurrency 64 / 1).Test Coverage
tests/unittest/_torch/modeling_v2/models/glm5_next/test_glm5_next_routing.py(CPU): routing admits the NVFP4 checkpoint on sm100 at TP / EP / attention-DP layouts with or without MTP, and declines other shapes, quantizations, PP, sm103 and the unsupported speculative features.tests/unittest/_torch/modeling_v2/models/glm5_next/glm_5_3_flash_nvfp4__sm_100__default/spec/test_modeling_v2_mtp_step.py(B200): the in-model step against the stock MTP-Eagle worker on synthetic batches (generation-only, context-only, mixed; greedy and sampled; K = 3, 1, 0): identical outputs, identical attention metadata on every draft step, identical KDA commits, metadata restored.tests/unittest/_torch/modeling_v2/models/glm5_next/glm_5_3_flash_nvfp4__sm_100__default/spec/test_mtp_kernels.py(B200, listed inl0_b200): the MTP layer's fused kernels against the modules / tensor ops they replace (embedding + RMSNorm + column slice with out-of-range ids, drafting rows).tests/unittest/_torch/kernels/parallel/test_lm_head_argmax.py(SM90+, underkernels/parallelinl0_h100):trtllm::lm_head_argmaxagainst torch's argmax (shapes, repeated calls, ties, strided output, rejected shapes).tests/unittest/_torch/modeling_v2/test_modeling_v2_claims.py(CPU).tests/integration/defs/accuracy/modeling_v2/test_glm5_next.py::TestModelingV2Glm53FlashNvfp4Sm100Default(4x B200): GSM8K with and without MTP. The NVFP4 reference ingsm8k.yamlis still to be added.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