Skip to content

Repair oracles: Stage A refutes P3's two-pass design; recycling does not help DFlash - #56

Merged
SamMausberg merged 15 commits into
mainfrom
repair/oracles
Oct 1, 2026
Merged

SamMausberg merged 15 commits into
mainfrom
repair/oracles

Conversation

@SamMausberg

Copy link
Copy Markdown
Owner

Oracle kill tests for PROPOSALS.md P2 (long-window exact repair) and P3 (target-anchored residual decoding). This PR carries the measured Stage A oracle and the one-step recycling result, the engine probes and drivers behind them, and the code for the remaining tests (exact Jacobi sweeps, decision-level anchored evaluator), whose runs are queued on the GPU. Results will be added to this branch as they land.

Results so far

Stage A, perfect continuations at width B (evidence/repair/stage_a_timing.json, stage_a_oracle.{json,csv}). GH200, concurrency 1, DFlash-4B with the drafter workstream's trace flags, verification forced to accept every B-token block (SGLang's SGLANG_SIMULATE_ACC_LEN), eight MATH-500 problems of 2,048 tokens:

B verify V(B) ms DFlash draft ms commit ms cycle ms tokens/s
16 4.78 2.40 0.11 7.60 2,102
32 7.30 2.51 0.12 10.25 3,119
64 15.62 2.53 0.12 18.61 3,436
128 28.10 2.71 0.12 31.32 4,084
256 44.82 3.21 0.14 48.62 5,260

Stock DFlash at block 16 on the same problems commits 7.68 tokens per 7.46 ms cycle (970 tokens/s); prefill and scheduling take f = 2.3% of a request, so 5x end to end needs 5.5x in decode.

  • P3 Stage A: refuted. The anchor-plus-audit design with free repair reaches at most 2.9x DFlash's decode rate (2.8x end to end) at any B, because it pays two verify passes of this cost. Per-position state writes inside V(B) are bounded by their bytes in this table; a measured split is queued.
  • P2 Arm A: 5x only at B = 256 with zero drafting cost (derived from measured V(B)). An ideal drafter whose blocks are always accepted reaches 3.2, 4.2, 4.0, 4.4 and 5.5x in decode (5.0x end to end only at B = 256); paying DFlash's own drafting cost at width B, perfect blocks give at most 5.1x in decode and 4.7x end to end.
  • The binding constraint is SGLang's verify pass: past B = 16 it grows about 0.167 ms per extra token, roughly five times what that token's GEMM work and 48 MiB per-position FP32 state write account for. From the code, the FlashInfer GDN verify kernel at one request walks the T positions sequentially in 512 CTAs per layer; the queued nsys and no-state runs test that prediction (written down in advance). A block-parallel exact GDN verify is moonshot's P7; this workstream will not build a second one.

One-step recycling on the shared DFlash trace (evidence/repair/one_step_recycling.json, draft_source_accuracy.csv). At the 18,525 cycle boundaries after a rejection (block 16), drafting the next block from the previous verify pass's target predictions accepts 0.52 drafts on average, against 4.44 for the fresh DFlash draft; keeping the previous draft's tail gives 1.11, and the best of the three chosen with hindsight 4.55 (+2.5%). Block 8: 0.45, 1.15 and 3.30 against 3.21. The target's prediction after a wrong draft token matches the continuation 14% of the time once that token is corrected (DFlash's first drafted token: 84%). This is the P2 Arm B sliding-recycling result; multi-sweep exact Jacobi is queued.

What is in the PR

  • engine/sglang/patches/repair/0001: env-gated probes in SGLang's DFlash worker (CUDA-event phase timing without host syncs, reference-continuation injection, recycle/keep policies, and a probe mode that re-verifies the same prefix k times with the GDN conv/SSM state restored and checks the restored pass reproduces the first pass bit for bit; 0 mismatches in 66 smoke cycles). 0002: a timing-only switch that verifies without per-position GDN states. All off by default.
  • experiments/repair/: serve_probe.py (one server per run, startup lock, foreign-CPU recording), panel.py, analyze_timing.py, stage_a.py, analyze_jacobi.py, residual_eval.py (fixed-basis anchored evaluator on the HF model, two cascading replays against the original anchor, R_i, hazards, free-running repair audited exactly), summarize_residual.py, p3_gate.py (Sam's economic gate with a bytes-only repair-cost lower bound), nsys_kernels.py, gdn_state_bench.py, and the GPU session scripts in runs/.
  • evidence/repair/README.md: exact commands, configuration and provenance.

Exactness

Every committed token is a target-verified token; the probes never commit approximate state. Forced-acceptance runs commit meaningless tokens by design and are used only for cost. The exactness comparison of the policies against plain decoding (top-2 logprobs) is queued.

Not yet in this PR

Measured split of V(B) (no-state verify, nsys at B = 64/256); exact Jacobi sweeps at B = 16/32/64; decision-level anchored evaluator and the P3 economic gate; reference-continuation acceptance at each width and timed policy runs; output-equality check. The ReplaySSM spec protocol refuses DFlash on this model ("requires a KDA model"), and the GDN kernel microbenchmark stalled in kernel compilation, so neither contributes numbers.

Samuel Mausberg added 13 commits September 30, 2026 21:40
engine/sglang/patches/repair-0001 adds env-gated probes to SGLang's DFlash
worker (per-cycle GPU phase timing, reference-continuation injection, Jacobi
recycling policies, and exact Jacobi sweeps from the same committed prefix).
experiments/repair/ drives them (serve_probe.py), builds the checkpoint
panel from the drafter's shared DFlash trace, times GDN state handling at
wide blocks, derives the Stage A oracle table, analyses Jacobi progress and
evaluates a fixed-basis anchored residual evaluator at the decision level.
At boundaries after a rejection, drafting the next block from the target's
suffix predictions accepts 0.52 drafts on average at block 16 (0.45 at
block 8) against 4.44 (3.21) for the fresh DFlash draft.
…racle

Forced full acceptance at B = 16..256 on GH200 (c = 1): the verify pass
takes 4.8, 7.3, 15.6, 28.1 and 44.8 ms, so a perfect drafter reaches at
most 5.5x DFlash's decode rate (5.0x end to end) at B = 256 and the
two-pass anchor-plus-audit design at most 2.9x (2.8x end to end).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T00:51:01.912706Z a5b4d82 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a5b4d82d02

ℹ️ 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".

Comment on lines +138 to +144
elif not g and args.state_bytes_bound:
states = B * 24 * 32 * 128 * 128 * 4 / (write_tbps * 1e12) * 1e6
state_source = 'bound: per-position state bytes at the HBM write rate'
replay_a = med(g, 'replay_a', 'median_us')
if verify is None or commit is None or period is None:
continue
v0 = verify - (0.0 if replay_protocol else states)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use a valid lower bound for the P3 anchor pass

When the committed --state-bytes-bound path is used, states is only the theoretical minimum time required to write the state bytes; the actual state overhead may be much larger. Subtracting that minimum from verify therefore produces an upper bound on v0, yet v0 is added to the P3 cost and the resulting speedup is presented as a ceiling that refutes P3. Until a no-state run measures this term, a cheaper anchor pass remains possible, so the reported 2.9x maximum and Stage A refutation do not follow from these data.

Useful? React with 👍 / 👎.

Comment thread experiments/repair/p3_gate.py Outdated
Comment on lines +122 to +123
max_extra = B - 1 - a0 + 1
rigorous = audit_us / max_extra >= per_token_base

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Subtract the anchor's already-committed bonus token

For an anchor acceptance of a0, the anchor has already committed a0 + 1 tokens, while a width-B audit can commit at most B tokens (B - 1 accepted drafts plus its bonus). The maximum incremental gain is therefore B - a0 - 1, not B - a0; the extra token here understates audit_us_per_max_extra_token and can incorrectly mark the rigorous P3 rejection as passing near the threshold.

Useful? React with 👍 / 👎.

Comment thread experiments/repair/stage_a.py Outdated
Comment on lines +174 to +175
'gate_lower_us_per_token': (verify + commit) / (B + 1),
'gate_rejects': (verify + commit) / (B + 1) >= per_token_base,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Divide the gate cost by at most B committed tokens

A width-B DFlash candidate has acceptance lengths 0..B-1, so even full acceptance commits only B tokens; this is also the assumption used by s_a above and is confirmed by the forced-run commit_per_cycle values. Dividing by B + 1 understates the verify-and-commit cost per token and can turn a gate that should reject into gate_rejects = false.

Useful? React with 👍 / 👎.

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: REQUEST CHANGES

Reviewed head a5b4d82 against main at 565d253. The measurements are sound. stage_a_timing.json reproduces field for field from the raw runs, and stage_a_oracle.{json,csv} reproduces exactly from it. The P3 Stage A verdict survives once it is stated against a valid bound. The blocking items are in how the verdict and its evidence are written into the repository, plus three Codex comments.

Checked and correct

  • Timed runs had tracing off (integrator check 3).
    • The engine for every timed run is 101e52731b, which is bd66ce343e plus repair 0001 only. The drafter's cycle-trace patch, with SGLANG_DFLASH_TRACE_PATH, is not in it.
    • Every timed run's probe_env has only SGLANG_SIMULATE_ACC_* and SGLANG_REPAIR_TIMING_LOG; SGLANG_REPAIR_TRACE is unset.
    • The timer resolves CUDA events lazily with Event.query(). It calls synchronize() only on an event that has already completed, or when 255 records are pending.
    • Forced acceptance is device-side fills (dflash_utils.py:950-980).
    • "Drafter-trace flags" therefore means the server configuration (backends, overlapped plan stream, no tc_piecewise, stream interval 4), not tracing.
  • Foreign CPU load (check 4). During the runs it was 0.18-0.55 cores (foreign_cpu_during, not contaminated).
  • Per-cycle spread (check 4). The spread within each session is small. For example, V(256) has p10-p90 of 44.73-44.92 ms over 72 cycles, and V(16) has 4.75-4.84 ms over 1,032. Each width is one server session of 8 requests; see the suggestions.
  • Patches (check 5).
    • 0001 is env-gated: RepairProbe.enabled is true only if one of its variables is set, and every hook checks it.
    • 0001 applied at bd66ce343e equals 101e52731b, and 0001-0002 equals 5d8e00e3e1.
    • engine/sglang/README.md has a ## repair section, but see B4.
  • PR-body numbers match the files.
    • V(B), draft, commit, cycle and tokens/s (gpu_decode_tok_s medians).
    • 7.68 tokens per 7.46 ms, and f = 2.28%.
    • S_b at most 2.90 in decode and 2.78 end to end.
    • S_a 3.17/4.19/3.95/4.41/5.53.
    • S_a_real at most 5.12 and 4.68.
    • The verify slope of 0.167 ms per token from B = 16 to 256.
    • Recycling: 18,525 pairs; 0.52, 1.11 and 4.55 against 4.44 at block 16; 0.45, 1.15 and 3.30 against 3.21 at block 8; position-1 accuracy 14.1% against 84.4%.
  • Pre-commit passes on all changed files.

Blocking

B1. The 2.9x "ceiling" uses an upper bound where it needs a lower bound. The P3 verdict still holds, but only stated against the right bound (Codex P1 on stage_a.py:144; integrator check 2).

  • Why 2.9x is not a ceiling. V0 = V - states, and states is a byte bound at 3.0 TB/s, which is a lower bound on the state-write time. So V0 is an upper bound on the anchor pass, and 2.9x is an estimate, not a ceiling.
  • Measured part. In P3's formula as the code implements it, C_audit + C_state = V(B) + commit(B) is measured whole, whatever the split. Only C_anchor = V0 + anchor_write depends on the split.
  • A valid bound. V0 is at least the weight read of a full target pass, 8.41 GB at 3.79 TB/s = 2.22 ms. With that, S_b(256) <= 256 x 971.6 / (2,219 + 337 + 44,824 + 144) = 5.23x in decode, which is 4.77x end to end. That is below 5x. Even with V0 = 0 it is 5.49x in decode and 4.98x end to end. So with SGLang's per-position state protocol, the refutation does not depend on the split, and B = 256 is the best case.
  • Where it does depend on the split. Under a protocol where the audit pass also skips per-position states (boundary replay), S_b(256) = 248,721 / (2 V0 + 481). That reaches 5.51x only if V0 <= 22.3 ms, that is, if per-position state writes are at least 50% of V(256), against 9.6% under the byte bound. ReplaySSM did not start for DFlash, so this case is untested, and the queued no-state run (patch 0002) decides it.
  • Fix.
    1. Report the weight-floor ceiling (or the V0 = 0 one) as the ceiling behind "refuted", and present 2.9x/2.8x as the estimate under the byte bound.
    2. State the boundary-replay condition explicitly.
    3. In stage_a.py, label V0 and S_b as estimates, and add the bounded column.

B2. The repository has neither the verdicts nor the pre-registered rule (evidence/repair/README.md; integrator checks 1 and 6).

  • The README gives method and commands only. The Stage A table, the P3 verdict, the P2 Arm A figures and the recycling numbers appear only in the PR body.
  • The README cites "PROPOSALS.md P2 ... and P3", which is not in the repository; it lives in the coordination directory, which committed files must not cite.
  • Fix: add a results section to evidence/repair/README.md with:
    • P3 Stage A: quote the pre-registered rule as stated on 2026-09-30, before measuring: "perfect continuation blocks at B = 32/64/128/256 with free repair: S_oracle(B) = B C_D / (A_D (C_anchor(B) + C_audit(B) + C_state(B))); if it cannot reach the target end to end, stop the two-pass design".
    • The target: 5x end to end over DFlash at block 16. That needs 5.51x in decode at the measured f = 2.28% (Amdahl: (1-f)/(1/5-f)).
    • The verdict beside the target: the ceiling from B1, plus the 2.9x/2.8x estimate. "Refuted" means "misses the pre-registered 5x target", not "no gain".
    • P2 Arm A: the S_a and S_a_real rows, labelled derived.
    • One-step recycling: its own subsection with the numbers, its files (one_step_recycling.json, draft_source_accuracy.csv) and the label "measured, offline, from the drafter's trace".

B3. The session script the README cites is not committed (evidence/repair/README.md, "Session experiments/repair/runs/stage_a.sh").

  • .gitignore:34 ignores runs/. Commit a5b4d82, "Keep the GPU session scripts in the repository", changed only the README. The four scripts are untracked in your worktree.
  • Fix: git add -f experiments/repair/runs/*.sh, or move them to a path that is not ignored. Check that stage_a.sh is the script that produced timing1; the raw directory holds run_timing.sh.

B4. The engine README does not list patch 0002 or its variable (engine/sglang/README.md, ## repair (patches/repair/0001 ...)).

  • 0002 adds SGLANG_REPAIR_DROP_VERIFY_STATES=1. It stops advancing the committed GDN state, so outputs after the first cycle are meaningless.
  • Fix: title the section 0001-0002, add the variable to the table marked "timing with forced acceptance only; corrupts the committed state", and name the branch head 5d8e00e3e1.

B5. The two Codex P2 comments are valid (experiments/repair/p3_gate.py:123, experiments/repair/stage_a.py:175).

  • p3_gate.py:123. max_extra = B - 1 - a0 + 1 should be B - a0 - 1. The anchor has already committed a0 + 1 tokens, and an audit of width B from the same prefix commits at most B.
  • stage_a.py:175. The gate divides by B + 1, but a width-B cycle in SGLang commits at most B tokens (commit_per_cycle = B in every forced run). Sam's gate is written as C_R_lower / (B + 1) with B counting drafts. In SGLang's convention, where width B includes x0, that denominator is B. Use B, or state the mapping.
  • Both errors make the gate lenient. Neither changes a committed result: every gate_rejects stays False, and p3_gate has not run yet.

Suggestions (not blocking)

  • Baseline rate. The PR body gives DFlash's rate as 970 tokens/s, which is the median of per-request rates. The speedups use C_D/A_D = 971.6 us per token, which is 1,029 tokens/s pooled. Quote the pooled rate, or say which one, so that 5,260/970 = 5.4x is not read against S_a_real = 5.1x.
  • P2 Arm A at the threshold. "5.0x end to end only at B = 256" is 5.01x from one session. Call it at the target within the measurement spread. A second session per width would firm this up, though B1's verdict does not need it.
  • Repeats. Say in the README that each width is one session of 8 requests, and give the per-cycle p10-p90 spread.
  • Stale provenance. In one_step_recycling.json, .panel says "(branch drafter/block-drafter)". That branch merged in Drafter: public DFlash-4B on GH200, acceptance by position, fine-tuning tools #22 and the file is on main, so drop the branch.
  • Cycle count. The trace has 21,354 cycle records at block 16, and A_D is 6.186. The drafter's evidence counts 21,274 cycles and tau 6.184 for the same panel. The difference is probably one record per request; say which records you count.

…tracked run scripts

- stage_a.py: add the S_b ceiling (anchor pass at one weight read at the
  measured read peak) and the state share a boundary-replay protocol would
  need; the gate divides by B, the most a width-B cycle commits.
- evidence/repair/README.md: results and verdicts against the pre-registered
  Stage A rules, the target (5.51x decode at f = 2.28%), P2 Arm A rows
  labelled derived, and the recycling result labelled measured offline.
- experiments/repair/runs/*.sh were ignored by .gitignore (runs/); add them.
- engine README: patches 0001-0002, head 5d8e00e3e1, and the no-state switch
  marked as timing-only.
- p3_gate.py: the audit accepts at most B - 1 - a0 extra drafts.
@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE

Re-reviewed head 1d8195a (one commit on a5b4d82). All five blocking items and every suggestion are addressed. One merge conflict with current main needs resolving before the merge (see the end).

Blocking items

  • B1 (fixed). stage_a.py now reports S_b_ceiling: the anchor pass is charged one read of 8.41 GB at the 3.827 TB/s read peak plus the anchor cache at that rate, and the audit is charged its measured V(B) + commit.
    • These are valid lower bounds on cost, so the ceiling is a true ceiling: 5.24x in decode and 4.78x end to end at B = 256. That is below the 5.51x / 5x target at every width.
    • 2.9x / 2.8x is kept and labelled as the byte-bound estimate.
    • state_share_needed_for_target (50.1% of V(256), against the 9.6% byte bound) states the one case the verdict depends on: boundary replay with the replay uncharged. The README says the queued no-state run decides it.
    • The anchor-free column equals S_a (5.01x end to end), consistent with "with no anchor pass at all the two-pass design is S_a".
    • Rerunning stage_a.py on the committed timing reproduces stage_a_oracle.{json,csv} exactly.
  • B2 (fixed). evidence/repair/README.md now has "Results and verdicts".
    • It quotes the pre-registered P3 Stage A rule and the P2 Arm A rule (Sam, 2026-09-30), with no reference to files outside the repository.
    • It states the target: 5x end to end, which is 5.51x in decode at f = 2.28%.
    • The verdict "misses the pre-registered target at every width (refuted)" sits beside the 4.78x ceiling and the 2.78x estimate.
    • The P2 Arm A rows are labelled derived, with 5.01x flagged as at the threshold.
    • The recycling result has its own subsection, labelled "measured, offline", with its files.
    • I checked every number in the section against the CSV and JSON files: the V(B) table, the S columns, 12.9 GB, 3.95 MB per token, the baseline 1,029 / 970 tokens/s, the p10-p90 spread within 1.3%, and the recycling figures.
  • B3 (fixed). The four experiments/repair/runs/*.sh scripts are tracked. Apart from comments, stage_a.sh differs from the run_timing.sh that produced timing1 only in its paths (repository-relative, with OUT and PANEL overrides). The same runs execute in the same order.
  • B4 (fixed). The engine README section is titled 0001-0002 with head 5d8e00e3e1, and it lists SGLANG_REPAIR_DROP_VERIFY_STATES as for timing only and as corrupting the committed state.
  • B5 (fixed). p3_gate.py uses max_extra = B - 1 - a0. The stage_a.py gate divides by B and documents how Sam's B + 1 maps onto it. Every gate_rejects value is still False.

Suggestions (all taken). The pooled baseline is quoted, the repeats and spread are stated, the panel provenance is fixed, and the README reconciles the 21,354 cycles with the drafter's 21,274: one extra record per request, at most 80 of the 18,525 boundaries.

Other checks. Pre-commit passes on the changed files, and the commit has no AI co-author lines. The three Codex comments (P1, P2, P2) on a5b4d82 are all addressed in 1d8195a.

Merge note (not a review item). A test merge into current main conflicts in engine/sglang/README.md. Main appended a state section, and this PR appends a repair section at the same place. Merge main and keep both sections; I'll confirm the merge commit is a pure conflict resolution.

# Conflicts:
#	engine/sglang/README.md
@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE

Approving head 79f3e99. It is a merge of main (a4fb20f) into the approved 1d8195a. I checked that it is a pure conflict resolution:

  • Other paths. I re-merged a4fb20f into 1d8195a locally. Every path except engine/sglang/README.md is identical to 79f3e99 (git diff against 79f3e99, excluding the README, is empty).
  • The README. engine/sglang/README.md in 79f3e99 is exactly main's file followed by one blank line and the ## repair section from 1d8195a. The state section, the repair section and everything else are kept unchanged.

GitHub reports the PR as MERGEABLE/CLEAN. My earlier approval (#56 (comment)) applies to this head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant