Repository navigation
Drafter: exact snapshot-free GDN verify (fold-every-commit) for DFlash and MTP, with its exactness and timing jobs - #133
Conversation
engine/sglang/patches/drafter/0002 lets --enable-linear-replayssm-spec run with DFLASH on Qwen3.5 (GDN): DFLASH commits through update_mamba_state_after_mtp_verify, which now has the GDN circular-ring commit that EAGLE/MTP already reach through spec_utils. run_replay_check.sh compares it against stock DFlash verify on panel-v2 at concurrency 1 and 8 (tokens and top-5 logprobs, bitwise), and compare_outputs.py reports bitwise identical sequences and the first logprob difference.
…at start with dashes serve_run.py --extra must be written --extra=<flags>: argparse read '--extra --disable-radix-cache' as a missing value, which killed the first data-generation segment. Same fix in the replay check.
… arm in the replay check SGLang implements a fold-every-commit buffered verify for GDN whose verify is the recurrent kernel itself and whose commit is a bitwise clone of the recurrent update, but enables it only for KDA. Patch 0003 enables it for GDN behind SGLANG_GDN_REPLAYSSM_FOLD=1. run_replay_check.sh now compares stock DFlash verify with both buffered variants (compact circular replay and fold).
…d its summary run_phase_timing.sh times DFlash block 16 with the repair workstream's CUDA-event phase probe applied on top of the drafter engine series, at matched flags, and captures the GDN kernels each arm runs; phase_summary.py reports per-phase medians, the cycle period and each phase's share (the commit phase is what P10 could remove).
…er slot The ring-writing verify and the fold both index the raw ring by the physical mamba slot, so the rings are sized and budgeted per slot (as for KDA), not per active request as the compact circular replay is.
With GPU_STARTUP_MIN_FREE_GB=n the script takes the start-up lock, reads the GPU's free memory from nvidia-smi and runs the command only if at least n GiB are free; otherwise it releases the lock, waits GPU_STARTUP_RETRY_WAIT seconds (default 60) and retries up to GPU_STARTUP_TRIES times (default 30), then exits 75 without running the command. Unset, the script still execs flock -o as before. The lock descriptor is closed for the command, so a background server never holds it. CPU tests fake nvidia-smi on PATH.
…s at every first divergence
…s from free memory)
…nd the exactness table
…nistic batched waves (accept_probe --waves)
…walk (selector_rewalk.pt)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 332b68a71b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| compare( | ||
| 'fold verify output', stock_out, out_fold.reshape(batch * T, HV, V) | ||
| ), | ||
| compare('fold committed state', stock_committed, fold_committed), |
There was a problem hiding this comment.
Fail when fold parity comparisons differ
When either the fold verify output or committed-state comparison is not bitwise equal—for example after a kernel regression or on a different GPU—this script merely prints the mismatch, writes gdn_verify_parity.json, and exits successfully. Consequently, run_replay_check.sh never enters its parity-failure branch and leaves a failed result looking like a completed check. Return a nonzero status and avoid the final JSON unless the first two fold checks pass; the circular mismatch should remain informational because it is expected.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 0159c13, with one deliberate difference: a fold mismatch is a result worth keeping, so the JSON is still written, now with fold_bitwise_in_every_case, and the script exits nonzero unless both fold comparisons (verify output and committed state) are bitwise equal in every case; the circular comparison stays informational. run_replay_check.sh deletes any older JSON first and logs "KERNEL PARITY FAILED" on a nonzero exit, so a failed check can no longer look complete. The committed parity file passes the new rule (all 18 fold comparisons bitwise in its 9 cases).
…ock in every case, and record it in the JSON (Codex on #133)
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
… fold at c = 8 and 16; P10's gate is not met
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…ication in served DFlash and MTP (run_fold_localize)
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Verdict: REQUEST CHANGES (79eec25, 4 blocking, all small; the substance checks out) Checked and right
Blocking
Still to run on the fix head: Codex has not reviewed 79eec25 (its last review is of c0ee7ba). |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 79eec25f76
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| + if mamba_pool is None or getattr(mamba_pool, "replayssm_is_kda", False): | ||
| + return False | ||
| + fold = getattr(mamba_pool, "replayssm_spec_fold", False) | ||
| + if not fold and getattr(mamba_pool, "replayssm_cache_base", None) is None: |
There was a problem hiding this comment.
Gate the DFlash commit on speculative ReplaySSM
When a GDN DFlash server enables ordinary --enable-linear-replayssm but leaves --enable-linear-replayssm-spec off, replayssm_spec_fold is false while the live-replay pool can still have replayssm_cache_base (_replayssm_on is enabled by either flag later in this patch). This condition therefore enters the new speculative commit, returns before the stock intermediate-state scatter, and consumes a ring that target verify did not populate, potentially committing stale state or failing. Check mamba_pool.enable_linear_replayssm_spec before accepting either the fold or cache-base path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid; fixed by a new engine patch, drafter/0004 (engine 761d69deb3, in 1e3e647): the DFLASH commit hook returns False (so the stock intermediate-state scatter commits) unless the pool has enable_linear_replayssm_spec, before either the fold or the circular path. 0001-0003 are unchanged, so the committed runs (all at 31bda3e674, each with both ReplaySSM spec flags or with none) are reproducible as recorded; the engine README and evidence README say the gate changes nothing in those configurations. A served check of DFlash with decode-only --enable-linear-replayssm against stock DFlash (deterministic waves of 4) is added to the follow-up PR's queued shared check, which runs on an engine that includes 0004.
| limits = {p.get('effective_max_running_requests_per_dp') for p in pools.values()} | ||
| summary: dict[str, Any] = { | ||
| 'source': str(args.root), | ||
| 'base': args.base, | ||
| 'test': args.test, | ||
| 'pools_by_run': pools, | ||
| 'running_limit_match': len(limits) == 1, |
There was a problem hiding this comment.
Scope running-limit matching to each A/B group
run_fold_timing.sh deliberately places the b16 group (running limit 64) and b8 group (running limit 128) under one root, but this computes one global set across both groups. Consequently the committed summary reports running_limit_match: false even though stock and fold have matching limits within every comparison group. Compute the match per group, then aggregate those per-group results, so legitimate differences between independent groups are not reported as an A/B mismatch.
Useful? React with 👍 / 👎.
| writer = csv.DictWriter(handle, fieldnames=fields) | ||
| writer.writeheader() | ||
| writer.writerows(rows) | ||
| args.out.with_suffix('.kernels.json').write_text(json.dumps(kernels, indent=2) + '\n') |
There was a problem hiding this comment.
Write the kernel summary to the documented artifact
run_phase_timing.sh passes $out/summary, so with_suffix('.kernels.json') produces phase_timing/summary.kernels.json; however, the committed and documented artifact is phase_timing/kernels.json. Rerunning the documented job therefore does not regenerate that file and can leave stale kernel evidence in place. Write the sibling kernels.json path or align the runner, README, and committed artifact.
AGENTS.md reference: AGENTS.md:L15-L18
Useful? React with 👍 / 👎.
|
Update to my verdict on 79eec25 (still REQUEST CHANGES): Codex's three comments on this head are valid. Add them to my four items.
|
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Verdict: APPROVE (2eef679) 1e3e647 and 2eef679 resolve all seven items from my review of 79eec25: my four, plus Codex's three.
|
…cted by its gate (#133) From evidence/drafter/README.md (buffered GDN verify sections) and buffered_verify/, phase_timing/, fold_timing/ (#133): - kernel parity: the fold's verify output and committed state are bitwise equal to the stock verify's in all nine cases; circular replay differs in 19-20% of BF16 words; - served, matched pools: bitwise equal to stock verification for MTP s3 on all 80 sequences at c = 1, DFlash b16 on the 8 requests rerun at c = 1 (radix on), and both on all 80 in fixed-composition batches of 4 and 8 (radix off); no bitwise claim for closed-loop c > 1; - held batches: cycle 8.6% shorter at batch 8, 11.9% at 16; - served A/B, one session on both tuned DFlash arms: +5.8-6.1% at c = 8, +8.2-9.4% at 16, +11.8-12.0% at 32; -3.2% at c = 1 on block 16 and -1.4% on block 8 (likely value-tile cause, untested); - P10 rejected without building: the fold is 4.9% and 6.6% of the cycle at c = 8 and 16, below its 9.09% gate. New paragraph in App F.8, P10 status row (P11's row updated), a levers table row, evitem drafter-fold; the p10-split devitem goes.
Appendix F: exact fold-every-commit verification for DFlash; P10 rejected by its gate (#133)
…ull; at most five sessions Codex on 84717d2: the certified-head package's fingerprint is now part of the identity the equality hold's preflight records before any run, and build and every later check require it unchanged. The reused stock references must match bench's declared configuration (flags with and without Triton attention, c1 pass, concurrency 1, 256 new tokens, top-5 logprobs, 320 prompts, cold cache, S0's model and prompt set with the same prompt token counts), as must every stack equality run; the prompt file is pinned by hash from preflight to build. analyze.py accepts sessions stack-s1 to stack-s5 only (three and at most two replacements). expected.py's H note and the engine README reflect the merged #45/#52 and #133. Tests for each (98 pass).
Stock DFlash and MTP verification on Qwen3.5-4B writes one FP32 GDN state per block position per request, so that a rejected suffix can be rolled back: 48 MiB per position, 16 positions per request per cycle at DFlash block 16. SGLang already implements a snapshot-free alternative for KDA models, fold-every-commit: the verify runs the ordinary recurrent kernel, which also writes the raw per-token inputs to a ring, and the commit replays the accepted prefix into the checkpoint with a bitwise clone of the recurrent update. At the pin (bd66ce343e) it is disabled for GDN pools and for DFLASH. This PR enables it, checks whether it is exact against the stock verify, and adds the jobs that time it.
Status: complete. Exactness, the per-phase split and the served A/B on the tuned arms are all in. This PR will be updated as the queued runs land; it should not merge before they do.
Engine patches (
engine/sglang/patches/drafter/)0002 lets
--enable-linear-replayssm-specrun with DFLASH on GDN models, with SGLang's default GDN circular ring (compact records, chunked reconstruction). It is not bitwise (below) and is not proposed as a lever; 0003 reuses its commit hook.0003 adds
SGLANG_GDN_REPLAYSSM_FOLD=1: with--enable-linear-replayssm-spec, GDN pools use the fold-every-commit protocol, for DFLASH (its direct commit hook) and for EAGLE/MTP (throughspec_utils.commit_mamba_states_after_verify). The rings are indexed and sized per mamba slot, as the fold kernel expects.0004 (added after the runs, from Codex's review) takes the DFLASH commit hook only under
--enable-linear-replayssm-spec: plain--enable-linear-replayssmalso allocates replay rings, and without the gate a DFLASH server with only that flag would commit from a ring its verify never wrote. It changes nothing in any configuration measured here.All are off unless their flag is set. Applying 0001-0003 to bd66ce343e reproduces the tree of
engine/drafterat 31bda3e674 exactly (checked withgit am), which is the engine of every run in this PR; 0004 is engine 761d69deb3.engine/sglang/README.mdhas the apply commands and one row per patch.Exactness so far (
evidence/drafter/README.md, "Buffered GDN verify: exactness")gdn_verify_parity.py, random BF16 inputs at the 4B GDN shape, batch 1, 8 and 16, three seeds, random accepted lengths): the fold verify output and the folded state are bitwise equal to the stock verify output and its intermediate state at the accepted position in all nine cases, even though the stock verify launches value tiles of 4 and the ring verify tiles of 32 on sm_90. The circular verify differs in 19-20% of BF16 output words (at most 2.4e-4 absolute).run_fold_localize.sh, c0ee7ba; README "Matched pools and deterministic batching"). DFlash at c=1 with the per-cycle trace, eight requests (the four that differed plus four controls) at two pinned pool sizes: the fold equals stock in every token, top-5 logprob and every cycle's drafts, target argmax and accepted length. Both of today's arms reproduce the first check's stock run and differ from its fold run at the same four requests, so those differences followed that fold server's pools, not the fold. Deterministic batched waves (radix off): DFlash in waves of 4 and MTP s3 in waves of 8 are bitwise equal to stock on 80 of 80 sequences each, as are the stock reruns. With a closed-loop client above c=1 stock does not reproduce itself bitwise, so no claim is made there.Timing
Per-phase split (measured,
run_phase_timing.sh, 52d3882; README section "per-phase split and the P10 gate"). DFlash block 16, Triton GDN verify, identical pinned pools, one exclusive hold, one run per arm, GPU-timeline medians at a steady batch. The fold shortens the cycle from 10.83 to 9.90 ms at batch 8 (-8.6%) and from 15.37 to 13.54 ms at batch 16 (-11.9%): the verify loses 1.10 and 2.16 ms of per-position state writes and the commit gains 0.22 and 0.38 ms for the replay. Its tokens equal stock's on all 66 requests at both concurrencies (closed-loop runs, no logprobs; not the bitwise check). The fold phase is 4.9% and 6.6% of the cycle, below P10's 9.09% gate at both, so P10's anchor-fused replay is not built.Served A/B on the tuned arms (measured,
run_fold_timing.sh; README section "served A/B against the tuned DFlash arms"). One session: a single stock, fold, fold, stock sequence per arm in one exclusive hold (two runs per arm, n = 1 ABBA per point), bench confirm split, 512 tokens. Fold/stock in output tokens/s per GPU, with the range over the four run pairs, which is a within-session spread, not a confidence interval:dflash-tuned-b16dflash-tuned(b8)At c=1 the fold is slower: 3.2% on
dflash-tuned-b16, the c=1 leader (848 against 876 tokens/s), and 1.4% on block 8; at c=2 it is 1.7% slower on block 16. From c=8 up it is faster on both arms in this session (5.8-6.1% at c=8, smallest pairwise ratio 1.0498; 8.2-9.4% at 16; 11.8-12.0% at 32). Likely cause of the low-concurrency loss (code reading, not measured here): the ring-writing verify keeps value tiles of 32, while the stock per-position-state verify uses tiles of 4 for at most 64 sequences on sm_90; the kernel check found the two tilings bitwise equal on this GPU. The follow-up engine patch drafter/0004 selects the narrow tiles for the ring-writing verify; it is a separate PR, not part of this one.Also on this branch
evidence/drafter/timed_panel/): per-request tokens and milliseconds per cycle for blocks 16 and 8, one exclusive run.serve_run.pytakes the start-up lock with a free-memory gate and records the resolved pools;accept_probe.py --waves;compare_outputs.pycounts bitwise-identical sequences and now imports the state comparison together with its sibling module (it failed on main's currentexperiments/state_safety/compare.py);support_screen.py --selectorandrun_selector_rewalk.shfor P6's selector walk and P9's corrected re-walk (code only; no selector checkpoint exists yet).experiments/drafter/README.mdlists every file in the directory (the organization pass found 15 of 27 missing).Testing
pytest tests/test_drafter_tools.py: 6 passed, 1 skipped (the skipped test needs torch, which the repository venv does not have).evidence/drafter/README.md.Review comments
Codex (4791838), A/B summary read pools from the top level of
/server_info, where the running limit is absent: fixed in 9db308b (mergesinternal_states[0]first; test added).Codex (4791838),
fold_localize.pymissed strict-prefix differences: fixed in 9db308b (first_differencereturns the shorter length; cycle-count differences reported; test added). (The queued localize job was later resubmitted to run the fixed scripts; see the last item.)Codex (9db308b), four comments, all fixed in bbfad39 with tests: the selector re-walk overwrote the request counter (P1; the re-walk has not run yet); A/B ratios now exclude points bench's
invalid_reasonrejects; untraced first-check runs are compared by outputs only (--earlier), and cycles only when both runs are traced;compare_outputs.pyrecords strict-prefix logprob differences (no committed equality file changes: identical plus recorded sequences already sum to 80 in each, and two were regenerated to confirm).Codex (bbfad39), two comments, fixed in 22b9a0e: each localize run starts from an empty directory (append-mode traces); the phase-timing profiler runs on a separate server and
phase_summary.py --segmentssplits the timing log into client runs. Both queued jobs were resubmitted at their original queue arrivals from a worktree at 22b9a0e, so their outputs come from the fixed scripts.Codex (22b9a0e), two comments on
run_replay_check.sh(already run, not queued again), fixed in 332b68a: an older parity JSON is deleted before the kernel check; the MTP half writes to OUT-mtp.Codex (332b68a), parity check exited 0 on a fold mismatch: fixed in 0159c13 (nonzero exit unless both fold comparisons are bitwise in every case;
fold_bitwise_in_every_caserecorded; the committed parity file passes).Reviewer (79eec25), four items, fixed in 9d984d8/1e3e647/2eef679: main merged (Files-table conflict resolved;
drafting_requirement.pyfrom Drafter: the per-position acceptance a block drafter needs for 5x (derived from committed evidence) #134 listed);running_limit_matchper group; the two overstatements corrected (smallest pairwise ratio at c >= 8 is 1.0498; the block-8 c=4 fold run at 4.80 tokens per cycle named); the A/B stated as one session with the c=1 regression in plain words, here and in both READMEs.Codex (79eec25), three comments: the DFLASH commit gate (P1) is the new patch 0004; running limit per group (as above);
phase_summary.pywriteskernels.json, the committed name, and regenerating both phase files with the committed code reproduces them byte for byte.