GLM-5.2 131k context parallelism: dsv4-next stack + GLM fused-DSA contiguous-CP adapter - #7
GLM-5.2 131k context parallelism: dsv4-next stack + GLM fused-DSA contiguous-CP adapter#7JackRao123 wants to merge 546 commits into
Conversation
… state_dict (NVIDIA#3243) Co-authored-by: Xin Yao <xiny@nvidia.com>
Signed-off-by: oliver könig <okoenig@nvidia.com>
Signed-off-by: oliver könig <okoenig@nvidia.com>
Co-authored-by: Xin Yao <xiny@nvidia.com>
Signed-off-by: oliver könig <okoenig@nvidia.com> Signed-off-by: Charlie Truong <chtruong@nvidia.com> Co-authored-by: Charlie Truong <chtruong@nvidia.com>
Signed-off-by: oliver könig <okoenig@nvidia.com>
Signed-off-by: Charlie Truong <chtruong@nvidia.com> Signed-off-by: oliver könig <okoenig@nvidia.com> Co-authored-by: oliver könig <okoenig@nvidia.com>
Co-authored-by: Li Tao <lit@nvidia.com>
Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Signed-off-by: oliver könig <okoenig@nvidia.com>
Signed-off-by: oliver könig <okoenig@nvidia.com>
Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Signed-off-by: oliver könig <okoenig@nvidia.com> Signed-off-by: Charlie Truong <chtruong@nvidia.com> Signed-off-by: Hongbin Liu <hongbinl@nvidia.com> Signed-off-by: Youngeun Kwon <youngeunk@nvidia.com> Signed-off-by: Keshav Santhanam <ksanthanam@nvidia.com> Signed-off-by: Jimmy Zhang <jiemingz@nvidia.com> Signed-off-by: Santosh Bhavani <santosh.bhavani@live.com> Signed-off-by: Deepak Narayanan <dnarayanan@nvidia.com> Signed-off-by: Hollow Man <hollowman@opensuse.org> Signed-off-by: Robin Zhang <robinz@nvidia.com> Signed-off-by: jinliangl <jinliangl@nvidia.com> Signed-off-by: Maanu Grover <maanug@nvidia.com> Signed-off-by: dimapihtar <dpihtar@gmail.com> Signed-off-by: xiaoxi-wangfj <690912414@qq.com> Signed-off-by: skydoorkai <htsantaclara@163.com> Signed-off-by: Asha Anoosheh <aanoosheh@nvidia.com> Signed-off-by: meg miranda <mmiranda@nvidia.com> Signed-off-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com> Signed-off-by: sajadn <snorouzi@nvidia.com> Signed-off-by: lit <lit@nvidia.com> Signed-off-by: Faradawn Yang <73060648+faradawn@users.noreply.github.com> Signed-off-by: Cory Ye <cye@nvidia.com> Signed-off-by: adithyare <adithyare@nvidia.com> Signed-off-by: Soumye Singhal <soumyes@cw-dfw-cs-001-dc-01.cm.cluster> Signed-off-by: Ahmad Kiswani <kiswani.ahmad@gmail.com> Signed-off-by: mikail <mkhona@nvidia.com> Co-authored-by: HaochenYuan <106647990+HaochenYuan@users.noreply.github.com> Co-authored-by: Philip Petrakian <ppetrakian@nvidia.com> Co-authored-by: oliver könig <okoenig@nvidia.com> Co-authored-by: Duncan Riach <33532941+duncanriach@users.noreply.github.com> Co-authored-by: yobi byte <yobibyte@users.noreply.github.com> Co-authored-by: Charlie Truong <chtruong@nvidia.com> Co-authored-by: wdykas <73254672+wdykas@users.noreply.github.com> Co-authored-by: root <root@gpu-h100-0348.cm.cluster> Co-authored-by: root <root@gpu-h100-0193.cm.cluster> Co-authored-by: root <root@gpu-h100-0082.cm.cluster> Co-authored-by: root <root@gpu-h100-0495.cm.cluster> Co-authored-by: William Dykas <wdykas@cw-pdx-cs-001-vscode-02.cm.cluster> Co-authored-by: root <root@gpu-h100-0213.cm.cluster> Co-authored-by: root <root@gpu-h100-0435.cm.cluster> Co-authored-by: root <root@gpu-h100-0188.cm.cluster> Co-authored-by: root <root@gpu-h100-0032.cm.cluster> Co-authored-by: root <root@gpu-h100-0023.cm.cluster> Co-authored-by: root <root@gpu-h100-0368.cm.cluster> Co-authored-by: root <root@gpu-h100-0203.cm.cluster> Co-authored-by: root <root@gpu-h100-0229.cm.cluster> Co-authored-by: root <root@gpu-h100-0123.cm.cluster> Co-authored-by: root <root@gpu-h100-0217.cm.cluster> Co-authored-by: root <root@gpu-h100-0496.cm.cluster> Co-authored-by: root <root@gpu-h100-0261.cm.cluster> Co-authored-by: GitHub Actions <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jiayi Yan <66017932+1195343015@users.noreply.github.com> Co-authored-by: Yuzhong Wang <yuzhongw@nvidia.com> Co-authored-by: Hongbin Liu <lhb8125@users.noreply.github.com> Co-authored-by: Youngeun Kwon <youngeunk@nvidia.com> Co-authored-by: Keshav Santhanam <ksanthanam@nvidia.com> Co-authored-by: Jimmy Zhang <133159885+jiemingz@users.noreply.github.com> Co-authored-by: tgkyrie <74066353+tgkyrie@users.noreply.github.com> Co-authored-by: Dmytro Pykhtar <37850217+dimapihtar@users.noreply.github.com> Co-authored-by: Xin Yao <xiny@nvidia.com> Co-authored-by: rkarimimahab <rkarimimahab@nvidia.com> Co-authored-by: Rabeeh Mahabadi <rkarimimahab@nb-hel-cs-001-vscode-02.cm.cluster> Co-authored-by: Sanjeev Satheesh <sasatheesh@nvidia.com> Co-authored-by: Deepak Narayanan <dnarayanan@nvidia.com> Co-authored-by: Santosh Bhavani <santosh.bhavani@live.com> Co-authored-by: Ahmad Kiswani <kiswani.ahmad@gmail.com> Co-authored-by: Li Tao <lit@nvidia.com> Co-authored-by: Maanu Grover <109391026+maanug-nv@users.noreply.github.com> Co-authored-by: mvirts <mvirts@gmail.com> Co-authored-by: Antoni-Joan Solergibert <asolergibert@nvidia.com> Co-authored-by: ℍ𝕠𝕝𝕝𝕠𝕨 𝕄𝕒𝕟 <hollowman@opensuse.org> Co-authored-by: Robin Zhang <robinz@nvidia.com> Co-authored-by: Sheng Fu <shengf@nvidia.com> Co-authored-by: Venmugil Elango <498703+venmugil@users.noreply.github.com> Co-authored-by: mathemakitten <helenn@nvidia.com> Co-authored-by: Jared Casper <155158+jaredcasper@users.noreply.github.com> Co-authored-by: Parth Mannan <38387286+parthmannan@users.noreply.github.com> Co-authored-by: Teodor-Dumitru Ene <34819528+tdene@users.noreply.github.com> Co-authored-by: Tong Liu <tongliu@nvidia.com> Co-authored-by: Li Jinliang <jinliangl@nvidia.com> Co-authored-by: Jinliang Li <jinliangl@pool0-01676.cm.cluster> Co-authored-by: Jinliang Li <jinliangl@cw-dfw-cs-001-vscode-01.cm.cluster> Co-authored-by: Yashaswi Karnati <144376261+yashaswikarnati@users.noreply.github.com> Co-authored-by: Nick Schank <nick@reflection.ai> Co-authored-by: Jeffrey Chen <jeffrey@reflection.ai> Co-authored-by: janEbert <janpabloe@nvidia.com> Co-authored-by: rj42 <lbkzman@gmail.com> Co-authored-by: Juntao Wang <juntaow@nvidia.com> Co-authored-by: Pingtian Li <158665726+Wohox@users.noreply.github.com> Co-authored-by: Chris Grimm <chris@reflection.ai> Co-authored-by: Chenhan D. Yu <5185878+ChenhanYu@users.noreply.github.com> Co-authored-by: Eric Harper <eharper@nvidia.com> Co-authored-by: xiaoxi-wangfj <690912414@qq.com> Co-authored-by: Jianbin Chang <shjwudp@gmail.com> Co-authored-by: c1lovez1 <141424951+c1lovez1@users.noreply.github.com> Co-authored-by: Zhang Haitao <htsantaclara@163.com> Co-authored-by: yeyu-nvidia <yeyu@nvidia.com> Co-authored-by: kwyss-nvidia <kwyss@nvidia.com> Co-authored-by: Jon Barker <jbarker@nvidia.com> Co-authored-by: Asha Anoosheh <aanoosheh@nvidia.com> Co-authored-by: Siddharth Singh <136645615+sidsingh-nvidia@users.noreply.github.com> Co-authored-by: megnvidia <mmiranda@nvidia.com> Co-authored-by: thecaptain789 <257642323+thecaptain789@users.noreply.github.com> Co-authored-by: thecaptain789 <thecaptain789@users.noreply.github.com> Co-authored-by: litianjian <litianjian@bytedance.com> Co-authored-by: Yan Bai <baiyan1996@icloud.com> Co-authored-by: xuwchen <xuwenc@nvidia.com> Co-authored-by: John St. John <jstjohn@users.noreply.github.com> Co-authored-by: Lawrence McAfee <85179052+lmcafee-nvidia@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Robert Kirby <ArEsKay3@users.noreply.github.com> Co-authored-by: Siddharth Singh <sidsingh@nvidia.com> Co-authored-by: Robert Kirby <rkirby@cw-dfw-cs-001-vscode-01.cm.cluster> Co-authored-by: Teodor-Dumitru Ene <teodord.ene@gmail.com> Co-authored-by: Dennis(Zhenhuan) Liu <denliu@nvidia.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com> Co-authored-by: Shanmugam Ramasamy <111910568+shanmugamr1992@users.noreply.github.com> Co-authored-by: vasunvidia <108759426+vasunvidia@users.noreply.github.com> Co-authored-by: Philip Petrakian <pgpetrak@gmail.com> Co-authored-by: Sajad Norouzi <sajad.n@gmail.com> Co-authored-by: Kunlun Li <94586211+kunlunl@users.noreply.github.com> Co-authored-by: xielaixin <xielx@shanghaitech.edu.cn> Co-authored-by: Robert Kirby <rkirby@nvidia.com> Co-authored-by: Ming <93323717+dndnda@users.noreply.github.com> Co-authored-by: liming127 <liming127@meituan.com> Co-authored-by: Jon Barker <jbarker@oci-hsg-cs-001-vscode-01.cm.cluster> Co-authored-by: helen ngo <helen.ngo14@gmail.com> Co-authored-by: Jenny Chen <jennifchen@nvidia.com> Co-authored-by: yueshen2016 <39203804+yueshen2016@users.noreply.github.com> Co-authored-by: Faradawn Yang <73060648+faradawn@users.noreply.github.com> Co-authored-by: Cory Ye <44509866+cspades@users.noreply.github.com> Co-authored-by: Adi Renduchintala <adithya.r@gmail.com> Co-authored-by: Soumye Singhal <soumyes@cw-dfw-cs-001-dc-01.cm.cluster> Co-authored-by: Seonjin Na <sna@nvidia.com> Co-authored-by: Seonmyeong Bak <sbak@nvidia.com> Co-authored-by: Mikail Khona (NVIDIA) <mkhona@nvidia.com>
…tp_size. (NVIDIA#3529) Co-authored-by: xiaotaoliu <xiaotaoliu@tencent.com> Co-authored-by: Yuzhong Wang <yuzhongw@nvidia.com> Co-authored-by: Zijie Yan <zijiey@nvidia.com>
…tOutput (NVIDIA#3641) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: xiaoyao0115 <1804647152@qq.com> Signed-off-by: tailaim <tailaim@nvidia.com> Co-authored-by: kunlunl <kunlunl@nvidia.com>
…VIDIA#3668) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Signed-off-by: Hao Wu <skyw@nvidia.com> Co-authored-by: Hao Wu <skyw@nvidia.com>
Co-authored-by: Robin Zhang <robinz@nvidia.com>
…onnection(mHC). (NVIDIA#2943) Co-authored-by: Jingqin Yang <jingqiny@login-eos01.eos.clusters.nvidia.com> Co-authored-by: root <root@eos0478.eos.clusters.nvidia.com> Co-authored-by: Dennis Liu <denliu@nvidia.com>
…VIDIA#3629) (NVIDIA#3729) Co-authored-by: Jianbin Chang <shjwudp@gmail.com>
Signed-off-by: hongbinl <hongbinl@nvidia.com> Signed-off-by: svcnvidia-nemo-ci <svc-nvidia-nemo-ci@nvidia.com>
Signed-off-by: Teodor-Dumitru Ene <teodord.ene@gmail.com> Signed-off-by: Asha Anoosheh <aanoosheh@nvidia.com> Signed-off-by: Pranav Prashant Thombre <pthombre@nvidia.com> Signed-off-by: janEbert <janpabloe@nvidia.com> Signed-off-by: Philip Petrakian <ppetrakian@nvidia.com> Signed-off-by: Helen Ngo <helenn@nvidia.com> Signed-off-by: ykarnati <ykarnati@nvidia.com> Signed-off-by: Shijie Wang <jaywan@nvidia.com> Signed-off-by: Ajay Balasa <abalasa@nvidia.com> Signed-off-by: oliver könig <okoenig@nvidia.com> Signed-off-by: Antoni-Joan Solergibert <asolergibert@nvidia.com> Signed-off-by: ilml <tolong@nvidia.com> Signed-off-by: Keshav Santhanam <ksanthanam@nvidia.com> Signed-off-by: sraman <sraman@nvidia.com> Signed-off-by: Jingyue Wu <wujingyue@gmail.com> Signed-off-by: Hollow Man <hollowman@opensuse.org> Signed-off-by: hongbinl <hongbinl@nvidia.com> Signed-off-by: Charlie Truong <chtruong@nvidia.com> Signed-off-by: Lawrence McAfee <lmcafee@nvidia.com> Signed-off-by: wdykas <wdykas@nvidia.com> Signed-off-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Signed-off-by: svcnvidia-nemo-ci <svc-nvidia-nemo-ci@nvidia.com> Co-authored-by: Teodor-Dumitru Ene <34819528+tdene@users.noreply.github.com> Co-authored-by: Asha Anoosheh <aanoosheh@nvidia.com> Co-authored-by: Jorge Albericio <jalbericiola@nvidia.com> Co-authored-by: Pranav Thombre <pthombre@nvidia.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: janEbert <janpabloe@nvidia.com> Co-authored-by: Philip Petrakian <ppetrakian@nvidia.com> Co-authored-by: mathemakitten <helenn@nvidia.com> Co-authored-by: Yashaswi Karnati <144376261+yashaswikarnati@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Shijie <505749828@qq.com> Co-authored-by: Ajay <abalasa@nvidia.com> Co-authored-by: oliver könig <okoenig@nvidia.com> Co-authored-by: Antoni-Joan Solergibert <asolergibert@nvidia.com> Co-authored-by: Deepak Narayanan <dnarayanan@nvidia.com> Co-authored-by: Tom Long <tolong@nvidia.com> Co-authored-by: Keshav Santhanam <ksanthanam@nvidia.com> Co-authored-by: Teodor-Dumitru Ene <teodord.ene@gmail.com> Co-authored-by: Siddhartha Raman Sundara Raman <sraman@nvidia.com> Co-authored-by: Jingyue Wu <wujingyue@gmail.com> Co-authored-by: ℍ𝕠𝕝𝕝𝕠𝕨 𝕄𝕒𝕟 <hollowman@opensuse.org> Co-authored-by: Hongbin Liu <lhb8125@users.noreply.github.com> Co-authored-by: Charlie Truong <chtruong@nvidia.com> Co-authored-by: Lawrence McAfee <85179052+lmcafee-nvidia@users.noreply.github.com> Co-authored-by: wdykas <73254672+wdykas@users.noreply.github.com> Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
…ention (NVIDIA#5011) Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com>
Signed-off-by: tailaim <tailaim@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: kunlunl <kunlunl@nvidia.com> Co-authored-by: Kaixiang Lei <5780122+shyoshyo@users.noreply.github.com>
Signed-off-by: guihong-nv <guihongl@nvidia.com>
NVIDIA#5388) Signed-off-by: pingtianl <pingtianl@nvidia.com> Signed-off-by: Pingtian Li <pingtianl@nvidia.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Yan Bai <bayan@nvidia.com>
Signed-off-by: HaochenYuan <haocheny@nvidia.com>
…IA#3282) Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: kunlunl <kunlunl@nvidia.com>
…it-recompute RoPE: cast pid_m (program_id) to int64 in all 4 fused_mla_yarn_rope_apply kernels so seq_index*stride (H*D=36864) doesn't overflow int32 at seq>58k (131k -> 4.83e9). Fixes cudaErrorIllegalAddress in the attention backward. split-recompute: recompute_split_attn_mlp staged recompute (attn and MoE backward never co-reside) to cut the first-backward memory peak.
* feat(dsa): GLM-5.2 IndexShare config + helpers on the new DSA base Add dsa_indexer_topk_freq / dsa_indexer_skip_topk_offset config (cross-layer top-k sharing) with "dsa"-variant validation, and the is_dsa_skip_topk_layer / source_dsa_compute_layer helpers. Leaves the new base's dsv4_hybrid path intact. Signed-off-by: Paras Stefanopoulos <paras@parsed.com> * feat(dsa): fused absorbed-MLA DSA via dsa_kernels (DSAttentionFused) Add DSAttentionFused, a fused DSA core for the GLM-5.2 absorbed-MLA path: frozen-indexer top-k (indexer_topk) + FlashMLA sparse attention (dsa_sparse_attn), with cross-layer top-k sharing (IndexShare). Wire it as the apply_dsa_kernel_fusion branch of get_dsa_module_spec_for_backend alongside AbsorbedMLASelfAttention. Vendor the combined-kv AbsorbedMLASelfAttention from the trainers-main-dsv4-forward line (MQA matrix absorption: K up-proj folded into the query, V up-proj applied after core attention; combined linear_kv_up_proj split at runtime). On trainers-main this class was an unwired orphan with split k/v fields and no bridge mapping; the combined form maps 1:1 from HF kv_b_proj and is what the GLM-5.2 fused path requires. Signed-off-by: Paras Stefanopoulos <paras@parsed.com> * feat(dsa): fold LoRA adapter into the absorbed kv up-projection AbsorbedMLASelfAttention consumes linear_kv_up_proj as a raw weight during matrix absorption (K's up-proj folded into the query, V's applied after core attention) instead of calling its forward, so a LoRA adapter on that module would otherwise be ignored. Add _effective_kv_up_weight(): when the module is LoRA-wrapped (duck-typed AdapterWrapper, to avoid a megatron.core -> megatron.bridge dependency) return W_base + scale * (B @ A) and feed that into the absorption einsums, so the adapter trains (grads flow to A/B) and serves consistently. Restricted to TP=1 (the fused DSA path already enforces it). Signed-off-by: Paras Stefanopoulos <paras@parsed.com> * refactor(dsa): isolate GLM-5.2 fused DSA into additive files Keep GLM-5.2 support additive so it does not edit the actively-developed upstream DSA modules, minimizing rebase conflicts against NVIDIA dev. - glm_dsa_fused.py (new): DSAttentionFused + IndexShare helpers + the GLM fused-attention spec builder, importing shared primitives from dsa/dsa_kernels. - glm_absorbed_mla.py (new): GlmAbsorbedMLASelfAttention, folding the LoRA adapter into the kv up-projection effective weight via a _kv_up_proj_weight override. - dsa.py: DSAttentionFused + helpers removed (now byte-identical to base). - transformer_config.py: only the two IndexShare fields remain, declared so the GLM bridge's values survive the provider->config conversion. - absorbed_mla.py: _effective_kv_up_weight replaced by a minimal _kv_up_proj_weight seam. - module_specs.py: GLM fused branch -> build_glm_dsa_fused_attention_spec. Validated on 4xB200: 65k forward-backward PP16/EP2 loss=0.5747 (warmup 1.088 matches pre-refactor 1.089). Signed-off-by: Paras Stefanopoulos <paras@parsed.com> * build(dsa): pin nvidia-cudnn-frontend[cutedsl]>=1.25.0 The fused DSA path imports the cuDNN-frontend DSA namespace (cudnn.DSA.*), which is only present in nvidia-cudnn-frontend>=1.25.0 with the cutedsl extra; 1.24.x ships NSA but not DSA. The previous unpinned spec resolved to 1.24.0, silently breaking the fused GLM-5.2 attention kernels at import time. Validated end-to-end on a 5-node B200 cluster: full forward/backward, optimizer steps, LoRA weight-sync, and sampling on the fused DSA path (apply_dsa_kernel_fusion=True). uv.lock regenerated with uv 0.8.22; dev extra now resolves cudnn-frontend 1.25.0 plus the cutedsl transitive deps (nvidia-cutlass-dsl 4.5.0, torch-c-dlpack-ext), lts extra unchanged (no DSA). Signed-off-by: Paras Stefanopoulos <paras@parsed.com> * build(dsa): point flash_mla source at FlashMLA nv_dev (sparse fwd) The fused GLM-5.2 DSA path imports flash_mla_sparse_fwd, which only exists on FlashMLA's nv_dev branch. The previous rev (9edee0c, main) imports but lacks that symbol, so the trainer crashes at the first DSA sparse forward with ImportError. Point the source at nv_dev (b7643bd5). (This [tool.uv.sources] entry is the source of truth; the deployed trainer image vendors a prebuilt nv_dev wheel built with nvcc>=12.9 for sm100 — see basetenlabs/trainers server pyproject.) Signed-off-by: Paras Stefanopoulos <paras@parsed.com> * Use declared IndexShare config fields Signed-off-by: Paras Stefanopoulos <paras@parsed.com> --------- Signed-off-by: Paras Stefanopoulos <paras@parsed.com>
… linear dgrad
For a 3D grad_output, .matmul(weight) can be dispatched to a batched-GEMM
whose strideA argument is stored as int32 in the cuBLAS API. When
grad_output is a non-contiguous view (e.g. Megatron's standard [s, b, h]
layout on a [b, s, h]-contiguous storage), torch cannot collapse it to
2D without a copy and falls back to bmm. At long sequence and large
out-per-partition the resulting strideA = seq_len * out_per_partition
exceeds INT32_MAX and cuBLAS raises:
RuntimeError: at::cuda::blas::bgemm<at::BFloat16> argument ldb must
be positive and less than 2147483647 but got 2860646400
Repro: a frozen LM head under LoRA at seq=46080, vocab=248320, TP=4
(strideA = 46080 * 62080 = 2,860,646,400 > 2^31 - 1).
Flatten the leading dims into the M axis before the matmul so torch
routes through a single regular GEMM. The common Megatron-layout case
recovers the underlying [b, s, h]-contiguous view via a free
.transpose(0, 1) and the subsequent reshape becomes a pure view; for
any other 3D non-contiguous layout, fall back to an explicit reshape
that calls .contiguous() internally. The 2D path is unchanged.
Adds tests/unit_tests/tensor_parallel/test_layers.py
::test_LinearWithFrozenWeight_3d_non_contiguous_grad_output to defend
the dispatch path (the overflow itself only fires at sizes too large
for unit-test memory budgets; the test exercises the new code path at
small sizes against the same non-contiguous layout shape).
Signed-off-by: Kimbrian <kimbrian@parsed.com>
…fig (#6) GLM-5.2 declares indexer_rope_interleave: true (GPT-J interleaved rope in the DSA indexer; vLLM reads it as is_neox_style = not flag). The indexer's _apply_rope hardcoded the DeepSeek-V3.2 convention (non-interleaved), so the trainer scored its indexer on differently-rotated q/k than serving engines. Top-k selections still overlap at small candidate pools but diverge progressively with sequence length: measured trainer<->vLLM per-token logprob KL grows 0.010 -> 0.084 between 9k and 15k tokens, making long-context RL unusable. With the convention plumbed (dsa_indexer_rope_interleave, set by the GLM bridge from the checkpoint config), the same probe measures 0.009 at 15k — flat in length, zero systematic bias. Default False preserves DeepSeek-V3.2 behavior exactly.
…IA#5087) into trainers-main Brings in the dsv4-next stack the GLM-5.2 131k CP work builds on, most importantly kunlunl's DeepSeek-v4 Context Parallel support (NVIDIA#5087), plus THD packed-sequence support for DSv4 hybrid attention and related DSA fixes. Conflict resolution (pyproject.toml / uv.lock): take upstream's changes (flash-linear-attention>=0.4.2, flash_mla in no_pypi_wheels + no-build-isolation, cudnn-frontend git source pin, fusions coverage omit) but re-apply the two intentional Baseten deviations that a wholesale upstream take would have reverted: - nvidia-cudnn-frontend[cutedsl]>=1.25.0 version floor - FlashMLA pinned to commit b7643bd (not the floating nv_dev ref) with the comment explaining why the fused GLM-5.2 DSA path needs it. nv_dev already resolved to b7643bd in the lock, so the pinned commit is identical to what the branch was tested against; only the requested-rev label changed. Verified with 'uv lock --locked'. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
b187cf3 to
745c7e3
Compare
…n-next - free the per-layer ~4GiB mHC boundary in backward (release offload interface self.tensor on __exit__ + null variant-2 mlp_norm_manager, mirroring variant-1) [was 0623fdc] - in-place 3-way grad sum in BroadcastTensorFused.backward instead of allocating a fresh n-stream residual grad per layer [was b8c3bc3] Validated on the previous pin at 131k (v23: 2x fb+optim, no OOM). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186sfkoXA7xwj65U82bEZ3Y
- chunked Triton indexer scorer (_dsa_indexer_score_kernel + _chunked_indexer_topk_bshd, int64-hardened): frozen-indexer top-k without materializing the O(seq^2) dense score (32 GiB at 131k). Wired into indexer_topk and FusedIndexerSparseAttnFunc for the SBHD mb=1 frozen path only; THD/CP inputs keep the new _indexer_topk_core path (their per-rank local sq is already sharded by CP). Frozen path now also skips the step-5 loss derivation entirely (indexer_scores is not computed). DSV4_INDEXER_QBLOCK env controls the chunk (def 4096). - MoE dispatcher forward-state clear after combine (~437 MB/layer at 131k held into backward otherwise) [was 0644539/2c78e5728] - GLU linear-offset skip when glu_linear_offset==0 (saves a GLU-sized ~1.5-3 GiB alloc per layer at 131k) [was 0644539] Ports the validated jerry/131k stack (v14/v23) minus what upstream already has (RoPE int64 + split recompute = c9df1b4, int32 stride fix = 429df69, NCCL chunking dropped as obsolete on NCCL>=2.28). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186sfkoXA7xwj65U82bEZ3Y
…ention - glm_dsa_fused: THD contiguous-CP forward — autograd CP all-gather of the compressed latent KV (bwd reduce-scatters dKV), non-autograd gather of the frozen indexer's K rows, per-rank top-k against global KV via csa_cp_utils.compute_cp_indexer_topk (ratio=1) with q_causal_offsets, flat lowering via build_flat_topk_idxs THD, FlashMLA/cuDNN sparse attention unchanged. IndexShare holders store (topk, layout) per computing layer. - rope_utils: contiguous branch in _apply_rotary_pos_emb_thd (positions from GLOBAL cu_seqlens over this rank's contiguous packed-row interval), keyed on config.cp_partition_mode; zigzag path untouched. - absorbed_mla: pass max_seqlen=rotary_seq_len to the unfused THD RoPE calls (required by _apply_rotary_pos_emb_thd's packed-freqs detection). - transformer_config: allow 'dsa' alongside 'dsv4_hybrid' for cp_partition_mode='contiguous' + sequence_packing_scheduler validation. - CP1 fix needed even without CP: the re-layered GLM commit still passed seqlen_kv to build_flat_topk_idxs, which the PR#5087 rewrite no longer accepts (masking moved into indexer_topk); SBHD semantics unchanged. - size the CP indexer rope table by the global PADDED row count (scoped via pg_collection.cp) and clamp positions: max_seqlen_q is the max over REAL datum lengths while positions come from the padded cu_seqlens layout, so capacity-padding rows indexed past the table (OOB gather device assert); overflow rows are padding. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Jack Rao <jack.rao@baseten.co>
745c7e3 to
c37526e
Compare
|
Closing — superseded by the upstream fused DSA+CP in |
Purpose
One diff against
trainers-mainshowing every Megatron-LM change needed for GLM-5.2 131k CP. Retargeted fromtrainers-main-next-dsv4per Jack — the diff therefore includes that whole line (not just my commits), because 131k needs it:trainers-main-next-dsv4(the newer NVIDIA-dev base): upstream PR [dev] [DeepSeek-v4] Context Parallel support NVIDIA/Megatron-LM#5087 (DSv4 context-parallel machinery —csa_cp_utils,q_causal_offsetsthrough the DSA indexer kernels,cp_partition_mode='contiguous'), THD packed sequences ([dev] [DeepSeek-v4] Packed Sequence (THD) support for DSv4 Hybrid Attention NVIDIA/Megatron-LM#5011), the GLM-5.2 fused frozen-indexer commit re-layered, RoPE int64/split-recompute, mHC leak fixes, 131k memory hardening. These are jerry's/upstream's — listed here for visibility, authorship in the commits.jackrao/glm-dsa-cp, the last 4 commits):glm_dsa_fused.py_forward_thd_cp: autograd CP all-gather of the compressed latent KV (bwd reduce-scatters dKV), non-autograd gather of the frozen indexer's K rows, per-rank top-k against global KV viacompute_cp_indexer_topk(ratio=1) + THD flat-index lowering; FlashMLA/cuDNN sparse attention unchanged; IndexShare holders store (topk, layout).rope_utils.py: contiguous branch in_apply_rotary_pos_emb_thd(positions from GLOBAL cu_seqlens over each rank's contiguous packed-row interval); zigzag untouched;absorbed_mlamax_seqlen plumb.transformer_config.py: allowdsaalongsidedsv4_hybridfor contiguous CP validation.build_flat_topk_idxs(seqlen_kv=...)signature — GLM died at warmup on this line before this fix. Plus indexer rope-table sizing by padded length (OOB gather device-assert otherwise).Validation
Debug GLM: CP1-vs-CP2 loss parity 0.03%, per-rank peak shards 2.33 → 1.70 GiB. Full GLM-5.2-FP8, 4×8 B200, TP1/PP1/EP32/CP32: 131 072-token LoRA-SFT fwd-bwd at 98.2 GiB peak-alloc / 138.2 GiB hottest used, ~56 s/fb, memory fit R²=0.999 over 6 points.
Caveats: fb/memory validated; real-data parity + convergence pending; CE-only v1; ~1e-3 forward jitter at CP2 (nondeterministic kernel in the gather/FlashMLA path).
Companions: basetenlabs/trainers#592, basetenlabs/Megatron-Bridge#12.
🤖 Generated with Claude Code