Repository navigation
Conversation
Add a single-launch Triton kernel that runs the full per-step
expand + top-k recurrence on the GPU (power-of-2 topk in {4, 8, 16}),
replacing the Python step loop. `build_tree_verify_tokens` in
dflash_utils drives it and emits the EAGLE
(draft_tokens, parent_list, selected_index) contract, so the existing
spec-v2 KV / accept / mask path is reused unchanged.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Wire the fused GPU tree builder into DFlashWorkerV2 behind a new --speculative-dflash-tree-verify flag. When enabled (and --speculative-eagle-topk > 1), the draft block is expanded into an EAGLE-style verification tree whose node budget (--speculative-num-draft-tokens) may exceed the draft block size. - DFlashVerifyInput carries the tree (parent_list / selected_index) and reusable tree-mask / position buffers (EAGLE-style buffer reuse). - Accepted tree-path KV is moved to the contiguous front of each verify block (lossless; mirrors EAGLE v2) and the accept compaction runs in a single fused Triton kernel (dflash_tree_accept_compact). - speculative_hook relaxes the chain-only topk==1 / num_draft_tokens== block_size constraints when tree verify is on. Full-attention targets only; default off = byte-identical chain verify. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…cuda graph Extend the sgl-project#29395 draft-sampler graph-capture idea to tree verify. Add _DflashTreeDraftSampler, run as a draft-decode-graph tail hook, which captures BOTH the per-step top-k over the target LM head AND the fixed-shape draft-tree pruning (build_tree_verify_tokens: fused expand/select kernel + fast_topk + sort + gather) inside the draft cuda graph, writing (draft_tokens, parent_list, selected_index) to static buffers. On replay the tree draft step reads those buffers and skips the eager head GEMM, materializing draft_hidden, AND the eager tree build. Byte-for-byte with the eager path (fused kernel has one fixed constexpr config, compiled during graph warmup). tp=1 / no-added-vocab only. Only the verify attention mask build stays eager (its work is seq_len-dependent). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ng scaffolding
Ponytail cleanup, no behavior change on the supported path:
- dflash_tree_expand_topk.py: remove the unused single-step dflash_expand_topk4
kernel + is_dflash_expand_topk4_available + module topk constants (only the
fused full-recurrence kernel is used). 310 -> 203 lines.
- build_tree_verify_tokens: drop the eager non-fused fallback + _select_top_k_tokens_no_hidden
and the dead timing_ctx_factory/timer scaffolding; the fused GPU path is the only
supported one. Raise a clear error if CUDA/power-of-2-topk preconditions are unmet.
- speculative_hook: validate --speculative-eagle-topk in {4,8,16} at launch for tree verify.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
The tree accept was greedy-only (verify_tree_greedy_func + argmax), silently degrading non-greedy requests. Add compute_dflash_tree_sampling_accept: wraps the tree-native tree_speculative_sampling_target_only kernel with the pruned tree's retrieve structures (already built by build_tree_kernel_efficient), returning the same (predicts, accept_index, accept_token_num) layout so dflash_tree_accept_compact is unchanged. Tree accept now branches on sampling_info.is_all_greedy, mirroring the chain path. draft_probs=zeros (DFlash threshold-accept scheme), same as chain. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
TestDFlashServerTreeVerify enables the draft tree on the spec-v2 overlap path via --speculative-dflash-tree-verify + --speculative-eagle-topk 4 (triton verify attention). Reuses the chain gsm8k accuracy threshold (tree verify is greedy- lossless) and raises the accept-length bound. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Tree verify returned speculative_num_draft_tokens=self.block_size (the draft block size, 16) while next_token_ids = out_tokens.reshape(-1) has a per-request stride of draft_token_num (the verify budget, 32). batch_result_processor slices next_token_ids as [i*stride : i*stride + accept_lens[i]], so with the wrong stride every request after the first (bs > 1) reads another request's slot -- silently committing wrong tokens. Invisible until now because (a) bs=1 always reads at offset 0 regardless of stride, and (b) the chain path has block_size == draft_token_num so the two coincide; only tree verify decouples them. gsm8k accuracy at concurrency 64 collapsed to ~0.05 (vs baseline 0.75); accept_len stayed normal, so throughput benchmarks never caught it. Pass the verify budget (local block_size, already = draft_token_num in the tree branch) as the result stride. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Ran TestDFlashServerTreeVerify on the real CI model (Llama-3.1-8B-Instruct + z-lab UltraChat DFlash head, the sgl-project#22077 setup) — accept length is ~3.37 there (vs the chain suite's 2.8 bound), not the 3.5 I had guessed from Qwen's ~7.8. Tree still clears the chain threshold; 3.5 was just too aggressive for this head. Test now passes (gsm8k accuracy + accept length, batched verify bs>1). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
…upstream # Conflicts: # python/sglang/srt/server_args.py # python/sglang/srt/speculative/dflash_info.py
SubSir
marked this pull request as ready for review
July 13, 2026 21:14
SubSir
requested review from
Fridge003,
Qiaolin-Yu,
Ying1123,
hnyls2002,
ispobock and
merrymercy
as code owners
July 13, 2026 21:14
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
…upstream # Conflicts: # python/sglang/srt/speculative/dflash_worker_v2.py
…o dflash-tree-verify-upstream
efschu
pushed a commit
to efschu/htsglang
that referenced
this pull request
Jul 26, 2026
… group collective
Found by booting it: Nordstern L0 S4 (TP=5 over two hosts, EAGLE3, solo draft
placement, --disable-cuda-graph). Ranks 1-4 reached "Tree cache initialized"
and started their health checks; rank 0 went silent for 8 minutes until the
launcher killed it. py-spy on the solo rank:
all_gather_object (distributed_c10d.py)
_harmonize_cuda_graph_plan (model_runner.py:1098)
init_cuda_graphs (model_runner.py) <- tp_worker <- eagle_worker_v2
Under --speculative-draft-placement solo only the solo rank owns a real draft
runner; the shadow ranks get a stub (install_shadow_draft_runner_surface) and
never call init_cuda_graphs on it. The harmonisation's all_gather_object is
group-wide, so the solo rank entered a collective no other rank would ever
join. This is independent of nnodes -- it is a property of solo placement.
Fix: skip the harmonisation when spec_solo_rank_local_graphs is set. That flag
already declares exactly this ("this runner's graphs are captured rank-locally,
the shadow ranks skip draft capture entirely") and already suppresses the
capture backends' per-warmup TP barrier; the harmonisation is a second group
collective in the same category. It also MUTATES the shared cuda_graph_config,
so letting the draft runner harmonise could disable a phase for the target
runner too.
Also in this commit, from the same window:
* sgl-project#76 GUARD HARDENED (sgl-project#98 sighting). The trigger is no longer "topk > 1" but
"anything that would activate a tree-masked verify", via the new
ServerArgs.tree_verify_activation_reason(). Upstream carries three
unconsolidated PRs (sgl-project#31069/sgl-project#29587/sgl-project#29907) adding
--speculative-dflash-tree-verify, a SECOND door onto the terrain sgl-project#76 fenced
off. It does not exist here yet, so it is read with getattr: the guard is
armed for its arrival instead of waiting to be remembered during a merge.
The refusal is not theoretical -- see the byte-gate numbers below.
* l0_rank.sh: --max-total-tokens is now optional (MAXTOK=0 leaves the KV pool
uncapped) because a tok/s number without the context it was reached at is not
a result (harness rule sgl-project#4).
* l0_launch.sh: forward MAXTOK/MEMFRAC/EXTRA to the second host. They were not
forwarded, so MAXTOK=0 applied to the main rig only: rank 0 sized its pool to
133802 tokens while ranks 3/4 silently kept the 2048 default. A capacity
number measured that way means nothing.
TESTED
CPU: test_uneven_tp_args.py -- 13 passed (TreeSpec*), both directions. The new
flag is rejected under uneven DCP WITH topk=1 (i.e. exactly the case the old
guard would have let through), the healthy path (chain, no tree verify) stays
open with the flag false AND with it absent, the original topk door still
rejects, the message names which flag tripped it, and a single-GPU tree run is
untouched. Full suites: server_args + spec kernel backend -- 271 passed.
GPU, RTX 5090, byte gate step 1 (native sgl_kernel vs Triton spec kernels,
identical inputs, bit comparison of every output tensor of build and verify):
topk=1 chains 16/16 EXACT (bs 1-2, steps 2-3, FULL_MASK and QLEN_ONLY)
topk=2,4 trees 8/32 exact -- tree_mask differs by 6-13 elements, and one
case raised a CUDA error inside the Triton kernel
So the group-decision's refusal of topk>1 on the Triton path is now measured,
not precautionary, and this guard's subject matter is the same computation.
GPU, five ranks, both hosts (Llama-3.1-8B fp16, ratio 4,3,3,2,1, ctx 2048,
eager, HTCCL/gloo): S4 (solo) and S3 (split) BOTH BOOT AND SERVE after this
fix. That is the first live proof of the narrowed nnodes gate (f34a343) and
of the capability-keyed spec kernels (4bcb310) -- ranks 3 and 4 have no
sgl_kernel, so the group ran the Triton path end to end.
Contributor
|
Thanks @SubSir. Closing this because it has had no updates in 91 days. Reopen it if the work is still relevant. Some directories moved recently, so an older branch may need retargeting: |
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.
[Feature] DFLASH EAGLE-style draft-tree verification
Motivation
Adds EAGLE-style draft tree verification to DFLASH (spec-v2 worker), on top
of the existing chain verify (#16818 / #22077). The draft head proposes a top-k
tree per step; the target verifies it in one pass and accepts the best
root-to-leaf path — ~+22% accept length (budget 32) and higher low-concurrency
throughput. Opt-in via
--speculative-dflash-tree-verify(default off = chain,unchanged).
Modifications
New file
kernels/ops/speculative/dflash_tree_expand_topk.py— fused Triton kernelrunning the full per-step expand + top-k recurrence in one launch (power-of-2
topk in {4, 8, 16}); the per-step loop lives inside the kernel.
Modified files
speculative/dflash_worker_v2.py— tree draft-step, tree accept(
verify_tree_greedy_funcgreedy /tree_speculative_sampling_target_onlynon-greedy), scattered-accept KV move-to-front. Top-k sampling + tree build are
folded into the draft decode CUDA graph (mirrors [Spec] Capture DFLASH draft greedy sampling inside the draft decode cuda graph #29395).
speculative/dflash_info.py— tree fields + mask/positions/retrieve build inprepare_for_verify.speculative/dflash_utils.py—build_tree_verify_tokens(drives the fusedkernel) +
compute_dflash_tree_sampling_accept.kernels/ops/speculative/dflash.py—dflash_tree_accept_compact(treeanalogue of the chain accept-bonus kernel).
model_executor/runner/decode_cuda_graph_runner.py— mask-capable verify CUDAgraph for tree.
arg_groups/speculative_hook.py— validate--speculative-eagle-topk∈ {4, 8, 16}.server_args.py— the--speculative-dflash-tree-verifyflag.test/registered/spec/dflash/test_dflash.py—TestDFlashServerTreeVerify.Notes
1118 tok/s, accept 7.60 at conc=1, Qwen3-8B).
scheduling supported.
--speculative-eagle-topklimited to {4, 8, 16}; tree gains are low-concurrency.Accuracy Tests
Greedy tree accept is lossless by construction —
verify_tree_greedy_funccommits a draft token only when it equals the target argmax.
GSM8K accuracy (chat zero-shot, temp 0, max_tokens 2048), baseline vs chain vs
tree, Qwen3-8B / 1× B200:
The three track within sampling noise (tree is lowest at conc=1 but highest at
conc=64).
TestDFlashServerTreeVerify(max_running_requests=8, batched verify)gates gsm8k accuracy + accept length in CI — verified passing.
Speed Tests and Profiling
Qwen/Qwen3-8B(+z-lab/Qwen3-8B-DFlash-b16) andGemma-4-31B-it(+ z-labDFlash draft), 1× B200, triton, overlap. Launch:
Chain baseline = drop
--speculative-dflash-tree-verify/--speculative-num-draft-tokens, set--speculative-eagle-topk 1. torch.compileis used for Qwen3-8B only — on the 31B model its Triton GEMMs are slower than cuBLAS.
Cross-dataset, conc 1 (tok/s, accept in parens)
enable_thinking=False, 512 samples.Qwen3-8B:
Gemma-4-31B-it:
Budget 32 is the sweet spot: b128 raises accept but its verify cost erodes tok/s
— on the 31B model b128 gsm8k (364) even drops below chain (385).
Concurrency sweep, gsm8k (chain vs tree b32)
Separate config (128 questions, torch.compile on), so conc=1 tok/s differs
slightly from above.
Why tree loses at high concurrency
At
b16tree verifies the same 16 tokens/step as chain, isolating tree-build cost:Even at equal budget, tree's per-step overhead (tree build, masked attention,
scattered-accept KV move) outgrows the ~12% step savings — hidden at conc=1,
exposed once compute-bound (b32 loses more). Use tree for latency-sensitive /
low-QPS serving, chain for throughput.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ❌ Run #29780528370
Latest PR Test (Extra): ❌ Run #29780527538