Skip to content

Repair: P9 remainder verify, reuse program and c = 8/16; same-session verify control; B = 256 kernel trace - #150

Merged
SamMausberg merged 17 commits into
mainfrom
repair/p9-cost
Oct 1, 2026
Merged

SamMausberg merged 17 commits into
mainfrom
repair/p9-cost

Conversation

@SamMausberg

@SamMausberg SamMausberg commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Evidence from the repair workstream's session_x2 hold (2026-10-01 16:13-16:59 UTC) and the analysis code it needed. It answers four questions left open by #97 and #109: what verifying only the remainder of a reused window costs, what the reuse program costs on the GPU, whether reuse still pays at concurrency 8 and 16, and whether the cross-session verify decomposition (#89) holds within one session. It adds a kernel trace of the B = 256 verify pass.

Every timing here uses FlashInfer's GDN verify kernel (--linear-attn-decode-backend flashinfer, as on the DFlash model card and in the P9 baseline), except the Triton column of the control. SGLang's default on sm_90 is the Triton verify kernel, which the bench's tuned DFlash arms already use, so the FlashInfer-versus-Triton ratios do not stack on tuned DFlash.

Results (evidence/repair/README.md)

P9 remainder verify (c = 1). V(B) at B = 2..16 runs from 3.83 to 4.78 ms: two positions cost 80% of sixteen. Charging each reused cycle its measured m + 1 verify, the always-reuse oracle gives top-16 +1.17 (+1.09, +1.26), top-8 +0.39 (+0.31, +0.47), and keeps top-4 (-0.27; -0.39, -0.17), top-2 and top-1 rejected; the omniscient gate bounds any gated program at +2.16 for top-16. Fresh DFlash commits about 10.2 tokens over the two cycles around a boundary, so these are gains of about a tenth (always reuse) and a fifth (perfect gate) on them, as upper bounds under the stated scopes.

Reuse program. The fixed-shape program's messages and greedy walk take 133-315 us per reuse as one CUDA graph, almost independent of rank and batch; eagerly 3.2-5.8 ms.

Concurrency 8 and 16. The draft is 31%, 25% and 20% of the cycle at c = 1, 8 and 16, and the batched draft grows by only 73 and 55 us per added request. At c > 1 one reusing request only removes its own draft row, and the shorter batch period serves every request in the batch. Crediting the request an even share of the batched draft (an upper bound when the draft's cost is concave in rows), top-16 stays positive (+0.70 at c = 8, +0.48 at c = 16). Crediting the measured growth per added request instead, always-reuse by one request is rejected at every K, top-16 included (-0.19 and -0.18), and one reuse step of the program costs more GPU time than the draft row it removes. The omniscient gate still bounds a gated program at +1.27 for top-16.

Same-session verify control. FlashInfer / no per-position states / Triton: 4.78 / 4.60 / 4.57 ms at B = 16 and 44.70 / 40.72 / 19.19 ms at B = 256, within 1.5% of the cross-session values in #89.

Kernel trace at B = 256. Over the 19 complete cycles in the window, the FlashInfer verify kernel takes 1.36 ms per layer (5.3 us per position per layer), 32.7 ms per cycle or 72% of the profiled verify phase; the causal conv update kernel takes 6.5 ms per cycle. Derived, not measured: if the Triton path leaves the conv kernel unchanged, the conv update is about a third of the Triton pass at B = 256.

Code

  • serve_probe.py: closed-loop concurrency (--concurrency); Nsight options moved to nsys start.
  • analyze_timing.py: batched summary (full-batch cycles, draft share) for c > 1 runs.
  • p9_support_oracle.py: --width-timing (measured m + 1 verify, always-reuse and gated); c > 1 baselines, with --draft-saving-us for a per-request saving credited c times (the shorter batch period serves every request); the bootstrap is computed with numpy from the same draws, and the regenerated c = 1 JSON equals the committed one to 2e-13 in every shared field.
  • nsys_kernels.py: reads the kernel timeline (nsys export to SQLite) and charges the kernels up to the end of the last state commit to the whole cycles in that span (verify-kernel launches / 24 GDN layers); a cycle cut off by nsys stop is reported, not charged (Codex r4159272133). Prefill's GDN kernels and normalization kernels get their own categories.
  • p9_program_cost.py, p12_static_screen.py and the run scripts in experiments/repair/runs/. The P12 screen's evidence is not in this PR (its shared-lock run is still queued).

Validation

  • tests/test_repair_p9.py (16 tests, including the new width, batched-baseline, draft-saving and bootstrap-equivalence tests) and tests/test_repair_stage_a.py, run in the SGLang venv (torch); tests/test_repair_nsys_kernels.py (3 tests: categories, a truncated trailing cycle, partial windows fail); pre-commit on every changed file.
  • Every timed run recorded its foreign CPU load (at most 0.8 cores mean); p10-p90 spreads are in the README.

Not covered

The Triton verify kernel's width sweep and kernel trace were not run. The c > 1 oracle takes acceptance from the c = 1 support table. The exact Jacobi probes in the engine (P2) and the P12 screen come in later PRs.

Review

  • Codex r4159272133 (partial cycle in the nsys window): fixed in 51a20fb and 31a6a65; whole cycles only, see the reply on the thread.
  • Reviewer (REQUEST CHANGES at 2b49f5c): the two _marginal oracle commands are written out in full (31a6a65); the cycle count as above.

…elong to nsys start); add the B = 256 verify trace session
…lk at every correction slot

After a correction at J a reused window has m = 15 - J positions left, so a program could
verify m + 1 positions instead of a padded block of 16. runs/p9_verify_widths.sh times the
verify phase at forced widths 2..16 (m = 1..15); p9_program_cost.py now sweeps the correction
slot (walks of 14 down to 1 slots) instead of fixing it at 4.
…baselines

--width-timing takes the forced-acceptance verify at widths 2..16 from one session
(runs/p9_verify_widths.sh) and charges a reused cycle after a correction at J the
baseline cycle minus its draft minus V(16) - V(m + 1) of that session, always-reuse and
with the omniscient gate. It needs a c = 1 baseline.

A batched baseline (analyze_timing.py's c > 1 summary) is accepted: the cycle is the batch
period and a reuse saves the batched draft divided by c per request, with the per-request
rate, which is an upper bound on the saving when the draft's cost is concave in rows.

The bootstrap computes each replicate with numpy weights from the same random draws, so
the committed intervals reproduce while the run takes seconds instead of minutes.

--draft-saving-us replaces the saved draft with a given value, such as the growth of the
batched draft per added request, which is what one reusing request saves while the others
still draft.
The per-cycle figures divided by the state commit kernel's launches, but that kernel runs
twice per verify cycle (38 launches for about 19.75 cycles in the B = 256 trace), so every
per-cycle time came out halved. Cycles are now the most-launched GDN kernel's launches over
the 24 GDN layers; each top kernel also reports its mean time per launch.
…d for all c requests

--draft-saving-us now takes s, how much one reusing request shortens the batch cycle, and
credits c s per reuse: the shorter period serves every request in the batch, which commits
c r_F tokens per unit time. The default (s = draft(c) / c) already credited draft(c); passing
the measured per-request draft growth credited only s, c times too little.
…r GDN kernels

The most-launched kernel in the GDN category was not the verify kernel in the B = 256 trace
(547 launches against the verify kernel's 474): prefill's chunked GDN kernels share the
category. Cycles are now the launches of the named verify kernel (FlashInfer's
gdn_verify_kernel_mtp or SGLang's Triton fused_sigmoid_gating_delta_rule_update) over the
24 GDN layers, and the other GDN kernels get their own category.
Normalization kernels (FlashInfer's fused add-RMSNorm is a CUTLASS kernel) no longer count as
GEMMs.
…ify control and B = 256 trace

session_x2 (exclusive, 2026-10-01 16:13-16:59 UTC; FlashInfer GDN verify kernel unless noted).
P9 at c = 1 with the measured m + 1 verify (V(2) = 3.83 to V(16) = 4.78 ms): top-16 +1.17
(+1.09, +1.26), top-8 +0.39; top-1, 2 and 4 stay rejected for always-reuse. The reuse program
takes 133-315 us per reuse as one CUDA graph. At c = 8 and 16 the draft is 25% and 20% of the
cycle and grows 73 and 55 us per added request: with the even share top-16 stays positive
(+0.70, +0.48); one request reusing alone is rejected at every K. Same-session control: the
cross-session decomposition holds within 1.5%. Kernel trace at B = 256: the verify kernel is
32.7 ms of the 45.2 ms profiled pass, the conv update 6.5 ms.
@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-01T19:03:52.766597Z 31a6a65 Manual request
ℹ️ 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: 2b49f5c8a1

ℹ️ 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 thread experiments/repair/nsys_kernels.py Outdated
Comment on lines 114 to 115
cycles = verify_launches / GDN_LAYERS
per_cycle = {k: v / 1e3 / cycles for k, v in sorted(by_cat.items())} if cycles else {}

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 Count actual verify cycles rather than all verify launches

When the profiling window includes prefill or warm-up work, verify_launches is not necessarily a multiple of the 24 GDN layers, so dividing it by 24 counts those extra launches as fractional decode cycles and understates every per-cycle category. The committed verify_kernels_b256.json demonstrates this: 474 launches produce 19.75 “cycles,” while its 38 state-commit launches correspond to 19 cycles because that kernel runs twice per cycle. Count the real cycle marker (accounting for its two launches) and charge all window kernels to those cycles.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 51a20fb (code) and 31a6a65 (evidence). The trace holds 19 complete cycles (24 verify launches and 2 state-commit launches each) plus a trailing cycle that nsys stop cut off after 18 verify launches. Dividing all launches by 24 charged that fragment as 0.75 of a cycle. Charging everything to 19 commit-delimited cycles instead would have added the fragment's ~25 ms of verify work to the per-cycle cost. nsys_kernels.py now reads the kernel timeline (nsys export to SQLite) and charges only kernels that start before the end of the last state commit, divided by the whole cycles in that span: 456 launches / 24 = 19. It reports the cut-off kernels separately (479 kernels, 34.9 ms) and fails when the span is not a whole number of 24-layer cycles or holds no commit. Per cycle: verify kernel 32.68 ms (unchanged, = 24 x 1.362 ms), conv update 6.48, GEMMs 5.87. Tests: tests/test_repair_nsys_kernels.py.

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: REQUEST CHANGES (2b49f5c, 2 blocking, both small; the accounting and every P9 number check out)

Checked

  • The regenerated c = 1 oracle reproduces main's. Across p9_support_oracle.json's 205 shared numeric fields, the largest relative difference from main's copy is 5.9e-13. Only the kind text and the added width fields differ.
  • The c > 1 credit (742cc63) is correct.
    • A reuse that shortens the batch period by s serves all c requests, so it is worth c r_F s tokens, which the c = 1 formula carries as T2_R - T2_F = -c s.
    • The default s = draft(c)/c gives -draft(c) as before. --draft-saving-us now sets s, and the code credits c s.
    • Summed over requests reusing at rate q, attributing c s to each reuse equals the batch's total period saving, so the attribution double-counts nothing.
  • The nsys cycle count (d5b6573) counts the named verify kernel's launches over 24 GDN layers, not the twice-per-cycle commit kernel or the most-launched GDN kernel.
  • Every number matches its JSON:
    • V(2..16) from p9_verify_widths.json (3.83 to 4.78 ms);
    • the measured-width table (K = 1 to 16: -0.04, -0.57, -0.27, +0.39 and +1.17, with the omniscient gate at +0.01 to +2.16);
    • all four c = 8 and c = 16 columns, and the omniscient-gate values in the note below them;
    • 73.09 and 55.01 us from the draft medians.
  • Labels and scope.
    • The verdict is labelled "(oracle, upper bounds under the stated scopes)".
    • The section says every number uses FlashInfer's GDN verify kernel, that c > 1 takes acceptance from the c = 1 support table, and that the concavity condition bounds s.
    • The earlier padded-verify caveat points to this section, which settles it.
  • Host identity: 0 hits. Attribution: clean.

Blocking

  1. Give the full commands. The command block abbreviates the _marginal runs as python experiments/repair/p9_support_oracle.py ... --baseline-run fresh_b16_c8 --draft-saving-us 73.09 and "55.01 and _c16_marginal at c = 16". Every committed file needs its exact command (AGENTS.md): write out both _marginal invocations in full.
  2. Codex r4159272133: the cycle count in verify_kernels_b256.json. 474 verify launches / 24 = 19.75 "cycles", while the 38 commit launches give 19. The window holds a partial cycle, so the per-cycle totals (47.4 ms, the 32.68 ms GDN verify and so on) carry about a 4% count uncertainty. The per-launch time (1.36 ms) and the shares do not. Either:
    • count whole cycles from a cycle marker and charge the window's kernels to those; or
    • keep the count and state the caveat next to the table: whole cycles 19, partial-cycle launches charged, per-cycle figures ±4%, per-launch time and shares unaffected.

Pre-commit and tests/test_repair_p9.py will run in the CPU window on the fix head.

…omplete cycles

The B = 256 trace holds 19 complete verify cycles (24 verify launches and two state-commit
launches each) and a trailing cycle that nsys stop cut off after 18 verify launches. Counting
474 launches / 24 = 19.75 cycles charged that fragment as three quarters of a cycle (Codex on
#150). The script now reads the kernel timeline from the report's SQLite export, charges the
kernels that start before the end of the last state commit to the complete cycles in that span,
reports the cut-off kernels separately, and fails when the span does not hold a whole number of
24-layer cycles or no commit at all. Tests cover the truncated tail and both failures.
… the marginal oracle commands

verify_kernels_b256.json regenerated with 51a20fb: the 19 complete cycles up to the last state
commit, the cut-off trailing cycle (18 verify launches, 34.9 ms) left out. Per cycle: verify
kernel 32.68 ms, conv update 6.48, GEMMs 5.87, the rest 2.43. The README states the two
_marginal oracle commands in full (review of #150).
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE (provisional, on 31a6a65: Codex is still running on this head, and pre-commit plus tests/test_repair_p9.py and tests/test_repair_nsys_kernels.py are queued in the CPU window. I will confirm or withdraw once both finish.)

31a6a65 and 51a20fb resolve both items.

  1. The two _marginal commands are written out in full (--cycles, --timing, --baseline-run, --draft-saving-us, --bootstrap, --out).
  2. The cycle count (Codex r4159272133). nsys_kernels.py now charges only kernels that start before the end of the last state commit, and divides by the whole cycles in that span: 456 verify launches / 24 = 19. It fails if the span is not a whole number of 24-layer cycles or holds no commit.
    • verify_kernels_b256.json agrees: 19 cycles, 38 commit launches, and 901.74 ms charged.
    • The cut-off trailing cycle (479 kernels, 34.94 ms) is reported but not charged.
    • Per cycle: GDN verify 32.68 ms (68.9%), conv 6.48, GEMM 5.87, the rest 2.43, total 47.5. These match the README table, and the old 47.4 over 19.75 cycles is consistent with them once the trailing 34.9 ms is added back.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 31a6a65554

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

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE (confirmed on 31a6a65)

This confirms my provisional approval. Codex found no issues on this head (19:03 UTC), and pre-commit from main to 31a6a65 is clean. tests/test_repair_p9.py and tests/test_repair_nsys_kernels.py pass in the SGLang environment (19 tests). Without torch, the P9 module skips and the other 3 pass.

@SamMausberg
SamMausberg merged commit e4439dd into main Oct 1, 2026
SamMausberg added a commit that referenced this pull request Oct 1, 2026
The run used local commit a05df1d (never pushed); its p12_static_screen.py and runs/p12_screen.sh
are the same git blobs as at d365673, which is on main through #150 (Codex on #165).
SamMausberg added a commit that referenced this pull request Oct 1, 2026
…epair tasks done

p12_static_screen.provenance.json: the run's commit a05df1d (local, never pushed) recovered from
the run worktree's reflog, the scripts' SHA-256 and git blobs, identical at 694c0bc on main, the
input hash, lock and time. jacobi_probe_provenance.json copies both probe runs' run.json records
(17bbeac and engine 5d8e00e3e1, both clean) with input and trace hashes. TASKS.md: the engine
Jacobi task (#165) and the P9 cost task (#150) are done (Codex and review on #165).
SamMausberg added a commit that referenced this pull request Oct 1, 2026
…ejections; the measured widths do

The free-verify bound rejects none of the tested sets, but the verify measured at
each remaining width (#150, already in the notes) still rejects reuse with the
top-1, top-2 and top-4 sets. The sentence that said the rejections do not extend
to a narrower verify now says which bound it means. Requested by the repair agent.
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