Repository navigation
[Refactor] spec: Move platform dispatch and Triton kernels into kernels/ops - #45504
Conversation
fill_front_out_cache_loc_func for post-verify move targetskernels/ops wrappers
kernels/ops wrapperskernels/ops
…upled-spec rid codec and inbox
|
/rerun-test test_next_verify_prep.py test_graph_pool_borrow.py test_move_accept_tokens_targets.py test_build_eagle_tree.py test_spec_ngram.py registered/spec/uno/test_uno.py test_spec_eagle.py test_spec_eagle_topk.py test_eagle_reject_sampling.py registered/spec/dflash/test_dflash.py test_dspark_kernel_parity.py test_dflash_overlap_hostsync.py test_renorm.py test_dflash_logits.py test_verify_mask.py test_kernels_namespace.py test_spec_utils_reexport_surface.py test_uno_tree_sparse_sampling.py test_eagle_worker_v2_topk1_fastpath.py test_dspark_accept_tail.py |
|
/tag-and-rerun-ci |
|
🚀 🚀 🚀 🚀 |
… 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.
…traverse — entries 102,103,119-supersede,120,194,195,261-264 3 markers consumed (eagle_utils RE-PLANTED; spec_utils re-plant; eagle_info VERIFIED-ABSORBED). B4 tree count now 12. PER-FILE: - eagle_utils.py (entry 103): RE-PLANTED the tensors-after-early-return graft (num_needed_tokens == 0 returns before any torch.tensor -- the 17F were the fail-fast + alloc-path rebuilding CPU tensors every round; topk>1 max_alloc_len back to the list-builtin max) MERGED with upstream's in-range mirrorless block: it rides AFTER the tensors now (it reads cur_kv_lens_cpu) with a getattr-guarded seq_lens_cpu read -- identical semantics for the real ScheduleBatch (attr always present), stale-stub-proof. - spec_utils.py (entries 102,120,195; 261 deduped): * entry 261 sgl-project#45491: DEDUPED with evidence -- git log 12dc623..2a6c204 proves 573b571 IN RANGE; its verify-window semantics SURVIVE upstream's later refactors (sgl-project#45504 kernel move + sgl-project#46990 typed views collapsed the triton assign_extend_cache_locs pair) as fill_front_out_cache_loc_func(num_correct_drafts+1, batch.out_cache_loc, ...) carrying sgl-project#45491's OWN comment text; the fork-hunks window-form is thus superseded-in-place (origin/main has neither old name -- the replacement landed within the same range). * entry 195 sgl-project#44317: RE-PLANTED the traverse_tree host walk (tolist + numpy bitmask view; int words) + the needs_vocab_mask() skip (the backend-side methods ALREADY landed upstream in constrained/ -- consumer half was the dropped one) + the leftover-grammar_mask clear on the grammars-present-but-unconstrained path (the merged tree had the clear on the SUCCESS path only -- the stale-mask class this entry exists for). traverse_tree 3F -> green. * entry 102 (PLE on the ReplaySSM branches) + entry 120 (circular-ring fold before a plain extend): RE-PLANTED, RETARGETED to sgl-project#45504/sgl-project#46980 reality: kernel import path attention.fla.* -> attention.linear.* (upstream's kernels regroup), and the fold reads mamba_pool.get_speculative_mamba2_params_all_layers() (upstream sgl-project#46980 deleted the req-pool delegate; same route the verify-commit uses now). test_replayssm_extend_fold collection 1err -> 2P (the documented 'pair': its sibling test_replayssm_ring_fold.py was PRUNED by upstream's own sgl-project#44690 (file gone; a stale .pyc remains) and the 'gdn cutedsl probe' err belongs to kernels/ops/attention (6 CUDA-import collection errs there -- B1/B5 zone, not this dir): the spec-dir population is now 0err. test_replayssm_verify_ple_commit 1F -> green (stub re-anchored: router part_view seam + PLE pools off-pin restored -- the entry-102 pin the upstream file rewrite dropped, present in the 309-tip test verbatim). - eagle_info.py (entry 194): VERIFIED-ABSORBED -- the call sites pass num_token_blocks=None + kv_lens_sum, and runner_ids.pack_read_stream auto-sizes with the fork's OWN helper (spec_kv_index_token_blocks, now hosted in kernels/ops/attention/kv_indices) -- the 'AUTO-SIZED upgrade' B3-4 recorded; identical tiling math. - Entry-119 supersession chain CLOSED as briefed: sgl-project#45435's upstream form (tails padded -1 + mamba_lazy_undo_prealloc_at_boundary + untracked_decode_batch_idx gate) is the tree's reality (B4-2 audit); entry 119's production half stays dead. - test_ngram_mamba_verify_update.py (B2-marked file, B2 marker INTACT): restored only the two PLE off-pins + the entry-102 comment that the 309-tip fork version carried and upstream's rewrite dropped -- my re-plant re-creates the condition they exist for. ACTUALS (damage -> after, CVD=9, prod venv, per-file): test_eagle_decode_allocation 17F -> ** 18P ** (16-matrix + capacity + 1) test_spec_utils_traverse_tree 3F -> green (file pin incl.) test_replayssm_extend_fold 1err -> ** 2P ** test_replayssm_verify_ple_commit 1F -> green DIR unit/spec 363P/20F/21S/238sub/2err -> ** 388P/0F/21S/238sub/0err ** (two consecutive full-dir re-runs EXACT; DoD(b): zero non-env F). Lint: ruff format + F821/E9/F401 clean on the six files. No GPU; no push. Co-Authored-By: OpenCode <[email protected]>
…v2 step CUDA graph (spec_step) (#19) * [Feat] [GB300/Rubin] glm_dsa, spec_step: GLM-5 DSA fused verify and NextN 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. * [Fix] spec_step: keep the step graph on torch 2.14 and make lifted.py 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. * [Fix] glm_dsa: accept --speculative-algorithm NEXTN 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. * [Perf] glm_dsa: split the verify path into packages; Rubin round-7 hop 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]> * [Feat] glm_dsa: serve MTP with 5 draft steps (6 verify rows a request) Port #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]> * [Fix] glm_dsa: run on released SGLang (megakernel API 2, multi-node TP8) - 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]> * [Fix] glm_dsa: name the NextN draft's architecture and pin its config 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]> * [Fix] glm_dsa: repair names lost in the package split (TP8 e2e on Rubin) - 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]> * [Feat] glm52/sm107: CuTeDSL megakernels for GLM-5.2 TP16 decode and MTP 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]> * [Refactor] glm52/sm107: drop the draft diagnostics, ablation and test knobs and the unused non-TMA EH load path Co-Authored-By: Claude <[email protected]> * [Refactor] glm5_3/sm107: move the GLM-5.2 Rubin megakernels under glm5_3 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]> * [Cleanup] glm_dsa: remove the package superseded by glm5_3 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]> * [Feat] glm5_3/sm107: serve TP16 through --enable-nvidia-megakernel 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]> * [Docs] glm5_3/sm107: state the steps the TP16 path does not cover Co-Authored-By: Claude Opus 5.5 <[email protected]> * [Lint] Apply pre-commit (ruff, ruff-format, isort, codespell) 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]> * [Test] glm5_3/sm107: ignore __pycache__ in the no-binaries check 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]> --------- Co-authored-by: Brayden Zhong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Donglin Yang <[email protected]>
fill_front_out_cache_loc_funcandassign_draft_cache_locs_contiguous_funcinkernels/ops/speculative/cache_locs.py, each dispatching to the Triton kernel or thesgl_kernelCPU op;move_accept_tokens_to_target_kvcacheand the draft cache-loc assignment call them, andspec_utilsdrops its CPU-op imports,next_power_of_2, and the unusedassign_extend_cache_locsforwardsrt:compute_dflash_correct_drafts_and_bonustokernels/ops/speculative/dflash.py(sodspark_acceptno longer imports it fromsrt),table_qk_norm_rope_tokernels/ops/attention/table_qk_norm_rope.py, anduno_tree.pytokernels/ops/speculative/uno_tree.pyunchangedreconstruct_indices_from_tree_mask_funcinreconstruct_tree.py(Triton on XPU, the compiled op elsewhere);ngram_workerdrops its per-platform importsTreeMaskMode, the tree-build and greedy-verify Triton launchers, andverify_tree_greedy_funcintokernels/ops/speculative/spec_tree.py, and split the platform dispatch out ofbuild_tree_kernel_efficientintobuild_tree_kernel_efficient_func;eagle_utilskeeps the mask allocationkernels/ops/sampling/renorm.py(top_k_renorm_prob,top_p_renorm_prob) andkernels/ops/speculative/verify_sampling.py(tree_speculative_sampling_target_only,chain_speculative_sampling_triton),Nonewhere a platform has no kernel; DFlash and EAGLE import from there instead of each keeping its own tablealign_evict_mask_to_page_size,get_src_tgt_cache_loc,get_target_cache_loc, andfilter_finished_cache_loc_kernelwith theirspec_utilsforwards (and the unusedassign_req_to_token_poolforward),create_num_accept_tokens_filter,compute_ragged_extend_lengths,read_draft_checkpoint_gamma, and the decoupled-spec request-id codec,DraftControlInbox, andReadyDraftControls, which only their tests usedtest_next_verify_prep.pycalls the draft wrapper over a smaller matrix;test_graph_pool_borrow.pypatches the sampling op whereeagle_utilsbinds it; droptest_decoupled_spec_io.py, whose schema has no production callerNo behavior change on CUDA. Elsewhere: on NPU, DFlash's target-probability renormalization uses the
sgl_kernel_npuops EAGLE already uses, with thetorch_npupath as fallback; on CPU the draft assignment passeswindow_cols, which equalsnum_stepsthere.CI States
Latest PR Test (Base): 🚫 Run #39556705672
Latest PR Test (Extra): ❌ Run #39556705491
Latest PR Test (AMD ROCm 10): ⏳ Run #39556705596