Repository navigation
[port] Fuse standard RoPE packing for MLA and DSA (upstream #6343) - #98
Merged
Merged
Conversation
This was referenced Sep 16, 2026
HJSang
marked this pull request as ready for review
September 17, 2026 00:21
HJSang
force-pushed
the
port/6343-fused-rope-packing
branch
from
September 21, 2026 17:11
89cf02a to
b388c8e
Compare
HJSang
force-pushed
the
port/6343-fused-rope-packing
branch
from
September 23, 2026 16:32
b388c8e to
977bdce
Compare
yueming-yuan
approved these changes
Sep 24, 2026
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.
Test results (2026-09-23) — ✅ no regressions
test_mla_yarn_rope_apply,test_absorbed_mla,test_attention_variant_dsa,test_multi_latent_attention(4 ranks)None of the 106 failures is caused by this PR. The 15 that are not on the base are all in tests this PR adds, and they fail for reasons already present on
miles-main:ValueError: spec sets linear_q_up_proj=TEColumnParallelLinear and q_layernorm=…. This comes from the QK-norm resolver ported in [port] Megatron-Core APIs needed by Megatron-Bridge main (#4452 MLA resolver, gdn alias, #5865 FSDP names) #102, and the same error already breaks 80 existingtest_absorbed_mlacases on the base. It should be tracked separately against [port] Megatron-Core APIs needed by Megatron-Bridge main (#4452 MLA resolver, gdn alias, #5865 FSDP names) #102.[rope-True]case of a CP-THD precision test whose 3 sibling cases fail the same way on the base.This PR's kernels are also exercised by the #99 / #101 E2E runs (RoPE fusion is off in Miles recipes, so there is no numerics change).
Environment: 2× new 4× B200 devboxes (
b200-verda-k8s),radixark/miles:devrebuilt after miles#3296 (cuDNN Frontend 1.28.0 with the compact wrapper, TE 2.17, torch 2.13), Miles @a6b72d31f, basemiles-main@96fe16ecb. Unit tests ran undertorchrun --nproc_per_node=4, and every failure was compared against the base run the same way. The Miles E2E recipe is DeepSeek-V4-Flash-FP8-4layer, GSM8K, deterministic mode, 3 rollouts,--dsv4-impl megatron --dsa-kernel-backend cudnn, with a per-token old-vs-train log-prob dump (~3.14M response tokens per arm). Rollouts were identical across arms. Full details: #99 (comment)Ports NVIDIA#6343 (
53f4976901, merged to upstreamdev2026-08-26, author Robin Zhang) ontomiles-main. Cherry-picked with-x; auto-merged with no conflicts.What it does
fused_mla_rope_concat) with a fused backward. Upstream measured the long-sequence packing region going from 85 kernels to 2 and from 0.848 ms to 0.099 ms per attention call.transformer_config.pyasserts that forbade RoPE fusion for MLA with standard RoPE and for DSA are removed; arotary_percent < 1guard falls back to the unfused path with a one-time warning.[PE, NOPE]projection.Upstream A/B on 8x B200, GLM-5.2 proxy: step time -2.11% (THD 4K, CP1) and -2.80% (THD 32K, CP8); self-attention GPU span -10.6% / -11.5%; memory unchanged.
Interaction with radixark changes
fused_mla_yarn_rope_apply.pyis also modified by radixark commitab0327a0b(MLA RoPE Triton kernel head indexing andv_dim=0support, #5). The merge kept every line of that fix; verified by grepping each added line ofab0327a0bin the merged file.Applicability to Miles: opt-in, not automatic
Miles'
scripts/models/deepseek-v4-flash.pypasses--no-rope-fusion(since NVIDIA#1910), and the true-on-policy contract disables RoPE fusion for the Megatron backend to keep trainer and SGLang numerics aligned. Withapply_rope_fusion=False,should_use_fused_mla_rope()returns False and none of the new kernels run. So this port changes nothing for current Miles recipes. To realize the speedup, a follow-up in Miles would drop--no-rope-fusionfor DSv4 runs that do not require bitwise trainer/rollout alignment, and that change should be A/B'd for numerics before adoption.The port is still worth landing now: it keeps
miles-mainaligned with upstream ahead of thedevbump, and NVIDIA#7064 (next in this series) builds on the RoPE primitives introduced here.Validation
4x B200 devbox,
radixark/miles:dev, Megatronmiles-main@73b54618f+ this commit, single-process pytest:fusions/test_mla_yarn_rope_apply.pyexperimental_attention_variant/test_absorbed_mla.pyexperimental_attention_variant/test_attention_variant_dsa.pytransformer/test_multi_latent_attention.pyexperimental_attention_variant/test_attention_delay_wgrad.pyThe three failures reproduce identically on unpatched
miles-main:test_absorbed_mla::test_functionality[...tp_cp_sp1]andTestFusedDSAIndexerLossGradientTP::test_fused_indexer_loss_gradient_tp_consistencyrequire a multi-process TP launch (world_size not divisible by model_sizein a single process; upstream also marks the latter flaky), andTestParallelMLAAttention::test_gpu_forward_thd_padded[yarn]fails apacked_seq_paramsassertion on this base. Not caused by this change.Series
Second of two ports of DeepSeek V4 commits from upstream
devthatmiles-mainlacks. Companion: #97 (upstream NVIDIA#7079). Further DSv4 commits (NVIDIA#7064 fused THD ops, NVIDIA#5992 compact indexer) are left for the fulldevbump.🤖 Generated with Claude Code