Skip to content

[Spec] DFlash: remove per-step host syncs so the CPU runs a full step ahead (spec-v2 overlap) - #31468

Merged
hnyls2002 merged 12 commits into
sgl-project:mainfrom
thanhhao98:htphan/dflash-overlap-hostsync
Jul 18, 2026
Merged

hnyls2002 merged 12 commits into
sgl-project:mainfrom
thanhhao98:htphan/dflash-overlap-hostsync

Conversation

@thanhhao98

@thanhhao98 thanhhao98 commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Under spec-v2 overlap scheduling, DFlash stalls the host every decode step: nsys shows a large cudaStreamSynchronize between the draft and verify cuda graphs, so cudaGraphLaunch for step N+1 is only issued after step N has finished (launch lead ≈ −50 µs). EAGLE3 spec-v2 runs a full step ahead; DFlash should too. This PR removes every per-step host↔device sync on that path. Result: the CPU queues step N+1 a full step early (launch lead +19 ms, run-ahead fraction 0.88 → 0.995), worth +12–13% tok/s/user at low concurrency and +3–5% at high, with GSM8K and accept-length unchanged.

Modifications

Each item removes one per-step host block:

  1. Compact draft-cache rebuild → one triton kernel (rebuild_compact_draft_req_to_token). The old rebuild synced three times per step (lengths.max().item(), a boolean-mask gather's implicit nonzero D2H, and a blocking .to("cpu")), each waiting on the previous verify step. The kernel writes the suffix window + verify-block slots directly into the draft req_to_token row with no data-dependent shapes. The host seq_lens_cpu planning bound becomes min(len, window+page) — deliberately an envelope, not a mirror of the exact page-align math, which is a non-monotonic sawtooth and would under-shoot when fed the reserved over-estimate.

  2. HybridAttnBackend: OR-delegate needs_cpu_seq_lens to the sub-backends. The missing attribute defaulted to True, forcing FutureMap.resolve_seq_lens_cpu's pinned D2H + stream.synchronize() before every step's launches — zero run-ahead on hybrid arms even when both sub-backends opt out.

  3. Fold the TP>1 draft greedy sampler into the draft cuda graph (tp=1 fold already existed): per-rank shard (max, global id) → two in-graph NCCL all-gathers → first-max select. Bit-exact vs a full-vocab argmax including shard-boundary ties. SGLANG_DFLASH_EAGER_DRAFT_SAMPLER=1 restores the eager path.

Correctness

  • Unit tests in this PR (test/registered/unit/spec/test_dflash_overlap_hostsync.py): kernel bit-exact vs the legacy path (incl. no writes past the verify block), sampler == full-vocab argmax incl. a shard-boundary tie, the sawtooth-envelope bound with its counterexample, hybrid flag delegation, filter_batch host-list equivalence.
  • 8×B200 probes at production dims (tp=8, vocab 163840): fused rebuild and folded sampler bit-exact, cross-rank identical.
  • GSM8K 5-shot: 0.965 == 0.965 (main vs main+PR); accept-length 2.47 / 2.51.

Benchmarks (Kimi-K2.6-NVFP4 + DFlash draft, 8×B200 TP=8, aiperf 50K-prefix)

Same-base A/B, identical stack, only this PR's commits differ:

cc main 40a3bd76 main + PR Δ
1 256.9 288.0 +12.1%
2 215.0 243.6 +13.3%
4 169.7 174.4 +2.8%
8 125.2 131.8 +5.3%
16 80.5 84.5 +5.0%

nsys (cc16, same pair): launch lead median −51 µs → +19.1 ms; run-ahead fraction 0.883 → 0.995; per-thread cudaStreamSynchronize 336×/3816 ms → 9×/11 ms. The only remaining per-step host sync is the intended copy_done in result processing (identical to EAGLE3 spec-v2). Same shape on the tokenspeed_mla arm (K2.7: +11.5% cc1, lead −57 µs → +17.1 ms); details in the PR comments.

Checklist

  • Format your code according to the Code Formatting with Pre-Commit.
  • Add unit tests as outlined in the Running Unit Tests (test/registered/unit/spec/test_dflash_overlap_hostsync.py, 7 tests, validated on B200).
  • Update documentation / docstrings / example tutorials as needed, according to Writing Documentation.
  • Provide throughput / latency benchmark results and accuracy evaluation results as needed, according to Benchmark and Profiling and Accuracy Results.
  • For reviewers: If you haven't made any contributions to this PR and are only assisting with merging the main branch, please remove yourself as a co-author when merging the PR.

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ⏳ Run #29632179798
Latest PR Test (Extra): ❌ Run #29632179752

@github-actions github-actions Bot added the blackwell SM100/SM120 label Jul 16, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Hao Phan added 4 commits July 17, 2026 10:33
…to the draft graph

Two per-step host-stall fixes for spec-v2 run-ahead (the CPU must launch
step N+1's cuda graphs while step N still executes):

1) Compact draft req_to_token rebuild: replace the masked segment gather
(+ 2x assign_req_to_token_pool) with one fused fixed-grid triton kernel.
The old path blocked the host twice per decode step: lengths.max().item()
and the boolean-mask packed gather (data-dependent shape => implicit
nonzero D2H), serializing the CPU behind the previous verify step. The
draft-forward host planning bound (seq_lens_cpu) is now computed on CPU
from the scheduler-maintained host lens via the monotonic envelope
min(len, window+page) instead of a blocking D2H. The exact page-align
mapping is a non-monotonic sawtooth, so the envelope (not a mirror of the
arithmetic) is required to stay an upper bound when fed the reserved
overlap over-estimate. Legacy path kept only for non-GPU-triton platforms.

2) Extend _DflashDraftSampler to the vocab-parallel (TP>1) head and lift
the tp>1 eager bail: per-rank shard max/argmax -> global id, two NCCL
all-gathers (captured into the draft graph like the draft model's own
collectives), first-max select. Tie resolution is bit-exact vs a
full-vocab argmax (contiguous ascending shards + first-max argmax).
A/B escape hatch: SGLANG_DFLASH_EAGER_DRAFT_SAMPLER=1 forces eager.
Removes the eager between-graphs sampler cluster (matmul + reduce +
2x all_gather + gather) from the host launch path.
decide_needs_cpu_seq_lens ORs the flag across attn backends; the hybrid
prefill/decode wrapper had no attribute so the getattr default (True)
forced FutureMap.resolve_seq_lens_cpu into its per-step pinned D2H +
fwd_prepare_d2h_stream.synchronize() even when both sub-backends opted
out (trtllm_mla prefill + cutedsl_mla decode). That host sync sits before
any of step N's launches and blocks on step N-1's verify completing on
GPU, forcing zero CPU run-ahead on the hybrid arm.
DFlashDraftInputV2.filter_batch sliced reserved_seq_lens_cpu with
new_indices.cpu(), a blocking D2H of the GPU index tensor on the
scheduler thread every time batch composition changed. ScheduleBatch
already holds the host-side keep list; pass it through and index the CPU
tensor directly. EAGLE/ngram accept the kwarg unchanged.
…prep churn

- init_forward_metadata: never derive max_seq from the GPU tensor (the
  .max().item() drains the whole stream backlog under spec-v2 overlap);
  fall back to the static context bound when no host mirror exists.
- DCP eager paths: set dcp_local_max_seq_len / dcp_prefix_local_max
  host-side (ceil(global/world) bound covers get_dcp_lens on every rank),
  so forward_decode/_forward_verify_dcp never hit the per-layer
  local .max().item() device sync (61 syncs/step on Kimi) off-graph.
- _apply_cuda_graph_metadata target-verify: fuse the seq_lens+T add
  straight into the captured int32 seq_lens_k buffer (out= same-kind
  downcast) and feed that buffer to the block-table kernel: one kernel,
  no per-step temp alloc.
- WAR fastpath: reuse a 2-deep event ring instead of allocating a fresh
  cuda Event per graph replay (DFlash records twice per step).
@thanhhao98
thanhhao98 force-pushed the htphan/dflash-overlap-hostsync branch from 677d454 to 361a7e8 Compare July 17, 2026 03:33
Hao Phan added 2 commits July 17, 2026 14:15
…comments further, add unit tests

- SGLANG_DFLASH_EAGER_DRAFT_SAMPLER moves to the typed envs registry.
- Second comment pass: keep only the load-bearing invariants (sawtooth
  envelope, tie-safety, needs_cpu_seq_lens OR-default trap, re-record
  safety, legacy-path sync rationale).
- test_dflash_overlap_hostsync.py: fused rebuild bit-exact vs legacy path
  (+ no write past the verify block), vocab-parallel sampler == full-vocab
  argmax incl. shard-boundary ties (simulated TP group, single GPU),
  host-bound envelope >= exact incl. the sawtooth counterexample,
  HybridAttnBackend needs_cpu_seq_lens delegation, filter_batch host
  keep-list equivalence.
@thanhhao98

thanhhao98 commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor Author

nsys before/after — the overlap improvement, Kimi-K2.6-NVFP4 cuteDSL, cc16

BEFORE (main 40a3bd7):

before: per-step cudaStreamSynchronize blocks the launch thread

AFTER (this PR):

after: launches queued a full step ahead; only the intended copy_done event sync remains

@hnyls2002

hnyls2002 commented Jul 18, 2026 •

Copy link
Copy Markdown
Collaborator

/rerun-test registered/unit/spec/test_dflash_overlap_hostsync.py registered/spec/dflash/test_dflash.py registered/core/test_basic_sanity_dflash.py registered/spec/eagle/test_spec_eagle.py registered/spec/test_spec_ngram.py registered/attention/test_hybrid_attn_backend.py registered/attention/unittests/mla/test_trtllm_mla.py

@hnyls2002

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Rebase Required Before Re-run

A major update has landed on main. Your PR is diverged relative to required base commit a5c0b94034.

Re-run was not dispatched. What to do:

  • Rebase your branch onto the latest main and push again
  • Follow issue #21065 for context
  • CI-fix PRs may request the bypass-maintenance label to skip this check

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jul 18, 2026
@github-actions

github-actions Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test registered/unit/spec/test_dflash_overlap_hostsync.py registered/spec/dflash/test_dflash.py registered/core/test_basic_sanity_dflash.py registered/spec/eagle/test_spec_eagle.py registered/spec/test_spec_ngram.py registered/attention/test_hybrid_attn_backend.py registered/attention/unittests/mla/test_trtllm_mla.py:

🚀 1-gpu-5090 (4 tests): ✅ View workflow run

cd test/ && python3 registered/unit/spec/test_dflash_overlap_hostsync.py
cd test/ && python3 registered/spec/dflash/test_dflash.py
cd test/ && python3 registered/core/test_basic_sanity_dflash.py
cd test/ && python3 registered/spec/eagle/test_spec_eagle.py

🚀 1-gpu-h100 (3 tests): ✅ View workflow run

cd test/ && python3 registered/spec/test_spec_ngram.py
cd test/ && python3 registered/attention/test_hybrid_attn_backend.py
cd test/ && python3 registered/attention/unittests/mla/test_trtllm_mla.py

🚀 4-gpu-b200 (1 test): ✅ View workflow run

cd test/ && python3 registered/attention/unittests/mla/test_trtllm_mla.py

@hnyls2002

hnyls2002 commented Jul 18, 2026 •

Copy link
Copy Markdown
Collaborator

@thanhhao98 I reverted the read_done event ring on your branch (commit 4a488a5) — it is orthogonal to this PR's goal: it removes a per-step allocation, not a host sync, and the same per-replay Event() pattern exists elsewhere (e.g. copy_done in scheduler result processing), so it should be done uniformly rather than for one site.

Could you resubmit the event-ring change as a separate PR covering all the per-step Event() sites? Please also drop the event-ring bullet from this PR's description (item 4) since it is no longer part of the diff.

@hnyls2002

Copy link
Copy Markdown
Collaborator

/rerun-failed-test

@thanhhao98

Copy link
Copy Markdown
Contributor Author

Thanks @hnyls2002 @kpham-sgl for pushing this. I removed event-ring in PR description.
I will create separate PR for it.

@thanhhao98
thanhhao98 deleted the htphan/dflash-overlap-hostsync branch July 19, 2026 06:31
Zhylkaaa pushed a commit to Zhylkaaa/sglang that referenced this pull request Jul 29, 2026
@kpham-sgl kpham-sgl mentioned this pull request Aug 13, 2026
1 task done
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 24, 2026
…e, Hybrid needs_cpu_seq_lens

Upstream 72c4ed1 (sgl-project#31468, v0.5.20), von Hand, zwei kleine Stuecke.

Portiert:
- ScheduleBatch.filter_batch reicht die Host-Keep-Liste als
  new_indices_cpu an spec_info.filter_batch. DFlashDraftInputV2 nimmt sie
  im Fork schon (nxt_kv_lens_cpu[new_indices_cpu]), bekam sie aber nie ->
  bisher new_indices.cpu() = blockierender D2H bei jedem Filter mit
  beendetem Request. EagleDraftInput / NgramVerifyInput (und damit
  FrozenKVMTPDraftInput) nehmen den kwarg an.
- HybridAttnBackend.needs_cpu_seq_lens = prefill OR decode (sonst zwingt
  der Basisklassen-Default True decide_needs_cpu_seq_lens zum per-Step
  seq_lens-D2H). Auf dem 27B-D-Pfad nicht aktiv (prefill/decode-Backend
  gleich, HybridLinearAttnBackend delegiert schon), der Vollstaendigkeit
  halber mitgenommen.

Test (CPU, incg 3 GiB): test/registered/unit/spec/test_dflash_overlap_hostsync.py
(neu, Teil 1): TestHybridNeedsCpuSeqLens (upstream) +
TestFilterBatchHostIndices (Fork-Feldnamen nxt_kv_lens_cpu, plus
Signaturpruefung eagle/ngram): 3 passed, 2 subtests. Gegenprobe gegen
Basis-Quellen: rot (siehe Teil 3, dort der Gesamtlauf).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 24, 2026
…h in SpecTpSync begrenzen

Teil 2 der sgl-project#31468-Portierung (DFlash: per-Step-Host-Syncs raus, damit die
CPU einen Schritt vorlaeuft). Keine Upstream-Zeile: das ist eine
Fork-Sync-Stelle, die der Zensus des 27B-D-Decodepfads gefunden hat.

Befund: SpecTpSync.sync (sgl-project#1485-Instrument, df2l6 17.09.) klont vor jedem
Broadcast den rang-lokalen Wert und vergleicht danach per torch.equal
(Device-Read -> blockiert den Host, bis der Stream leer ist). Begrenzt
war das nur ueber die Zahl der ABWEICHUNGEN (40). Auf Rang 0 (Broadcast-
Quelle) ist local == broadcast per Konstruktion -> der Vergleich retiriert
dort NIE; auf den Empfangsraengen nicht, solange sie uebereinstimmen. Im
DFLASH-Decode (TP3) sind das bis zu 6 blockierende Reads je Runde:
DFLASH_SELECTOR (draft_tokens) + 5x DFLASH_ACCEPT_GREEDY bzw. 3x beim
Selector-Sampling.

Aenderung:
- Die Broadcast-Quelle vergleicht nie (kann nichts finden).
- Empfangsraenge vergleichen hoechstens SGLANG_SPEC_TP_DIVERGE_CHECKS mal
  (Default 64 je SpecTpSync-Instanz, ~10 Decode-Runden); danach eine
  INFO-Zeile "sgl-project#1485 SPEC-TP-DIVERGE check retired ...". -1 = altes
  unbegrenztes Verhalten auf den Empfangsraengen (fuer Divergenz-Jagd),
  0 = aus. Die 40er-Grenze fuer Log-Zeilen bleibt.
- Broadcast selbst unveraendert (Entscheidungen bleiben rang-einheitlich).

Test (CPU, incg 3 GiB): TestSpecTpSyncDivergeBudget (Fake-TP-Gruppe, zaehlt
clone-Aufrufe = Vergleiche): Rang 0 -> 0 von 100, Rang 1 Budget 5 -> 5,
-1 -> 100, 0 -> 0; Datei gesamt 7 passed, 2 subtests.
Gegenprobe mit Basis-spec_tp_sync.py: 3 failed (Rang 0 vergleicht 100x,
Rang 1 100x statt 5, "0" wirkt nicht) -> rot.

Metall: SPEC-TP-DIVERGE-Zeilen erscheinen nur noch in den ersten ~10
Runden je Rang 1/2; fuer eine Divergenz-Jagd SGLANG_SPEC_TP_DIVERGE_CHECKS=-1.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 24, 2026
… Host-Sync + Sync-Zensus

Upstream 72c4ed1 (sgl-project#31468, v0.5.20). Nicht die Upstream-Datei: der Fork-
dflash_worker_v2 ist stark geforkt; die Sync-Stellen des 27B-D-Pfads
(TP3 split, --speculative-draft-window-size 2048 -> compact draft cache,
page_size 1, DFlash2-Selector im Graph, flashinfer, Overlap an) einzeln
nachgewiesen und entfernt.

Befund je Decode-Runde im Compact-Zweig (forward_batch_generation):
 1. seq_lens_cpu.copy_(draft_prefix_lens.to("cpu"))      blockierender D2H
 2. _gather_req_to_token_segments: lengths.max().item()   blockierend
 3. ... req_to_token[...][mask] (bool-Index, impl. nonzero) blockierend
Jeder davon laesst die CPU auf das Ende der Vorrunde warten.

Portiert / angepasst:
- kernels/ops/speculative/cache_locs.py: rebuild_compact_draft_req_to_token
  (Triton, fester Grid, keine Host-Reads) -- upstream-Hunk unveraendert.
- DFlashWorkerV2: _compute_compact_draft_seq_lens_host (min(len,
  window+page), monotone Huelle, >= exakt; bei page_size 1 und exaktem
  Spiegel = exakt). Quelle batch.seq_lens_cpu (im Fork exakt aus
  overlap_utils.resolve_seq_lens_cpu), sonst draft_input.nxt_kv_lens_cpu
  (Fork-Name fuer upstream reserved_seq_lens_cpu), sonst der alte D2H.
- Compact-Rebuild per Kernel, WENN _use_triton_compact_rebuild und kein
  _solo_pool_mapper (der Solo-Kleinpool uebersetzt die gesammelten Slots
  und bleibt deshalb auf dem alten Gather-Pfad, unveraendert).
- SGLANG_DEBUG_DFLASH_SYNC_TRACE=N (neu, Default 0 = aus): die ersten N
  Decode-Runden laufen unter torch.cuda.set_sync_debug_mode("warn");
  Logzeilen DFLASH-SYNC-ROUND rank= round= syncs= und DFLASH-SYNC-SITE
  site=<datei:zeile> (je Stelle einmal). Muster wie
  hicache_write_path.sync_trace. Das ist der Host-Sync-Zaehler fuers Metall.

Nicht portiert (begruendet):
- TP>1-Greedy-Head im Draft-Graph (_DflashDraftSampler mit all-gather):
  der 27B-D-Pfad nutzt den DFlash2-Selector (_SelectorDraftSampler, im Fork
  schon unter TP gefaltet); der Greedy-Head laeuft dort nicht.
- trtllm_mla_backend: MLA, nicht unser Pfad.
- _bonus_id_bufs int32->int64: ein Cast-Kernel je Runde, Zeile liegt direkt
  neben dem Mamba-Verify-Bereich (Agent A) -> fuer sauberen Merge weggelassen.

Test (CPU, incg 3 GiB), test_dflash_overlap_hostsync.py komplett:
12 passed, 2 subtests:
- TestCompactSeqLensHostBound (upstream + 27B-Form window 2048/page 1 exakt).
- TestRebuildCompactDraftReqToTokenInterpreted: Kernel bit-exakt gegen den
  alten Gather+2x-assign-Pfad, im Triton-INTERPRETER (Subprozess,
  TRITON_INTERPRET=1), 5 Formen inkl. bs 6/window 2048/page 1/block 8
  (upstream-Test ist CUDA-only).
- TestDflashSyncTraceUnarmed (Durchreichen ohne CUDA / fuer Prefill).
- Gegenprobe gegen die Basis-Quellen (Teil 1-3 zurueckgedreht): 11 failed /
  2 passed (rot).
- Bestehende DFLASH-Tests unveraendert gruen: test_dflash_logits 7,
  solo_pool 24, solo_vocab_broadcast 11, flip_consumer_d 5,
  draft_kv_producer_p 14.

Metall-Pruefpunkt (nur dort messbar): Decode tok/s D, DFLASH-SYNC-ROUND
syncs= vor/nach, SGLANG_DFLASH_PHASE_TIMING (prep/embed/draft_fwd/verify ms).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 24, 2026
…ec ring

27B ReplaySSM package, slice S3 of REPLAYSSM_PLAN.md. With the flag off every
path is unchanged (no rows planned -> recurrent route, intermediate commit).

Ported: upstream GDNAttnBackend._replayssm_target_verify (same kernel call,
launch_mode="verify", null block -1, request rows as replay indices) and the
compact commit sequence of upstream's spec_utils (commit_gdn_replayssm_spec +
commit_gdn_replayssm_circular + conv-window rollback).

Adapted (this line's own wiring; upstream refuses GDN + DFLASH):
- ForwardMetadata.replayssm_spec_rows: the verify metadata plans the request
  rows (req_pool_indices) in all three builders (eager, graph capture, graph
  replay -- there the static buffer with padded rows zeroed). The commit reads
  the rows the verify used from the metadata, like mamba_cache_indices, so no
  caller changes: DFLASH (dflash_worker_v2 untouched), the EAGLE/MTP commit
  and the lane all go through update_mamba_state_after_mtp_verify.
- The commit sits in that shared hook (ring branch when intermediate_ssm is
  None). Linear chain -> accepted = last step + 1 (bonus included); -1 folds
  nothing, like the masked scatter.
- FOLD EVERY COMMIT for any SSM dtype (upstream defers the fold for fp32):
  radix insert, HiCache backup, tail adopt and the flip all read `temporal`
  and assume it is the committed state after every verify, as the recurrent
  route makes it. The ring is then per-step scratch (write_pos 0 at every
  verify).
- Heal: outside a capture the verify metadata re-states write_pos = is_flush
  = 0 for the step's rows (true by construction after every commit), so a
  verify never trusts cursor bytes from an earlier step (TMS restore, flip,
  reused row). cache_base is circular and harmless at write_pos 0.
- forward_extend routes the verify to the ring when rows are planned; a draft
  tree on the ring, or a pool with neither intermediate state nor planned
  rows, is refused. The ring kernel honours token strides, so the verify split
  stays torch.split views (sgl-project#33778).
- Advance cursor null block 0 (request row 0 is the ReqToTokenPool padding
  row); the widest verify window is kept on the pool as the advance's
  constant (one compiled variant across the adaptive ladder).
- Ring length must be >= 16 (the compact commit's tl.dot) -- pool and static
  check; S2 test moved to L=16.
- _replayssm_spec_for: a draft-KV-only producer (no verify workspace, sgl-project#1233
  FIX 4) treats the flag as a no-op instead of hitting the pool's
  missing-window refusal.
- getattr on the new metadata field in the two readers (sgl-project#624 stub drift:
  test_gdn_verify_strided_qkv_33778 doubles predate it).

Tests (CPU, incg cgroup, one file at a time):
test/registered/unit/layers/attention/test_replayssm_spec_route_s3.py: 10
passed. Hermetic: rows planned + healed (eager, replay; not in capture;
padded row -> row 0), flag off / decode plan nothing, the three refusals,
producer no-op. Interpreter (production route functions on real CPU pools,
ring vs intermediate, 2 layers, head ratio 3, 2 requests + padded row, track
crossing, second step after garbage cursors + heal): fp32 verify rel 3.7e-7 /
2.4e-7, commit (incl. track slot) 2.9e-7 / 3.1e-7 vs the recurrent route;
fp16 (bf16 stand-in) verify 5.0e-4 vs recurrent 3.8e-4 of the fp32 truth,
commit 3.6e-4 == recurrent 3.6e-4; conv rollback equal; untouched slots
bit-exact; cursors 0 after every commit. On the S2 sources: 7 failed + 3
errors.
Regression: test_replayssm_spec_ring_pool_s2 10, test_mamba_checkpoint_interval
58, test_dflash_mamba_track_post_verify_37818 5, test_conv_verify_private_
window_444 13, test_prefill_graph_stale_track_rows_34184 2,
test_weg2_prefill_only_capture_1233 15, test_forward_metadata_plan_record 9,
test_fused_replay_state_indices_32219 3, test_gdn_verify_strided_qkv_33778 4,
test_verify_intermediate_row_ownership_450 12, test_mamba2_conv_verify_
private_window_450 10, test_dual_group_concurrency 159 -- all passed.
ruff F: no new findings.

27B line (desk/27b-up-replayssm-line-0924): cherry-picked from 7d69bd8
(desk/27b-up-replayssm-0924, on the NF-based staging line fa757eb), clean.
gdn_backend.py and mamba2_metadata.py are identical on both lines;
dflash_worker_v2 differs here (sgl-project#31468, sgl-project#33459/sgl-project#30096 ports) but not in
_update_target_mamba_state_after_verify, so the DFLASH commit reaches the
shared hook exactly as on NF. One adaptation, text only: the commit
docstring listed "tail adopt" among the readers of `temporal` -- that is the
NF line's H21 install (weg2.tail_adopt), absent here; the 27B readers are the
radix insert, the HiCache backup (the weg2 L2 arena write, xsn351) and the
P/D flip.

Tests on this line (CPU, incg cgroup, S3 tree, one file at a time):
test_replayssm_spec_route_s3.py 10 passed -- interpreter, production route vs
the recurrent route: fp32 verify rel 3.74e-7 / 2.40e-7 (step 1 / step 2 after
garbage cursors + heal), commit incl. the track slot 2.94e-7 / 3.10e-7 (all <
4e-7); fp16 (bf16 stand-in) verify 5.03e-4 / 2.72e-4 vs recurrent 3.84e-4 /
2.55e-4 of the fp32 truth, commit 3.61e-4 / 3.27e-4 == recurrent; conv
rollback equal, padded outputs zero, untouched slots bit-exact, cursors 0
after every commit; test_replayssm_spec_ring_pool_s2.py 10 passed (8
subtests).

Regression (package tip = S6 tree, same cgroup, one file at a time):
test_dflash_mamba_track_post_verify_37818 5,
test_conv_verify_private_window_444 13,
test_prefill_graph_stale_track_rows_34184 2,
test_weg2_prefill_only_capture_1233 15, test_forward_metadata_plan_record 9,
test_fused_replay_state_indices_32219 3, test_gdn_verify_strided_qkv_33778 4,
test_verify_intermediate_row_ownership_450 12,
test_mamba2_conv_verify_private_window_450 10, test_dual_group_concurrency
159, test_mamba_checkpoint_interval 58 -- all passed.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 25, 2026
…ec ring

27B ReplaySSM package, slice S3 of REPLAYSSM_PLAN.md. With the flag off every
path is unchanged (no rows planned -> recurrent route, intermediate commit).

Ported: upstream GDNAttnBackend._replayssm_target_verify (same kernel call,
launch_mode="verify", null block -1, request rows as replay indices) and the
compact commit sequence of upstream's spec_utils (commit_gdn_replayssm_spec +
commit_gdn_replayssm_circular + conv-window rollback).

Adapted (this line's own wiring; upstream refuses GDN + DFLASH):
- ForwardMetadata.replayssm_spec_rows: the verify metadata plans the request
  rows (req_pool_indices) in all three builders (eager, graph capture, graph
  replay -- there the static buffer with padded rows zeroed). The commit reads
  the rows the verify used from the metadata, like mamba_cache_indices, so no
  caller changes: DFLASH (dflash_worker_v2 untouched), the EAGLE/MTP commit
  and the lane all go through update_mamba_state_after_mtp_verify.
- The commit sits in that shared hook (ring branch when intermediate_ssm is
  None). Linear chain -> accepted = last step + 1 (bonus included); -1 folds
  nothing, like the masked scatter.
- FOLD EVERY COMMIT for any SSM dtype (upstream defers the fold for fp32):
  radix insert, HiCache backup, tail adopt and the flip all read `temporal`
  and assume it is the committed state after every verify, as the recurrent
  route makes it. The ring is then per-step scratch (write_pos 0 at every
  verify).
- Heal: outside a capture the verify metadata re-states write_pos = is_flush
  = 0 for the step's rows (true by construction after every commit), so a
  verify never trusts cursor bytes from an earlier step (TMS restore, flip,
  reused row). cache_base is circular and harmless at write_pos 0.
- forward_extend routes the verify to the ring when rows are planned; a draft
  tree on the ring, or a pool with neither intermediate state nor planned
  rows, is refused. The ring kernel honours token strides, so the verify split
  stays torch.split views (sgl-project#33778).
- Advance cursor null block 0 (request row 0 is the ReqToTokenPool padding
  row); the widest verify window is kept on the pool as the advance's
  constant (one compiled variant across the adaptive ladder).
- Ring length must be >= 16 (the compact commit's tl.dot) -- pool and static
  check; S2 test moved to L=16.
- _replayssm_spec_for: a draft-KV-only producer (no verify workspace, sgl-project#1233
  FIX 4) treats the flag as a no-op instead of hitting the pool's
  missing-window refusal.
- getattr on the new metadata field in the two readers (sgl-project#624 stub drift:
  test_gdn_verify_strided_qkv_33778 doubles predate it).

Tests (CPU, incg cgroup, one file at a time):
test/registered/unit/layers/attention/test_replayssm_spec_route_s3.py: 10
passed. Hermetic: rows planned + healed (eager, replay; not in capture;
padded row -> row 0), flag off / decode plan nothing, the three refusals,
producer no-op. Interpreter (production route functions on real CPU pools,
ring vs intermediate, 2 layers, head ratio 3, 2 requests + padded row, track
crossing, second step after garbage cursors + heal): fp32 verify rel 3.7e-7 /
2.4e-7, commit (incl. track slot) 2.9e-7 / 3.1e-7 vs the recurrent route;
fp16 (bf16 stand-in) verify 5.0e-4 vs recurrent 3.8e-4 of the fp32 truth,
commit 3.6e-4 == recurrent 3.6e-4; conv rollback equal; untouched slots
bit-exact; cursors 0 after every commit. On the S2 sources: 7 failed + 3
errors.
Regression: test_replayssm_spec_ring_pool_s2 10, test_mamba_checkpoint_interval
58, test_dflash_mamba_track_post_verify_37818 5, test_conv_verify_private_
window_444 13, test_prefill_graph_stale_track_rows_34184 2,
test_weg2_prefill_only_capture_1233 15, test_forward_metadata_plan_record 9,
test_fused_replay_state_indices_32219 3, test_gdn_verify_strided_qkv_33778 4,
test_verify_intermediate_row_ownership_450 12, test_mamba2_conv_verify_
private_window_450 10, test_dual_group_concurrency 159 -- all passed.
ruff F: no new findings.

27B line (desk/27b-up-replayssm-line-0924): cherry-picked from 7d69bd8
(desk/27b-up-replayssm-0924, on the NF-based staging line fa757eb), clean.
gdn_backend.py and mamba2_metadata.py are identical on both lines;
dflash_worker_v2 differs here (sgl-project#31468, sgl-project#33459/sgl-project#30096 ports) but not in
_update_target_mamba_state_after_verify, so the DFLASH commit reaches the
shared hook exactly as on NF. One adaptation, text only: the commit
docstring listed "tail adopt" among the readers of `temporal` -- that is the
NF line's H21 install (weg2.tail_adopt), absent here; the 27B readers are the
radix insert, the HiCache backup (the weg2 L2 arena write, xsn351) and the
P/D flip.

Tests on this line (CPU, incg cgroup, S3 tree, one file at a time):
test_replayssm_spec_route_s3.py 10 passed -- interpreter, production route vs
the recurrent route: fp32 verify rel 3.74e-7 / 2.40e-7 (step 1 / step 2 after
garbage cursors + heal), commit incl. the track slot 2.94e-7 / 3.10e-7 (all <
4e-7); fp16 (bf16 stand-in) verify 5.03e-4 / 2.72e-4 vs recurrent 3.84e-4 /
2.55e-4 of the fp32 truth, commit 3.61e-4 / 3.27e-4 == recurrent; conv
rollback equal, padded outputs zero, untouched slots bit-exact, cursors 0
after every commit; test_replayssm_spec_ring_pool_s2.py 10 passed (8
subtests).

Regression (package tip = S6 tree, same cgroup, one file at a time):
test_dflash_mamba_track_post_verify_37818 5,
test_conv_verify_private_window_444 13,
test_prefill_graph_stale_track_rows_34184 2,
test_weg2_prefill_only_capture_1233 15, test_forward_metadata_plan_record 9,
test_fused_replay_state_indices_32219 3, test_gdn_verify_strided_qkv_33778 4,
test_verify_intermediate_row_ownership_450 12,
test_mamba2_conv_verify_private_window_450 10, test_dual_group_concurrency
159, test_mamba_checkpoint_interval 58 -- all passed.

NF line (H64, onto 88dec66): one conflict, resolved line by line in
gdn_backend.forward_extend. This line carries no sgl-project#33778 port (no
kernel_dispatcher.target_verify_supports_strided_qkv), so the 27B hunk that
widens use_strided_verify_qkv for the ring has nothing to widen. Kept the NF
condition `(is_cuda() or is_hip()) and qkv_dim <= MAX_FUSED_QKV_SPLIT_DIM`:
the ring verify gets the same q/k/v preparation as the recurrent verify on
this line (dense [1, T, H, D] from fused_qkv_split_gdn_prefill on CUDA,
torch.split views elsewhere); _replayssm_target_verify flattens both layouts
by numel. Text only: the commit docstring names the NF H21 tail adopt
(weg2/tail_adopt.py reads and installs cache.temporal) among the readers of
temporal again -- the 27B line had dropped it because it lacks H21.
Tests (CPU, incg cgroup, one file at a time): test_replayssm_spec_route_s3.py
10 passed; test_replayssm_spec_ring_pool_s2.py 10 passed (8 subtests).

(cherry picked from commit 974254d)
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 26, 2026
…cks, chronologisch)

Grundlage: Präsenz-Scan aller 230 27B-Commits seit 76f8deb gegen diesen Baum
(Stichprobe der hinzugefügten Zeilen je Commit); die 94 fehlenden minus die bewusst
anders gewählten Formen (76e87ac/4ae11ababd -> S3 form.calibration_identity;
479f6ec/d7f588e017/d0fba8955f/34892e3017 -> S2 NF-Formen; 7f81f09/3c14481318 ->
S4/S7a; 3dbb790 line_gate_27b (Werkzeug, Schritt 9); 8604d13 W100-by-name
(Nutzer: bleibt aus); 6545e2c flashinfer-Pin in pyproject (Image-Frage, nicht Baum)).
Liste: 92bbccb eb5d044 829ebd0 431fcbc ef4d11f 6816062 a233e50 2cc593c f0c8451 87cc4fb c529777 31f2dbe c50085a 3301a96 036b368 e1d1fe9 03c68af 6dddc2e 06932b5 87389c4 58a7490 f85ac55 fc64aa5 5aa24dd 97c0e9a 159333c d9f1532 f3c685b 8550655 e50fb59 db2c2ef f09dc0d c255e10 51b810e 28a55a2 34965fc ff3d9cc 340a018 bee5e10 67b6352 fdade85 ed6630d f1c9a43 b434831 517f26d 0b6b60b a40837f 644de86 aff2b7c 197b701 856024b 238512a 9738626 b857a22 1f8c24d d294b3e 810239d b429dfd e714c95 9efd974 3d63e0a d3cfcf3 fee6134 7985b56 49a14e9 fc45706 19c720e 5306bee 6f1235a c98eaa3 93bc802 328349e f9fb3a2 572af73 94fa8b4 d342caa 2fd7d7e 3ebbb96 871d55f 78c2f16 3babf51 196f6a8 e70af54 22eccfc

Inhalt: Upstream-Ports (sgl-project#33758 sgl-project#37818 sgl-project#36738 sgl-project#33459/sgl-project#30096 sgl-project#34446 sgl-project#36267 sgl-project#33778 sgl-project#34859
sgl-project#36415 sgl-project#35255/sgl-project#36638 sgl-project#39858/sgl-project#40259 sgl-project#31417 sgl-project#34892 sgl-project#32225 sgl-project#30832/sgl-project#36626 sgl-project#39574 sgl-project#29579
sgl-project#31468 sgl-project#32575 sgl-project#31648); xsn409/410-Wake-Verdikte; Vision-Linie V1-V3b + xsn438
(SGLANG_WEG2_VISION_FLIP_URGENT); D-Planer L6 (159333c); DFLASH-Window-Pool
sync-frei, PLAN_SYNC_FREE, D-Kollektive (vocab-argmax, a2a-Merge, deferred rebuild),
#DGAP/D_DEFER_SEQ_LENS_CPU; Mamba-Anker Raster 4096 + Per-Path-Cap + Inner-Release;
P-TRIM (--p-trim-end-anchor); FP8 uniform Marlin; ModelOpt/NVFP4 RadixArk; GGUF G1-G6
+ F1/F2; native-mixed sgl-project#38 (sm_8x W4A8, sm_12x CUTLASS/W4A16); RC1-Capture-Set; sgl-project#49
Agent-Turns; dynchunk (--p-chunk-policy, --p-chunk-dynamic-min-tokens).

Auflösungen (Gabel -> Form, Grund):
- L6 d_operating_point_rows: 27B (d) "Token-Vektor auf jeder Position aus der Kapazität"
  nur bei TP-symmetrischem D (Profil d_layout paged_dcp); sonst NF-sgl-project#1293-Pin + NF-Anker-
  Klausel. mamba_ssm_dtype aus EARLY_READ_FACTS nur bei Profil early_read_flags.
  Overhead-Kalibrierung liest mit form.CalibrationIdentity statt LineIdentity.
- RC1 Capture-Set: neuer RecordKey-Term d_capture_set (qwen27b), Leser
  CalibrationIdentity.d_max_running_requests; nextflash unverändert.
- URC Carrier-Hold: 27B _weg2_carrier_hold entfällt (S2 NF-Rotation), Inner-Release und
  Per-Path-Cap bleiben (Env, Default aus; 27b.env setzt sie).
- scheduler_pp_mixin/overlap_utils/batch_result_processor: NF H49/H58 und 27B #PGAP/#DGAP
  komponiert (beide Instrumente getrennt schaltbar).
- schedule_policy: P-TRIM-Kurzschluss vor NF H63-Fold/QSA-Korn; sgl-project#36415 Hoist + NF
  computed_input_len.
- gdn_backend sgl-project#33778: 27B-strided-Verify; NF-Ring flacht beide Layouts ab.
- flashinfer_backend: RC9-Datei + NF-Form-A-Waiver (27B-intern mehrfach gegabelt).
- checkpoint_census: GGUF-Leser + NF exclude_segments (PLE) in einer Aggregation.
- xchg_manifest: FLAT_SEGMENTS in beiden (dst/src) NF-Breitenbedingungen ausgenommen.
- vram_peak_window: NF-Kumulativ-Peak liest über den 27B-Fast-Read.
- FP8: 8c86eb8-Rest nachgezogen (private Workspace-Registry entfernt, wie RC9).
- argv_d: vision= an allen drei Aufrufstellen (inkl. NF --d-only).
- census_checkpoint_decision (W161) jetzt für beide Profile aktiv.

Gates: py_compile aller geänderten Dateien; ruff F821/F811 ohne neue Funde gegenüber
dem Vorgänger (PendingSeqLensCpu ist String-Annotation wie in RC9); dup_defs_gate 0 neu.
Tests: 73 portierte Testdateien, Lauf nach dem Ruhefenster (Boot aktiv).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blackwell SM100/SM120 run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants