Repository navigation
[Feat] [RUBIN] glm5_3/sm107: GLM-5.2 TP16 bs=1 megakernels and EAGLE v2 step CUDA graph (spec_step) - #19
Merged
Conversation
…extN draft; EAGLE v2 step CUDA graph - glm_dsa: target verify (4-16 rows) and NextN draft/draft-extend megakernel specs for GlmMoeDsaForCausalLM on SM103 and SM107 (TP8, NVFP4 MoE). - spec_step: one CUDA graph per EAGLE v2 topk-1 decode step plus bitwise- identical spec fusions, installed via HookRegistry behind env switches.
… importable - hooks.py: torch 2.14's `_CUDAGraph` binding reads `keep_graph` in `__init__`, so overriding only `__new__` let a bare `torch.cuda.CUDAGraph()` drop its raw graph at capture end, and decode graph capture failed in cuGraphInstantiate with CUDA_ERROR_INVALID_VALUE. - lifted.py: defer annotations. `Tuple`, `Optional` and `torch` are bound only in the SGLang module each function is rebound into, so the first verify raised `NameError: Tuple`. - lifted.py: `eagle_sample` drops its inline sampler imports, which referenced `_is_npu` (removed from eagle_utils by sgl-project/sglang#45504), and uses eagle_utils' module names. - lifted.py: `_draft_extend_for_decode` passes `sampling_seed=` and `positions=` again, as current SGLang does. Tested on 8x B300, GLM-5.3-NVFP4, TP8, EAGLE 3/1/4, SGLang f4a2df3dac, all spec_step switches on.
The construction check compared the raw server argument with EAGLE, so a NEXTN launch (the InferenceX GLM-5.3 B300 AgentX recipe) was refused with "speculative algorithm 'NEXTN' is not supported (EAGLE / NEXTN only)". NEXTN resolves to the same EAGLE worker; the spec's requirement and the spec_step runner already accept it.
[Fix] glm_dsa, spec_step: fix the plugin path on SGLang main
…p scheduling switches Split the GLM-5 DSA verify path into the attention/, boundary/, moe/ and runtime/ packages plus plan.py (runtime.py kept as runtime_legacy.py), and fix two leftovers of the split: a stray @DataClass in moe/__init__.py and a duplicated module header in boundary/__init__.py. The spec's model_disable_reasons now calls eligibility.model_construction_reasons with the HF config and the server arguments. Port two hop scheduling ideas from the TRT-LLM Rubin round-7 branch, both off by default and output-neutral: - SGLANG_NVIDIA_MEGAKERNEL_GLM_HOP_MAX_SHARED_CARVEOUT=1: every hop kernel prefers the maximum shared-memory carveout, so an SM a hop CTA lingers on can host the next layer's large-shared-memory kernels under PDL. - SGLANG_NVIDIA_MEGAKERNEL_GLM_HOP_CTAS_PER_SM=1|2: pad the o_proj consumer hop's launch shared memory (sized from the device's per-SM limits) so at most N CTAs share an SM while polling. Round 7's single-loop 16-slot polling does not apply: at 8 ranks the consumer already polls all sources in parallel. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Port sgl-project#24's 5 / 1 / 6 support (3889557, 492aa0a, 77015e7) to the GLM-5 DSA specs, which served speculative_num_draft_tokens 4 / speculative_num_steps 3 only. - eligibility: SERVED_TOKENS_PER_REQUEST = (4, 6) and MAX_ROWS = 16; supported_rows(T) gives every whole number of requests up to 16 rows (T 4: 4 / 8 / 12 / 16, T 6: 6 / 12). The executor builds only the widths of the server's speculative_num_draft_tokens; the spec and Tier 1 refuse any other value or a pair with draft tokens != steps + 1, naming 4 / 3 and 6 / 5. - MoE: moe_split groups rows by 4 with the remainder last (6 -> (4, 2) on the two-group engine, 12 -> (4, 4, 4) on the four-group engine). - Draft: the eh_proj shard rows are the draft decode's 1-4 plus the covered widths (T 6: 1, 2, 3, 4, 6, 12). - One request at 6 rows keeps the fast forms: split MoE fold hop (SPLIT_MAX_ROWS 6), plain hops on dense layers (DENSE_MAX_ROWS 6) and the 16-warp sparse MLA up to 6 rows. Kernels unchanged. At T 4 every width, row map, eh row set and kernel form is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Takes SGLang megakernel API version 2 and the plugin interface's new location (sglang.kernels.plugin_kernels.nvidia). Conflicts: CODEOWNERS, README's model table and plugin.SPECS keep both sides' entries; test_contract keeps one _files. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- spec, draft_spec: API_VERSION 2; the built objects offer no EAGLE entries or graph variants (draft_loop, draft_extend, begin_draft_round, graph_variants are None). Restore the target's _Built (widths, summary, plan, forward), which the package split had dropped, so build returns a BuiltMegakernel again. - spec: accept Feature.MULTI_NODE_TP, so TP8 can span the two 4-GPU trays of an NVL72 rack, as the draft spec already does. - spec: drop the DsaView binding-member and EAGLE_DRAFT_CAPTURE_CHECK gates, which only an unmerged SGLang (sgl-project/sglang#46210) passes; the covered step reads the DSA backend through get_attn_backend() and never through those views. - attention: build the AttentionGlue directly (it has no build classmethod). - draft_spec: import the megakernel interface from its new location first. - glm_dsa, spec_step: declare every SGLang import in SGLANG_READS (the stricter contract test); import modules as modules (import a.b.c as c); name reads by the file that defines them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… fields draft_spec gets ARCHITECTURE and pins the fused draft layer's attention shapes and model_type (Requirements.hf_config), as test/unit/test_glm_dsa_config.py expects: a NextN config that differs in one of them is refused at load, naming it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- draft.py: read TARGET / tp_gather / per_rank from runtime.executor; runtime is now a package and no longer exports them. - attention/step.py, moe/step.py: restore @DataClass on StepContext and MoeRecords (capture failed with "StepContext() takes no arguments"). - moe/step.py, moe/__init__.py: import the shape constants, HIDDEN and MoeGlue where they are used; moe/__init__ re-exports from moe.step. - draft_attention.py: import AttentionGlue / FusedAttention / kernel_rows from attention.fused. Verified on two Rubin trays (TP8, --nnodes 2, dummy weights): the fused verify routes the decode graphs at 4/3/1 (bs 1-4) and 6/5/1 (bs 1-2), generate requests succeed; unit tests 582 passed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
wenscarl
added a commit
to nvrohanv/sgl-nvidia-mega
that referenced
this pull request
Nov 4, 2026
…ithout NVLink multicast Port the Rubin pieces of sgl-project#19 (glm_dsa) to the GLM-5.3 / GLM-5.2 specs. The kernels are the same; only the admission changes. - spec, draft: admit sm_107 (Rubin / VR NVL72) next to sm_103. The draft takes the target's ISAs. - spec, draft: declare Feature.MULTI_NODE_TP, so TP8 can span the two 4-GPU trays of an NVL72 rack (GB300 NVL72, Rubin VR NVL72), as the Qwen3.5 and Kimi K3 specs do. - runtime: SGLANG_NVIDIA_MEGAKERNEL_GLM_ALLOW_NO_AR_FUSION=1 (off by default) lets the model check and the per-step coverage pass where SGLang's FlashInfer all-reduce + RMSNorm fusion does not apply (no NVLink multicast). The stock residual steps then run SGLang's unfused all-reduce, which is what its boundaries run there, and slot hops runs its own symmetric-memory all-reduce. Without the variable nothing changes. - README: the GPUs and the two-tray launch. test/unit/test_glm5_3_rubin.py covers the three changes on CPU. Co-Authored-By: Claude Opus 5.5 <[email protected]>
YAMY1234
added a commit
that referenced
this pull request
Nov 10, 2026
… NVFP4 MTP target verify and NextN draft (#24) * [Feat] [B300] glm5_3: NVIDIA megakernel specs for GLM-5.3 NVFP4 MTP target verify and NextN draft on B300 TP8 Add sgl_nvidia_mega/glm5_3: the GLM-5.3 target spec for SGLang's megakernel layer (MTP verify steps of 1 to 4 requests, 4 to 16 rows, on 8 x B300 at TP 8), its step functions with stock paths adapted from SGLang's model code, and the CuTe DSL attention, small-M NVFP4 MoE and all-reduce hop kernels. With --enable-nvidia-megakernel every target slot runs (attention, moe, hops, qkv_a_small_m_shared, dnorm); SGLANG_NVIDIA_MEGAKERNEL_SLOTS is a test and bisect override. Needs SGLang's DSA binding view. Add the GlmMoeDsaForCausalLMNextN draft spec (slot draft, on by default) and its CuTe DSL kernels: the embedding gather and eh norms in one kernel, the column-sharded eh projection gathered by the target's all-reduce hop, the distributed top-1, and the draft layer's MLA prologue, in every captured draft graph. Needs embedding replication (with the flag, SGLang's megakernel layer sets SGLANG_ENABLE_EMBED_REPLICATION when it is unset), greedy draft acceptance and SGLang's EAGLE draft graph capture check; the contract test skips the check's marker, naming it, on an SGLang without it. At startup rank 0 logs the covered verify widths (1-4 requests) and the derived weight copies' memory per GPU, and warns when --max-running-requests is set above 8, where the megakernel helps little. Also the README section, a NOTICE paragraph, a CODEOWNERS line and the contract test's checks of the DSA binding view reads and the mirrored SGLang code; the GLM-5.3 tests are filed separately. The same specs serve GLM-5.2 NVFP4, which has GLM-5.3's architecture (GlmMoeDsaForCausalLM) and the same value of every config field the target and draft specs pin. The spec names and the plugin's log, refusal and rank agreement texts name both models, and the module path stays glm5_3. test/unit/test_glm5_3_glm5_2_config.py runs the published config of nvidia/GLM-5.2-NVFP4 (revision 53e0691e21895a3863a606dfd12910c69eba94ab) through SGLang's requirement check for both specs, and checks that a config that differs in any pinned value, or lacks one, is still refused. The package imports SGLang's megakernel interface from its location since sgl-project/sglang#45389 (sglang.kernels.plugin_kernels.nvidia, sglang.srt.kernel_plugins.nvidia) and falls back to sglang.srt.megakernels on an older SGLang, as deepseek_v41 does. * docs: correct GLM GPU test availability * [Feat] [B300] glm5_3: serve MTP with 5 draft steps (6 verify rows a request) The GLM-5.3 / GLM-5.2 specs served MTP / EAGLE with 3 draft steps only, so the 5 / 1 / 6 setup of SGLang's GLM-5.3 and GLM-5.2 B300 NVFP4 low-latency recipes stopped at startup with --enable-nvidia-megakernel. The verify widths, the MoE row map and the draft eh rows are now derived from the verify rows a request T (speculative_num_draft_tokens = speculative_num_steps + 1, top-1 drafts), and the specs serve the tested values 4 and 6 (plan.SERVED_TOKENS_PER_REQUEST); any other value is refused at startup, naming them. - Widths: every whole number of requests up to the kernels' 16 rows (plan.supported_rows): 4 / 8 / 12 / 16 rows at T 4 as before, 6 / 12 rows (1-2 requests) at T 6. Steps of more requests run SGLang's path. - MoE: the engine takes at most 4 row groups of at most 4 rows, token sets over one expert list rather than requests. moe_split groups the rows by 4 with the remainder last: T 4 keeps (4,) to (4, 4, 4, 4); 6 rows run on the two-group engine as (4, 2) and 12 rows on the four-group engine as (4, 4, 4). The one-group engine holds 4 rows, so it cannot take 6. - Draft: the eh_proj shard serves the draft decode's 1-4 rows and the draft extend at the covered widths, so T 4 keeps its rows and T 6 adds 6; remove the unused max_requests. - Attention, the hops and the draft attention already take any row count up to 16 on their 8- and 16-row forms; no kernel changes. At T 4 every width, row map, eh row set and kernel form is unchanged. * [Perf] [B300] glm5_3: the one-request fast forms at 6 verify rows With 5 draft steps a one-request verify step has 6 rows, past the 4-row limit of the forms that serve one request of 3 draft steps. Serve them at up to 6 rows: - the split MoE fold hop (SPLIT_MAX_ROWS 6; still taken only where the cooperative occupancy holds 2 x rows + 1 clusters of 8 CTAs, probed at build); - the plain all-reduce hops on the dense layers (DENSE_MAX_ROWS 6); - the 16-warp sparse MLA (one CTA per SM; its kernel already takes any row count and gives the 8-warp form's bytes). No width of 4 verify rows a request has 5 or 6 rows, so those steps keep their forms. The kernels are unchanged. * docs: glm5_3 MoE groups and eh_proj rows with 6 draft tokens The README's GLM-5.3 slot table named the MoE engine forms by requests and listed the eh_proj rows of 4 draft tokens only. Name the forms by row groups (6 rows run as 4 + 2, 12 as 4 + 4 + 4) and add the eh_proj rows of 6 draft tokens (6 and 12). * [Fix] glm5_3: pin the SGLang mirrors with main's mirror digest Main's SGLANG_MIRRORS check (#20) digests a function's tokens in another encoding than this branch's copy, which the merge replaced with main's. Pin the 18 GLM-5.3 mirrors with main's mirror_digest of the same SGLang code: no mirrored body changes, only how its digest is written. * [Fix] glm5_3: re-pin four SGLang mirrors for current SGLang main Four mirrored SGLang bodies changed on SGLang main. Each pin is now a tuple of the digests before and after the change, so the check passes on either SGLang: - DeepseekMLAForwardMixin.forward_absorb_prepare (sgl-project/sglang#46359): every changed line is on the --dcp-replicate-q-proj path, which runs only with decode context parallelism; the specs refuse it, and the stock attention step does not copy those lines. - DeepseekSparseAttnBackend._forward_trtllm (sgl-project/sglang#46990): the KV store and read go through the pool's layer router; on the DSA pool, a plain pool, that is the same set_mla_kv_buffer and get_key_buffer call with the same arguments, which the stock step makes. - DeepseekSparseAttnBackend.forward_decode: sgl-project/sglang#46990 as above, and sgl-project/sglang#44322, a triton branch for ROCm with decode context parallelism. - LogitsProcessor.forward (sgl-project/sglang#43449): the new lines run only with --enable-return-aux-hidden-states, which turns speculative decoding off, so never with the NextN draft; the output's new last_hidden_states stays None. The copied steps stay as they are. The other 14 mirrored bodies are unchanged on SGLang main. * [Fix] glm5_3: adapt the specs to SGLang's megakernel API version 2 SGLang main's megakernel contract is version 2: a built object may also offer the EAGLE entries draft_loop, draft_extend and begin_draft_round and attention graph_variants, which SGLang reads from every built object. The GLM-5.3 / GLM-5.2 target and draft built objects offer none of them (None: SGLang's own path, as before), and the specs declare API version 2, as main's DeepSeek-V4.1 and Qwen3.5 specs do. * docs: glm5_3 boundary docstring says plain dense hops up to 6 rows DENSE_MAX_ROWS is 6 since the 5-draft-step change; the module docstring still said 4. * test: glm5_3 pins the forward_mla mirrors after sglang#45946 sgl-project/sglang#45946 adds SAIL-only fp8 conditions to forward_absorb_prepare / forward_absorb_core and a FlashMLA-backend-only llama_4_scaling step to forward_absorb_prepare; the DSA path the spec serves is unchanged. Pin the new digests next to the old ones. * [Feat] [Rubin] glm5_3: serve SM107, TP8 across two trays, and nodes without NVLink multicast Port the Rubin pieces of #19 (glm_dsa) to the GLM-5.3 / GLM-5.2 specs. The kernels are the same; only the admission changes. - spec, draft: admit sm_107 (Rubin / VR NVL72) next to sm_103. The draft takes the target's ISAs. - spec, draft: declare Feature.MULTI_NODE_TP, so TP8 can span the two 4-GPU trays of an NVL72 rack (GB300 NVL72, Rubin VR NVL72), as the Qwen3.5 and Kimi K3 specs do. - runtime: SGLANG_NVIDIA_MEGAKERNEL_GLM_ALLOW_NO_AR_FUSION=1 (off by default) lets the model check and the per-step coverage pass where SGLang's FlashInfer all-reduce + RMSNorm fusion does not apply (no NVLink multicast). The stock residual steps then run SGLang's unfused all-reduce, which is what its boundaries run there, and slot hops runs its own symmetric-memory all-reduce. Without the variable nothing changes. - README: the GPUs and the two-tray launch. test/unit/test_glm5_3_rubin.py covers the three changes on CPU. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Perf] [GB300] glm5_3: Run the NextN draft-extend MLP on the select_index rows only The draft extend runs the NextN layer on every verify row of each request, but the next draft step reads only the select_index row (one per request); the logits processor already prunes to those rows before the LM head. After the post-attention norm the draft step now keeps those rows of the MLP input and of the residual SGLang's prepare wrote, so the MoE, its all-reduce and the final norm run on B rows instead of B * tokens (6 -> 1 and 12 -> 2 rows at EAGLE 5/1/6). The attention still writes every row's KV and indexer key. The hidden states handed to the logits then hold only the selected rows, with a LogitsMetadata that does not select again. - Slot draft_rowselect (shipped, a draft slot, needs slot draft). - Gate (draft_step.select_index_rows): DRAFT_EXTEND_V2, no logprobs, hidden capture not FULL, no padded-row mask, a 1-D select_index with 0 < B < N rows; the NextN MLP is DeepseekV2MoE without an all-to-all. Host-only facts, fixed per captured shape. draft_attention.select_rows raises on any other stream layout. - draft_attention.decoder_layer_forward takes the rows to keep (ffn_rows) and, at a width the draft attention family does not serve, SGLang's own attention call. - Rank 0 logs once per captured draft graph its attention and MLP rows. Numerics: the selection itself is exact (the kept rows equal the full-row stream's rows bit for bit through SGLang's residual stream and final add + RMSNorm). The draft MoE and its router pick their kernels by the row count, so the MLP output on B rows is not bit-identical to the same rows of the N-row run (draft.rowselect.mlp.* in the draft NUMERICS). Draft-only: target verification decides every emitted token. Tests: test/unit/test_glm5_3_draft_rowselect.py (CPU; the logits hand-off needs CUDA), test/kernels/test_glm5_3_draft_rowselect.py (4 GPUs). Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Feat] glm5_3: TP4 profiles, verify steps composed per width from kernel units The spec serves TP8 at 4 or 6 tokens per request up to 16 rows. It now also accepts TP4 at 3 to 6 tokens per request up to 48 rows (one GB300 tray: the InferenceX AgentX TP4 aggregate and PD decode-role configurations), and serves those widths with kernel units composed per step; the TP8 path (plan.build_providers, the executor, the families) is unchanged. - profile.py: the facts a build is decided on (TP, heads per rank, tokens per request, widths, device, features) and the accepted table: the TP8 envelope (plan.py) plus TP4 at 3-6 tokens, 48 rows. Profile.units says which build runs. - registry.py: candidates claim steps of a group atomically, with coverage per (profile, rows, mode) and contract tokens; per width the first preferred, switched-on, covering unit takes each step, the rest run the stock body. A decline (coverage) runs stock and is logged once per width; a family that covers a width but fails to build raises on every rank. A mixed group is a subclass of the stock group with the claimed steps bound to their units, so the stock step bodies and Providers.describe see them. - units.py: the TP4 preference table. Every unit is a slot (runtime.LL_SLOTS, shipped; OPT_IN_SLOTS only when listed), selected by SGLANG_NVIDIA_MEGAKERNEL_SLOTS as the TP8 families are; "" is parity (every accepted width on the stock bodies). - runtime/composed.py: the executor (GlmMegakernelVerify: its layer loop, first-capture checks and parity switch) on the composed step groups; its logits take ll.gemm's lm_head role and share the model processor's gatherer. runtime.build hands a TP4 profile to it. - spec.py: tp_sizes {4, 8}, the (TP, tokens) pairing checked against the profile table (profile_reasons), max_rows 48, the units' named tolerances. - ll/__init__.py, ll/jit.py: the units' package (optional modules, the ll.linear GEMM entry point, named tolerances) and the JIT loader for its .cuh kernels (SGLang's load_jit; refuses to compile under capture; failures raise). Tests: test/unit/test_glm5_3_{profile,registry,spec,ll_jit,verify_logits}.py. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Perf] [GB300] glm5_3: TP4 small-M BF16 GEMMs on PDL split-K and TGV (ll.gemm) The TP4 roles' small-M BF16 GEMMs that SGLang leaves on cuBLAS launch without programmatic dependent launch. ll.gemm moves them, at the row counts where a GB300 crossover bench measured a win in the GEMM's model context, to a PDL kernel (slot ll.gemm.<role> each): - router (FP32 logits): split-K at 17-96 rows (the tiny GEMM keeps <= 16); - indexer wk|weights_proj: split-K at 1-64 rows; - o_proj TP4: TGV 1-72; dense_down TP4: TGV 1-48; NextN eh_proj: TGV; - lm_head TP4: TGV 1-60; measured but deferred (run only when listed): the TP8 o_proj / q_b shapes. gemm_plan.py holds the plan and the named tolerances. The plan applies only on SM103 with 152 SMs; elsewhere, and for quantized or biased weights or unplanned rows, every role runs SGLang's own GEMM for the module, bit for bit. Split-K is a vendored copy of FlashInfer v0.7.2's cluster split-K kernel with FP32 output / any M and synchronization fixes (owner wait at .acquire.cluster, phase-0 wait before the TMEM release, tcgen05 thread-sync fences; no arithmetic change). FlashInfer's own kernel is used only when it carries those fixes (SplitKTactic.SYNC_FIXED); SGLANG_NVIDIA_MEGAKERNEL_GLM_GEMM_SPLITK pins auto / flashinfer / vendored. TGV is SGLang's cutedsl_bf16_gemm. Tests: test/unit/test_glm5_3_ll_gemm_plan.py (CPU: tactics, engagement only on SM103 / 152 SMs, slots, FlashInfer detection, stock dispatch); test/kernels/test_glm5_3_ll_gemm.py (1 GPU: path per role and row, tolerances vs cuBLAS and FP64, graph replay, PDL edges, launch stress). benchmark/bench_glm5_3_ll_gemm.py re-checks the crossover. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Perf] [GB300] glm5_3: TP4 sparse MLA flash decode as unit ll.sparse_mla_fd The sparse_mla and uv_proj steps of the TP4 verify attention and of the NextN draft layer's attention on a flash-decoding CUDA kernel over the top-k gathered FP8 KV rows, instead of TRTLLM-Gen's sparse MLA decode + torch.bmm. The step reads the running forward's ForwardView (view.dsa, view.kv_pool, view.metadata), as the stock step does. - Kernels (ll/csrc/attention/glm_sparse_mla_fd_*.cuh, adapted from TensorRT-LLM's sparse MLA flash decode): one 16-CTA cluster per row, 8 or 16 heads; a v_b fold instance (8 heads, bitwise cuBLAS's BMM); a multi-tile mode (clusters of 2-8 CTAs, 8 heads). - Launch plan (GB300, 152 SMs): one-tile up to 7 rows; built at compile; the co-resident cluster counts are agreed over the TP group (MIN); a build failure on any rank raises on every rank. - Covers sm_103 with 152 SMs, 16 heads (TP4), <= 7 rows; declines with TRTLLM-Gen skip-softmax decode on. - Tolerance ll.sparse_mla_fd.max_abs = 0.0625 against TRTLLM-Gen (measured 0.052 / 0.055 at 8 / 16 heads). 16 heads: -2.1 to -2.8 us per layer at 5 / 6 rows (benchmark/bench_glm5_3_sparse_mla.py). Tests: numerics vs TRTLLM-Gen and an FP64 oracle, the provider steps vs the stock steps, CUDA-graph replay and the PDL chain (1 GPU); the launch plan and rank agreement (CPU). Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Perf] [GB300] glm5_3: TP4 attention front on low-latency fused-A and a one-launch MLA KV half The unit ll.attention (groups attention and draft_attention) serves the attention front of a TP4 rank (16 heads, SM103, 1-48 rows, every step mode) by claiming qkv_a / prologue / index_k / rope_cache of AttentionStep: - qkv_a: SGLang's min-latency fused-A kernel with a larger stage ring and a pipelined MMA loop from 9 rows, up to 16 rows (bit for bit SGLang's kernel); a split-K form at 17-24 rows when one wave fits (ll.attention.qkv_a_wide.max_rel of fp32); stock above 24 rows. - prologue: stock q_a norm; q_b on the pipelined form at 9-16 rows (bitwise); the kv_a norm deferred into rope_cache when folded. - index_k: the stock body with its key / head-gate projection through ll.linear("wk_weights_proj"). - rope_cache: one PDL launch for the kv_a norm (folded), RoPE and FP8 of q and k and the MLA cache append, bit for bit FlashInfer's norm and mla_rope_quantize_fp8 and SGLang's set_mla_kv_buffer (the cache through the step's ForwardView). The fold (slot ll.attention.kv_norm_fold) engages only when FlashInfer's norm backend, read from its public surface, is CuTe DSL and a probe at build gives the stock kv_a norm's bits; the family logs which way it went. fused_a_ll.cuh is adapted from SGLang's dsv3_fused_a_gemm.cuh. Tests (1 GPU): fused-A forms bitwise at 1-16 rows and within tolerance at 17-24, graph replay; the KV half bitwise (q and every cache byte); the stock AttentionStep vs ll.attention on one TP4 layer at 5-48 rows, eager and replayed. CPU: the norm-backend decision, coverage and composition. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Perf] [GB300] glm5_3: TP4 all-reduce + residual + RMSNorm hops on a plugin-owned Lamport buffer The unit ll.hops serves the three hop steps (HopSteps) of the TP4 verify step: - csrc/distributed/glm_ll_mnnvl_oneshot.cuh: one-shot / two-shot MNNVL all-reduce + residual + RMSNorm with a MoE-finalize prologue and an NVFP4 epilogue (builds with nvcc 13.0 and 13.4). Every wait on a peer is bounded: past the deadline it writes a host-mapped error record and traps (fail-stop). - ll/transport.py: the Lamport buffer and flags are the plugin's own (torch symmetric memory, or FlashInfer's McastGPUBuffer) in FlashInfer's MNNVL layout; no FlashInfer workspace or flags are shared. Modules load through ll.jit; a build failure raises on every rank. - ll/hops.py: the GB300 launch plan per world size and row count (W=4: one-shot up to 36 rows, two-shot 37-48), the family (deadline min(20 s, the build context's), o_proj through ll.linear) and its step group. Covers the TP4 verify step on sm_103 up to 48 rows; provides hops:finalize and mlp_input:nvfp4 (written only when a taken MLP unit consumes it). Tests: the plan tables (CPU); at W=4 every row 1-48 bit-identical to FlashInfer's one-shot / two-shot, the finalize hop bit-identical to moe_finalize_fuse_shared + the hop, a protocol mix eager and in a CUDA graph; fail-stop of every cross-GPU wait; a two-tray multicast probe. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Perf] [GB300] glm5_3: TP4 MoE and dense MLP steps with the deferred finalize (ll.moe) The units ll.moe.nvfp4 and ll.moe serve the MLP step (MlpSteps) of the TP4 verify step and leave the MoE finalize to the next hop: - MoE layers: the router GEMM (ll.linear("router"), FP32 logits), then FlashInfer's public trtllm_fp4_block_scale_moe with do_finalize=False and the layer's processed NVFP4 weights (SGLang's fused_experts_none_to_flashinfer_trtllm_fp4 call for this configuration), and the shared expert on the layer's alternate stream; returns a deferred finalize for the next hop. - ll.moe.nvfp4 takes the routed experts' FC1 input from the post-attention hop's NVFP4 epilogue; ll.moe quantizes its own input. - Dense layers: the stock gate_up_proj and SiLU-and-mul, then ll.linear("dense_down"), un-reduced. - Opt-in slot ll.moe.alt_stream_priority: the shared expert on a stream of the greatest priority at <= 6 rows. It gains only with FlashInfer's small-batch routing kernel (TP4 5/1/6: -1.82% step at 6 rows); on stock FlashInfer 0.7.2 it loses (+1.2% at 5 rows, TP4 4/1/5, n = 2; +2.4% at 6 rows), so it runs only when listed in SGLANG_NVIDIA_MEGAKERNEL_SLOTS. - Both require hops:finalize. A layer that does not fit declines the family with the layer and the reason. Tests (4 GPUs): the copied call equals SGLang's runner bit for bit at 5-48 rows; the layer (hop + MoE + finalize hop) equals the stock layer bit for bit on the hop's FP4 input inside FlashInfer's one-shot band; CUDA-graph replays equal eager; the priority stream keeps the bits. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Perf] [GB300] glm5_3: TP4 NextN draft composed from units (P6a eh_proj, LL attention, row select) The draft step (draft_step.FusedDraft) serves TP8. At a TP4 profile the draft spec now builds draft_units.ComposedBuiltDraft: each draft graph (draft decode at one row per request, draft extend at the verify rows) is composed through the registry from the draft step groups (draft_front, draft_eh, draft_attention, draft_mlp, draft_top1): - draft.front (slot draft): the draft step's fused embedding + eh norms (the kernel does not depend on the TP size); - ll.draft_eh (P6a, ll/draft.py): eh_proj row-parallel, each rank's K window times its weight columns. With the target's LL hops (found through the shared-table registry, runtime.register_target_hops) the partials are summed and the draft layer's input norm applied in one hop launch, and the layer starts from that (draft_attention.PreparedInput: the attention prepare is skipped); otherwise SGLang's all-reduce and the stock norm. Per draft forward at TP4, L2 flushed: 20-26 us vs 39-41 us for the replicated GEMM; - the draft layer's attention on ll.attention and ll.sparse_mla_fd (the stock DraftAttention on the step's ForwardView elsewhere); - draft_rowselect in the draft extend (draft_step.select_index_rows); - the LM head on ll.gemm's lm_head role; the top-1 stays SGLang's (at TP4 its one-tray multimem gather is as fast as the distributed argmax or faster). The composed draft is built when the target shares its embedding and LM head (set_embed_and_head, before the KV pool is sized), so the LM-head role is built on the target's head. Draft graphs outside the profile's widths run SGLang's draft forward. The TP8 draft keeps the TP8 widths (<= 16 rows). Tests: test/unit/test_glm5_3_draft_units.py and test_glm5_3_draft_eh_prepared.py (CPU: widths, compositions, slots, the hand-off to the logits processor), test/kernels/test_glm5_3_draft_eh_proj.py (4 GPUs: numerics at 1-48 rows, the hop sum + norm, graph replay). Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Test] glm5_3: Serving tests and decode A/B configuration at the AgentX TP4 / TP8 points - test/e2e/glm5_3_server.py, test_glm5_3_server.py: servers at the InferenceX AgentX configurations (tp4-416: aggregated TP4, EAGLE 4/1/5, HiCache; tp8-516: aggregated TP8 on two trays, EAGLE 5/1/6, HiCache; tp4-516: the disaggregated decode role, TP4, EAGLE 5/1/6, standalone): on / off (the active line, covered decode graphs, GSM8K-200 within 3 points), parity (SGLANG_NVIDIA_MEGAKERNEL_SLOTS="" vs flag off, greedy ids and logprobs bitwise) and HiCache load-back (load-back output equals the device-hit output). - benchmark/README.md: the GLM decode A/B protocol at those configurations. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Feat] [GB300] glm5_3: Serve the TP4 decode role of a PD-disaggregated deployment A PD deployment of GLM-5.2 on GB300 (the InferenceX AgentX 1p5d-c30 / 1p3d-c40 points) runs a TP1 PP4 prefill role and TP4 EAGLE 5/1/6 decode roles. The spec now lists Feature.PD_DISAGGREGATION, so a decode role serves its verify steps on the TP4 kernel units: the KV arrives through the transfer backend (NIXL) into pool slots before a request's first verify step, outside the covered step, and the decode radix cache is not a framework feature. The TP8 envelope keeps PD refused (pd_reasons). The prefill role runs without the flag (TP1 and PP are refused anyway). Tests: test/unit/test_glm5_3_spec.py (the decode role accepted at TP4, refused at TP8); test/e2e/test_glm5_3_server.py TestGlm53PDDecode (GSM8K through a running 1P1D router, decode engaged, prefill not, no NIXL transfer failure). Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Test] glm5_3: Remove the tests this PR added (repo policy: no tests in sgl-nvidia-mega) Per review, sgl-nvidia-mega carries no tests. Remove the 28 test files this PR added under test/e2e, test/kernels and test/unit (the GLM-5.3 TP4, draft row select and PD decode tests and their helpers glm5_3_server.py and glm5_3_slots.py), and drop the benchmark README's pointer to the removed test/e2e/glm5_3_server.py. Tests that already exist on the base branch are left untouched. Co-Authored-By: Claude Opus 5.5 <[email protected]> * glm5_3: Keep SGLang's copyright notice in the headers of files adapted from SGLang Apache-2.0 requires derivative files to retain the copyright notices of the work they adapt. Following the OSRB guidance, add "Portions Copyright 2023-2024 SGLang Team (Apache-2.0)" after the NVIDIA SPDX lines of the glm5_3 files adapted from SGLang, and name the origin of ll/moe.py, whose routed-expert call copies SGLang's. fused_a_ll.cuh copies most of SGLang's dsv3_fused_a_gemm.cuh, so it keeps that file's header unchanged and adds the NVIDIA and SGLang lines below it. Header lines only. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] glm5_3: pin the SGLang mirrors for main's SGLang (cf6133a) main's unit tests check out SGLang cf6133a, where eight glm5_3 mirrors no longer matched. Each change keeps the covered steps as mirrored, so the new digest is added beside the old ones (both SGLangs pass): - forward_absorb_prepare / forward_absorb_core (#44503, #38943): the indexer, the unfused RoPE and the W_UV projection moved into the run_mla_indexer, prepare_mla_qkv and project_mla_values hooks, whose defaults are the old calls (no SGLang class overrides them); the DCP extend gather is out of the spec's setups. - Indexer.forward_cuda, DeepseekSparseAttnBackend._forward_trtllm (#46890): prefill-CP only. - DeepseekV2DecoderLayer.forward (#46857), in the hops, the MoE step and the draft attention: an assert under CP decode attention TP, which the spec refuses. - LogitsProcessor.forward (#47200): vocab-sharded logits for a target verify only; the draft steps the mirror covers take the gather as before. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Doc] glm5_3: Document the TP4 split-K GEMM source switch in the README SGLANG_NVIDIA_MEGAKERNEL_GLM_GEMM_SPLITK picks the split-K source of the TP4 small-M GEMMs (auto, flashinfer or vendored); document it next to the TP4 units, as the README documents Qwen3.5's SGLANG_NVIDIA_MEGAKERNEL_MOE_TACTICS. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Yangmin Li <[email protected]> Co-authored-by: shuw <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Kaixi Matteo Chen <[email protected]>
…TP draft Adds sgl_nvidia_mega/glm52/sm107 (Rubin, sm_107a), enabled with GLM5MK=1 through the plugin. For bs=1 decode on agentx it reaches 1139 tok/s/user against stock SGLang's 352 (about 3.2x): - the 75-layer decoder chain runs as one kernel launched per layer with PDL overlap (MLA attention with the sparse indexer, NVFP4 MoE on tcgen05, cross-rank exchange over Lamport buffers); - dense layers 0-2, the MTP draft step and the fused verify/sampling tail replace the stock paths; - CuTeDSL ops keep the per-step bookkeeping (page table, post-verify, draft pages, tree layout) inside CUDA graph replay. Unit tests cover the hook-up, the kernel-tree import order and the ops against torch implementations. Co-Authored-By: Claude <[email protected]>
… knobs and the unused non-TMA EH load path Co-Authored-By: Claude <[email protected]>
[Feat] glm52/sm107: CuTeDSL megakernels for GLM-5.2 TP16 decode and MTP draft
Follow the model/<sm> layout of main's glm5_3/sm103: the TP16 bs=1 decode and MTP draft kernels move from glm52/sm107 to glm5_3/sm107. - add glm5_3/__init__.py, byte-identical to main's, so the package ships with setuptools' find_packages and merges with main without a conflict - rename the package, its error messages and the plugin hook-up (GLM52_TP16_ENV -> GLM5_3_SM107_ENV; the switch is still GLM5MK=1) - rename test/unit/test_glm52_sm107.py -> test_glm5_3_sm107.py - point the import-isolation test's PYTHONPATH at the repo root Kernel-internal outlined function names (glm52_*_piece) are unchanged so the compiled code stays identical to the validated build. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts: - plugin.py: GlmMoeDsaForCausalLM / ...NextN now go to main's glm5_3 spec and draft (the successor of glm_dsa); glm_dsa stays in the tree but is no longer registered. - README.md: main's model table and GLM-5.2 notes; drop the GLM-5 DSA row and flags; keep the speculative step graph section; add a note on the GLM5MK=1 TP16 Rubin path in glm5_3/sm107. - CODEOWNERS, pyproject.toml: keep both sides. - test_contract.py: main's optional-contract skip, with the "any alternative" message. Co-Authored-By: Claude Opus 5.5 <[email protected]>
After merging main, GlmMoeDsaForCausalLM and its NextN draft are registered to glm5_3, which covers the same model, GPUs and TP8 verify / draft steps, so nothing loads glm_dsa any more. Remove the package, its config test and its CODEOWNERS line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The GLM-5.2 TP16 Rubin path is now selected by glm5_3's specs, with --enable-nvidia-megakernel as its only switch: - glm5_3/spec.py admits TP16 (sm_107 only) and dispatches by TP size: config_disable_reasons, model_disable_reasons and build go to sm107 at TP16. The TP8 / TP4 server arguments and environment move from Requirements (one per spec) to config_disable_reasons (per TP size), checked and worded as SGLang checks them. - glm5_3/draft.py: the NextN draft dispatches to sm107 at TP16. - sm107: build_target / build_draft pack the weights at build and bind the KV pools before the runner's CUDA graphs; the built megakernel plans one request's verify step (target) and draft steps (draft). sm107 pins its own validated server arguments and SGLANG_DSA_FUSE_TOPK. - Remove the GLM5MK switch, the sys.meta_path import hooks, the os._exit guards and root/sitecustomize.py. The cubin directory is SGLANG_NVIDIA_MEGAKERNEL_GLM_SM107_CUBINS, refused at argument resolution when unset or incomplete (no /glm5mk default). - Tolerate SGLang without dsa_backend.fused_dsa_target_verify_metadata. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Formatting only: ruff-format and isort over glm5_3/sm107 (mostly the kernels from #2), spec_step and the sm107 test. No statement changes: the ASTs match apart from import ordering, every module imports the same names, and the sm107 unit tests (including the CuTe DSL / GPU tests and the kernel-tree import order) pass on VR200. codespell: `arith.CmpFPredicate.OLT` (MLIR's ordered less-than) is marked `# codespell:ignore`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Any earlier test that imports the package writes git-ignored __pycache__/*.pyc under sm107, which this check flagged in CI. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve README.md: take main's short README (sgl-project#82); add TP16 to the GLM row and move the TP16-on-Rubin text to docs/models/glm5_3.md, and the speculative step graph switches to docs/spec_step.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
This was referenced Nov 23, 2026
mattteochen
added a commit
to mattteochen/sgl-nvidia-mega
that referenced
this pull request
Nov 23, 2026
Since sgl-project#19 the GLM-5.3 spec checks its environment per TP size (pinned_reasons) instead of declaring it in Requirements.env, so SGLang's FLAG_SETS_ENV no longer sets SGLANG_ENABLE_EMBED_REPLICATION with --enable-nvidia-megakernel, and without it the server stops at startup, naming it. The docs still said the flag turns it on. Say that slot draft needs it set to 1, as benchmark/README.md already does, and add it to the launch example. Co-Authored-By: Claude Opus 5.5 <[email protected]>
YAMY1234
pushed a commit
that referenced
this pull request
Nov 24, 2026
* [Feat] [VR200] glm5_3: Serve the TP4 kernel units on Rubin (SM107) On SM107 every TP4 kernel unit declined (ll.attention, ll.hops, ll.moe and ll.sparse_mla_fd gated on SM103 with 152 SMs, ll.gemm on GB300's plan only, and the TP4 draft required an SM103 GPU), so a TP4 build served no width and stopped. The kernels are the same sources on both GPUs: the JIT units compile for the device and the CuTe DSL kernels for its arch. - ll/device.py: the GPUs the units serve, GB300 (plans measured) and Rubin (plans derived from GB300's); each unit logs once when its plan is derived. - ll.attention, ll.hops, ll.moe and the TP4 draft accept both GPUs. - ll.sparse_mla_fd: on Rubin the row caps are GB300's cut to the clusters the device co-schedules, queried at build; a width Rubin cannot launch in one wave declines to TRTLLM-Gen instead of stopping the server. GB300 keeps its fail-stop on the same facts. - ll.gemm: one plan per GPU. Rubin runs GB300's ranges with every split-K tactic re-checked for one wave of 212 SMs, and keeps SGLang's router GEMM. The split-K source on SM107 is the vendored copy, since FlashInfer's explicit tactics serve SM100 / SM103. - The vendored split-K reserves the device's opt-in shared memory instead of CuTe DSL's SM100 constant (the same 232448 bytes on both GPUs). Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Test] glm5_3: The TP4 kernel units on Rubin, on CPU Rubin composes every TP4 width and draft graph as GB300 does, other GPUs take no unit, the TP4 draft admits SM107, the per-GPU GEMM plans (no router split-K on Rubin, every split-K tactic within one wave of 212 SMs), the split-K source on SM107, the sparse MLA's declines on Rubin against GB300's fail-stop, and the split-K shared memory read from the device. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] glm5_3: Square in FP32 in the TP4 one-shot hop's RMSNorm The TP4 all-reduce + residual + RMSNorm hop (ll.hops) squared each bf16 element in bf16 before summing in FP32 on its one-shot form, as FlashInfer 0.7.1's MNNVL one-shot did. FlashInfer 0.7.3 squares in FP32 (flashinfer-ai/flashinfer#6818), as its two-shot and our two-shot already did, so on the FlashInfer that SGLang pins (0.7.3 and later) the one-shot hop was no longer bit-identical to FlashInfer's one-shot, and its norm output was up to 1 bf16 ulp off the stock path's on some elements. The one-shot now converts each element to FP32 and squares it there. With the same launch geometry it is bit-identical to FlashInfer 0.7.3's one-shot again; every other step of the hop is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Refactor] glm5_3: Pick the TP4 units' plans once per build, with Rubin's in sm107/ The Rubin plans, caps and device selection moved out of glm5_3/ll, so ll/ holds GB300's code only and no longer checks the architecture (AGENTS.md: architecture directories do not overlap). - ll/target.py (replaces ll/device.py): Target, the GPU the ll.* units run on and the plans they run there (GEMM plan, SM count, GPCs, whether FlashInfer's explicit split-K tactics run, measured or derived), and GB300's, measured. - sm107/tp4.py: RUBIN, Rubin's target: GB300's GEMM plan without the router's split-K, 212 SMs, 16 GPCs, the vendored split-K, derived caps, and the notes each unit logs once. - targets.py: select(), the one place that maps an architecture to a target. Profile.from_args calls it once and the profile carries the result (Profile.target); the units read it from there. - ll.attention / ll.hops / ll.moe / ll.sparse_mla_fd decline when the profile has no target, instead of comparing the compute capability; ll.gemm and ll.build_linear take the target instead of (sm, sms); gemm_plan.PLANS, RUBIN_PLAN, device_plan and device_gpcs are gone. - The vendored split-K reserves CuTe DSL's sm_100 shared memory again, as on main: 232,448 bytes, which is also Rubin's opt-in. Same plans, caps and kernels on both GPUs as before. Tests: the selection happens once per profile, no ll/ file names SM107 or imports sm107/, and Rubin's GEMM plan is GB300's without the router. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Doc] glm5_3: Set SGLANG_ENABLE_EMBED_REPLICATION=1 for the NextN draft Since #19 the GLM-5.3 spec checks its environment per TP size (pinned_reasons) instead of declaring it in Requirements.env, so SGLang's FLAG_SETS_ENV no longer sets SGLANG_ENABLE_EMBED_REPLICATION with --enable-nvidia-megakernel, and without it the server stops at startup, naming it. The docs still said the flag turns it on. Say that slot draft needs it set to 1, as benchmark/README.md already does, and add it to the launch example. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
mattteochen
added a commit
to mattteochen/sgl-nvidia-mega
that referenced
this pull request
Nov 24, 2026
…ronment Since sgl-project#19 the GLM-5.3 spec checks its environment per TP size instead of in Requirements.env, so SGLang's FLAG_SETS_ENV no longer sets SGLANG_ENABLE_EMBED_REPLICATION for --enable-nvidia-megakernel, and the candidate arm stopped at startup ("SGLANG_ENABLE_EMBED_REPLICATION False is not True"). The helper now launches both arms with it, as the model page launches the megakernel, so the arms still differ only in the flag. Co-Authored-By: Claude Opus 5.5 <[email protected]>
6 of 7 tasks
YAMY1234
added a commit
to YAMY1234/sgl-nvidia-mega-fork
that referenced
this pull request
Nov 26, 2026
…erving image The GLM-5.2 NVFP4 decode megakernel paths of one submission image, on top of d5eb692: - TP4 / TP8 (based on Kaixi Matteo Chen's GLM-5.2 Rubin plugin work): the TP4 kernel units serve on Rubin (SM107) with plans derived from GB300's (glm5_3/ll/device.py); the TP8 envelope also serves the decode role of a PD-disaggregated deployment; the NextN draft step (draft front, sparse MLA, top-1 sink for the draft LM head, MoE tail in one hop); die-local MoE engines, o_proj router producers, MLA prologue overlap and fold forms. Each optimization is behind its SGLANG_NVIDIA_MEGAKERNEL_GLM_* switch; the test-only diagnostics stay off by default. - TP16 bs=1 (sgl-project/sgl-nvidia-mega sgl-project#19): glm5_3/sm107, the whole one-request EAGLE 7 / topk 1 / 8 step from prebuilt cubins (SGLANG_NVIDIA_MEGAKERNEL_GLM_SM107_CUBINS), and spec_step, the EAGLE v2 topk-1 decode step as one CUDA graph behind its own switches. sgl-project#19 applied cleanly in code; its documentation conflicts were resolved by keeping both sides (spec.py docstring and comment, README, docs/models/glm5_3.md with the TP4 / TP8 Rubin text added). glm5_3/sm107's draft-extend stand-in for SGLang's LogitsProcessorOutput reads every field it does not set as this SGLang's dataclass default (the GLM-5.2 serving tree's EAGLE worker reads next_token_argmax_partials); a CPU unit test checks each field against the real dataclass. Co-Authored-By: Claude Opus 5.5 <[email protected]>
YAMY1234
added a commit
to YAMY1234/sgl-nvidia-mega-fork
that referenced
this pull request
Nov 26, 2026
…erving image The GLM-5.2 NVFP4 decode megakernel paths of one submission image, on top of d5eb692: - TP4 / TP8 (based on Kaixi Matteo Chen's GLM-5.2 Rubin plugin work): the TP4 kernel units serve on Rubin (SM107) with plans derived from GB300's (glm5_3/ll/device.py); the TP8 envelope also serves the decode role of a PD-disaggregated deployment; the NextN draft step (draft front, sparse MLA, top-1 sink for the draft LM head, MoE tail in one hop); die-local MoE engines, o_proj router producers, MLA prologue overlap and fold forms. Each optimization is behind its SGLANG_NVIDIA_MEGAKERNEL_GLM_* switch; the test-only diagnostics stay off by default. - TP16 bs=1 (sgl-project/sgl-nvidia-mega sgl-project#19): glm5_3/sm107, the whole one-request EAGLE 7 / topk 1 / 8 step from prebuilt cubins (SGLANG_NVIDIA_MEGAKERNEL_GLM_SM107_CUBINS), and spec_step, the EAGLE v2 topk-1 decode step as one CUDA graph behind its own switches. sgl-project#19 applied cleanly in code; its documentation conflicts were resolved by keeping both sides (spec.py docstring and comment, README, docs/models/glm5_3.md with the TP4 / TP8 Rubin text added). glm5_3/sm107's draft-extend stand-in for SGLang's LogitsProcessorOutput reads every field it does not set as this SGLang's dataclass default (the GLM-5.2 serving tree's EAGLE worker reads next_token_argmax_partials); a CPU unit test checks each field against the real dataclass. Its fused verify tail covers a seed on a greedy verify (the argmax draws nothing; lm-eval sends a seed with greedy requests) and still refuses a seed when the verify samples; a CPU unit test covers both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
mattteochen
added a commit
to mattteochen/sgl-nvidia-mega
that referenced
this pull request
Nov 27, 2026
…ronment Since sgl-project#19 the GLM-5.3 spec checks its environment per TP size instead of in Requirements.env, so SGLang's FLAG_SETS_ENV no longer sets SGLANG_ENABLE_EMBED_REPLICATION for --enable-nvidia-megakernel, and the candidate arm stopped at startup ("SGLANG_ENABLE_EMBED_REPLICATION False is not True"). The helper now launches both arms with it, as the model page launches the megakernel, so the arms still differ only in the flag. Co-Authored-By: Claude Opus 5.5 <[email protected]>
mattteochen
added a commit
to mattteochen/sgl-nvidia-mega
that referenced
this pull request
Nov 27, 2026
Since sgl-project#19 the GLM-5.3 spec pins its environment per TP size (pinned_reasons on ENV at TP8 / TP4, glm5_3/sm107's at TP16) and leaves Requirements.env empty, so SGLang's FLAG_SETS_ENV no longer sets SGLANG_ENABLE_EMBED_REPLICATION, and a server with the NextN draft (slot draft) stopped at startup with "SGLANG_ENABLE_EMBED_REPLICATION False is not True" unless the user set it. config_disable_reasons now sets the variables of ENV listed in the spec's own FLAG_SETS_ENV to their pinned value when they are unset, at argument resolution, as SGLang does for Requirements.env: only at TP8 / TP4 and only when slot draft is on. It logs what it set, keeps and checks a value the user set, and clears what it set when the setup is refused. TP16 is unchanged: its draft reads the vocab-sharded embedding, which is why the variable cannot go back into Requirements.env. The docs say again that the flag turns it on. Tests: test/unit/test_glm5_3_flag_env.py. Co-Authored-By: Claude Opus 5.5 <[email protected]>
YAMY1234
added a commit
that referenced
this pull request
Nov 29, 2026
…#95) * [Fix] glm5_3: Set SGLANG_ENABLE_EMBED_REPLICATION automatically again Since #19 the GLM-5.3 spec pins its environment per TP size (pinned_reasons on ENV at TP8 / TP4, glm5_3/sm107's at TP16) and leaves Requirements.env empty, so SGLang's FLAG_SETS_ENV no longer sets SGLANG_ENABLE_EMBED_REPLICATION, and a server with the NextN draft (slot draft) stopped at startup with "SGLANG_ENABLE_EMBED_REPLICATION False is not True" unless the user set it. config_disable_reasons now sets the variables of ENV listed in the spec's own FLAG_SETS_ENV to their pinned value when they are unset, at argument resolution, as SGLang does for Requirements.env: only at TP8 / TP4 and only when slot draft is on. It logs what it set, keeps and checks a value the user set, and clears what it set when the setup is refused. TP16 is unchanged: its draft reads the vocab-sharded embedding, which is why the variable cannot go back into Requirements.env. The docs say again that the flag turns it on. Tests: test/unit/test_glm5_3_flag_env.py. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Fix] glm5_3: Restore SGLANG_ENABLE_EMBED_REPLICATION after the flag tests monkeypatch.delenv(raising=False) records nothing when the variable is absent, so the value the spec writes with envs.X.set() in the TP8/TP4 test stayed in os.environ for the rest of the test session. Set it to an empty value first so that monkeypatch records it and restores the original state at teardown. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Yangmin Li <[email protected]>
YAMY1234
added a commit
that referenced
this pull request
Nov 29, 2026
…ry for the GB300 runner (#92) * [Test] [GB300] glm5_3: Add TP4 E2E tests against the SGLang baseline Adds GLM-5.3 / GLM-5.2 (NVFP4) end-to-end tests for the four-GPU GB300 runner, following the DeepSeek-V4.1-Flash layout: - test/e2e/glm5_3_server.py: the model path, the TP4 MTP launch the spec admits (EAGLE 5 steps / topk 1 / 6 draft tokens, DSA + TRT-LLM decode, fp8_e4m3 KV at page 64, flashinfer_trtllm MoE, shared-experts fusion off). - test/e2e/test_glm5_3_server.py: baseline (flag off) then candidate (flag on) on GSM8K-1319, 5 shots, greedy, real acceptance, at 8 and 16 concurrent requests; per-question paired verdicts (candidate >= baseline - 1.5 pp) and an acceptance-length verdict (>= 0.9x baseline); engagement checked in both logs. SGLANG_NVIDIA_MEGAKERNEL_E2E_URL scores a running server instead. - test/e2e/test_glm5_3_switch.py: every slot off plus the parity switch; each eager verify step of 6 to 48 rows must match SGLang's logits bit for bit. - ci_models.yaml entry glm5_3 and the model page's Tests section. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Test] glm5_3: Set SGLANG_ENABLE_EMBED_REPLICATION in both arms' environment Since #19 the GLM-5.3 spec checks its environment per TP size instead of in Requirements.env, so SGLang's FLAG_SETS_ENV no longer sets SGLANG_ENABLE_EMBED_REPLICATION for --enable-nvidia-megakernel, and the candidate arm stopped at startup ("SGLANG_ENABLE_EMBED_REPLICATION False is not True"). The helper now launches both arms with it, as the model page launches the megakernel, so the arms still differ only in the flag. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Test] glm5_3: Say why both arms set SGLANG_ENABLE_EMBED_REPLICATION; match the active line by prefix The baseline arm runs without the flag, so the flag's own setting of the variable never reaches it: the helper keeps the two arms' embedding layout the same, also once the flag sets the variable for the candidate. The active-line check now matches the start of the unit list instead of its first entry, which depends on the unit names. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Yangmin Li <[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.
Motivation
At bs=1, GLM-5.2 NVFP4 decode with EAGLE MTP on Rubin is launch- and host-bound. This PR adds two pieces to the plugin:
glm5_3/sm107(from [Feat] glm52/sm107: CuTeDSL megakernels for GLM-5.2 TP16 decode and MTP draft wenscarl/sgl-nvidia-mega#2, by Donglin): CuTe DSL megakernels for the bs=1 decode step of GLM-5.2 at TP16 on 4 x 4 VR200, with EAGLE 7 draft steps / 8 verify tokens.glm5_3spec, so--enable-nvidia-megakernelis the only switch.spec_step: one CUDA graph per EAGLE v2 topk-1 decode step, plus six small spec-path fusions. This piece is model-agnostic.After merging main, the GLM architectures (
GlmMoeDsaForCausalLMand...NextN) are registered to main'sglm5_3spec and draft (#24). This branch's earlierglm_dsapackage has been removed.Modifications
sgl_nvidia_mega/glm5_3/sm107/(new)Per the
<model>/<sm>/layout, this sits next to main'sglm5_3/sm103. GLM-5.2 has GLM-5.3's architecture and the same pinnedHF_CONFIG.kernels/chain_n148sq): one kernel, launched per layer with PDL overlapkernels/dd)verify_tail.py)eagle_sample+ glueops.py)Kernel symbol names (
glm52_*_piece) are unchanged, so the machine code is identical to #2.How it is enabled:
--enable-nvidia-megakernelonly. At TP16, theglm5_3target spec (spec.py) and draft spec (draft.py) dispatch tosm107:sm107)config_disable_reasons)glm5_3's server-argument and environment pinssm107.config_reasons: SM107 only, EAGLE 7 / topk 1 / 8 tokens,fp8_e4m3KV,trtllmDSA decode,flashinfer_trtllmMoE, no unified memory, no PD disaggregation,SGLANG_DSA_FUSE_TOPK=0, and a complete cubin directorymodel_disable_reasons,build)glm5_3runtimesm107.build_target/build_draftWhat
builddoes. It packs the weights before SGLang sizes the KV cache, then binds the chain and the draft to their runner's KV pools just before that runner captures its CUDA graphs.What SGLang reports. The built megakernel plans one request's verify step (target) and draft steps (draft). SGLang logs
NVIDIA megakernel: active (… glm5_3/sm107 …)andruns the decode graphs of batch sizes [1].Refusals. Any refusal stops the server at startup with the reasons listed, through SGLang's normal refusal path.
Requirements no longer shared across TP sizes.
glm5_3's TP8 / TP4 server-argument and environment pins moved fromRequirements(one per spec, shared by every TP size) toconfig_disable_reasons, checked per TP size. Their wording matches SGLang's own checks.Removed from [Perf] [GB300] deepseek_v41: Megakernel decode attention chain for 1 to 48 rows #2: the
GLM5MKswitch, thesys.meta_pathimport hooks, theos._exitguards,root/sitecustomize.py, and the/glm5mkdefault.Cubin directory.
SGLANG_NVIDIA_MEGAKERNEL_GLM_SM107_CUBINSpoints at the prebuilt{chain,d012,draft,tail}/{entry.cubin,CALL.json}. It is configuration, not a switch, and startup is refused when it is unset or incomplete.Ported from SGLang
a4ff5634bto current SGLang. The flag only exists in SGLang from [Feat] [NVIDIA] megakernels: Add --enable-nvidia-megakernel and a layer for NVIDIA megakernel plugins sglang#44945 on. It still runs on the old API.ForwardModemoved toforward_mode.py.fused_dsa_target_verify_metadatawas removed.run_eagle_verifynow computes the commit outputs itself, soverify_tailno longer rewrites it.softcap, theeagle_sampleoptions,iteration_ids, and the 3-tuple returned byprepare_for_draft.IterationIds) the way SGLang's own draft does.Tests.
test/unit/test_glm5_3_sm107.pycovers:test_contract.pypasses for everysm107/glm5_3file against SGLang27aedf7f9.sgl_nvidia_mega/spec_step/(new; model-agnostic; installed throughHookRegistry)Each switch is off by default. With all of them off, no hook is registered.
SGLANG_NVIDIA_MEGAKERNEL_SPEC_STEP_GRAPHFullCudaGraphBackend: keeps the raw graphs, splices replays into an active child-graph capture, adds graph epochsresolve_decode_backendEAGLEWorkerV2.init_cuda_graphs/forward_batch_generationspec_utilscapture overrides/get_server_infostatsSGLANG_SPEC_STEP_GRAPH_FUSED_INPUT_COPYSGLANG_SPEC_PACKED_VERIFY_BROADCAST,SGLANG_SPEC_LEAN_SAMPLED_VERIFY,SGLANG_SPEC_CHUNKED_VERIFY_SAMPLINGeagle_utils.eagle_sampleandtree_speculative_sampling_target_onlySGLANG_SPEC_FUSED_DRAFT_EXTEND_TAILEagleDraftWorker._draft_extend_for_decodeSGLANG_SPEC_FUSED_RELAYFutureMap.stashandFutureMap._resolve_spec_extrasEvery fusion's outputs are bitwise identical to the path it replaces.
Other
plugin.py: GLM architectures go to main'sglm5_3spec / draft. The spec_step hooks are registered there too.README.md: the TP16 Rubin path and what it covers, plus the speculative step graph switch table.CODEOWNERS,pyproject.toml(package data forspec_step/csrc).glm_dsa(andtest/unit/test_glm_dsa_config.py). Main'sglm5_3covers the same model, GPUs and TP8 steps.Accuracy Tests
All
glm5_3/sm107runs below are TP16 on 4 x 4 VR200 with cubinsart_28a0d41, through--enable-nvidia-megakernel, against stock SGLang on the same nodes.f5cc4856a(Nov 20 nightly)27aedf7f9(Nov 4 nightly)Earlier evidence, from the same kernels under the old
GLM5MKswitch on SGLanga4ff5634b:eagle_sample: 900/900 greedy, 25,200/25,200 argmax.spec_step: bitwise identical by construction (same kernels, same reductions, same RNG stream).Speed Tests and Profiling
agentx, through
--enable-nvidia-megakernel.27aedf7f9, InferenceX aiperfinferencex-agentx-mvp, concurrency 1, 300 s, simulated acceptance length 3.91 in both arms, same 4 nodes.glm52-nvfp4-tp16-vr200-agentx-enable-nvidia-megakernel-pr19-20261120.Stock on this SGLang is slower than on
a4ff5634b(3.86 vs 2.84 ms), so the speedup is larger than #2's 3.2x. The megakernel's absolute ITL matches #2 (0.878 ms).sglang bench, through
--enable-nvidia-megakernel.f5cc4856a, random 1K output, concurrency 1, simulated acceptance length 3.91, same 4 nodes, megakernel / stock / megakernel.spec_step. On TP8 Rubin with the earlierglm_dsakernels, the step graph gave +1.7% at c1 (2.38 → 2.34 ms ITL) and was flat at c4. TODO: re-measure on top of main'sglm5_3.Reproduce (
glm5_3/sm107, TP16, 4 nodes, each node)Limitations
glm5_3/sm107:Checklist
pre-commit run --all-files)glm_dsa(superseded byglm5_3)--enable-nvidia-megakernelas the only switch forglm5_3/sm107🤖 Generated with Claude Code