Repository navigation
perf(kernel): fuse adjacent mHC post and pre operations for Hopper decode - #5216
Merged
RunningLeon merged 4 commits intoDec 2, 2026
Merged
Conversation
silencelamb
marked this pull request as ready for review
November 30, 2026 06:02
This was referenced Nov 30, 2026
silencelamb
requested review from
RunningLeon,
hehesnail and
zzwwrr
and removed request for
hehesnail
December 1, 2026 06:38
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.
Motivation
A matched GLM-5.3-Flash single-request decode trace on H200 recorded 450 mHC kernels per step in LMDeploy (1.230 ms of kernel time) and 181 in vLLM (0.957 ms). Each of the 45 target layers has attention and FFN mHC boundaries. The preceding Post and following Pre can share the updated residual at 89 internal boundaries.
Implementation
LMDEPLOY_FUSED_MHC_DECODE=1, for the PyTorch engine. GLM-5.3-Flash and DeepSeek-V4 Flash/Pro dispatch through the sharedHcPrePostmodule. The CUDA implementation supports four residual streams, hidden size 4096 or 7168, and 1–32 BF16 decode tokens per rank on SM90. Prefill, deterministic mode and other shapes retain their existing path.Incremental AgentX performance
On the three-PR deployment at C100, enabling fused mHC (
99add054) increased output throughput by 1.25%, request throughput by 1.58%, and goodput by 4.50%. These are full-service results on GLM-5.3-Flash. The single-boundary and DeepSeek-V4 measurements below retain their own workloads.8×H200, DP8/EP8/TP1, native MTP3, RDMA Mooncake, Weka 256K, independent 1,800 s scored windows. Five-PR AgentX report with configurations, controls and concurrency sweeps.
Full GSM8K accuracy on this PR
Scored
99add054on GLM-5.3-Flash FP8 with only the feature in this PR enabled. All 1,319 test questions used the same five train demonstrations, greedy decoding, seed 42, C32 through the router and the historical QA settingmax_tokens=1024(generated tokens per question, with input tokens counted separately). The grader compares the last parsable number after####with the gold answer and includes all 1,319 questions.LMDEPLOY_FUSED_MHC_DECODE=1The historical QA image on the same GLM-5.3-Flash FP8 weights scored 91.74% / 91.58% (1,210 / 1,208 correct out of 1,319). The earlier 91.96% QA result used a different checkpoint.
This full-set score is for GLM. The DeepSeek-V4 Flash and Pro GSM8K smoke checks below retain their 16-question scope.
Per-PR counts, repeat runs and scoring evidence.
GLM-5.3-Flash single-boundary latency on H200
CUDA Graphs cycle through all 89 internal sublayer weights from the GLM-5.3-Flash checkpoint. Inputs are synthetic and identical across paths. Each value is the median of 15 alternating-order rounds, eight graph replays per round, in microseconds per boundary. This comparison uses the LMDeploy implementation in this PR for both modes.
Validation
test_dsv4_hc_pre_fused.py,test_dsv4_hc_prepost.pyandtest_routed_experts.py. Coverage includes both BF16 rounding points with changed inputs across graph replays and the intra-/inter-layer handoff in a two-layer hybrid decoder.GLM-5.3-Flash full-checkpoint decode
Paired runs used the same GLM-5.3-Flash checkpoint (
3f1971b7), 8×H200, DP8/EP8/TP1, one active request, a 1,024-token prompt, and the same 64 teacher-forced decode inputs. Both runs captured one CUDA graph per rank. On active rank 0:The fused trace contains 89 Post/projection kernels. The default and fused runs agree on the prefill argmax and all 97,417 sampled prefill cache/state values on rank 0. Decode top-1 agreed at 60/64 matched positions across the 154,880-way vocabulary. Mean per-position relative L2 logit difference was 0.1117 (maximum 0.2398). Replaying the same path within each process reproduced all 64 argmax tokens. This single trajectory measures numerical drift and latency. Task-level quality and MTP acceptance remain unmeasured.
A separate fresh-process control with the flag disabled reproduced all 64 × 154,880 reference logit values exactly. The same four top-1 differences reappeared when comparing that control with the fused run. In an additional eager diagnostic on the first real decode input, both kernels received identical inputs at each of the 89 boundaries. Their normalized BF16 activations differed in 54 of 364,544 elements (maximum absolute difference 0.001953125). The operator-level agreement should be interpreted separately from the measured full-model logit drift.
DeepSeek-V4
The shared module owns Post deferral, consumption by the next Pre, and the deterministic-mode opt-out. The CUDA backend checks the input shape and device. DeepSeek-V4 retains its standalone RMSNorm in the default path and materializes the final four-stream residual before its learned hyper-head. For Pro, the reduction indexes all 14 segments per thread at width 7168. Width 4096 retains the original reduction order.
Each row uses all eligible attention/FFN checkpoint weights (85 in Flash and 121 in Pro) with identical synthetic activations on a single H200. The comparison uses each model's production Post, Pre and standalone RMSNorm as the default. CUDA-event medians are in microseconds per boundary.
Full-checkpoint validation on H200
Each model used a 512-token prompt and 64 decode inputs from its default greedy trajectory. We compared every vocabulary logit and timed the same inputs with the flag set to 0 and 1. The step measurement is the median rank-0 CUDA-event time across two warm 64-step graph replays (target forward and LM head). Prefill logits matched exactly in both pairs.
6e763230)0366e4e0)Mean per-position relative logit L2 differences were Flash 0.08191, Pro 0.07817. Mean next-token NLL on the fixed default greedy continuation (nats, default → fused) was Flash 0.27052 → 0.28090, Pro 0.07070 → 0.07263.
Each model also generated its own greedy answers to the first 16 GSM8K test questions, with the first five training examples as demonstrations, a 160-token generation limit and numeric exact match after
####. Missing answers at the limit count as incorrect. This is a small paired smoke test.Pro changed from 60 (correct) to 55 on the 15th question. On the separate fixed decode trajectory Pro kept all 64 top-1 tokens, demonstrating why we also tested free-running answers.
Shared-path regression
2965d40fand this revision. One additional two-token scale assertion varied with warmup order. The strict tolerances were retained.