Skip to content

Appendix D: integrate the state-safety results (#59) - #74

Merged
SamMausberg merged 6 commits into
mainfrom
paper/appendix-state
Oct 1, 2026
Merged

SamMausberg merged 6 commits into
mainfrom
paper/appendix-state

Conversation

@SamMausberg

@SamMausberg SamMausberg commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Integrates the state-safety results merged in #59 into Appendix D, the status table and the evidence register. The main text is unchanged.

What the appendix now says

  • Figure 5 is drawn from evidence. It now reads evidence/state_safety/first_difference_by_module.csv through pgfplots (\datafigure) instead of typed counts. The counts and the layout are unchanged: 167 at layer 0's GDN recurrence; gated RMSNorm in 13 GDN layers; 6 at layer 3's attention; 5 at layer 0's MLP in a batched prefill.
  • Fresh-server repeats (D.4, noise_floor.csv):
    • At batch 1 a fresh server reproduces all 320 prompts bitwise, including the one prompt whose log-probabilities changed on the same server.
    • At concurrency 32 a fresh server reproduces 296 of 320; 24 diverge at exact ties, 0.35 per 1,000 compared tokens, because arrival timing changes batch composition.
  • History dependence through the prefix cache (D.4, new paragraph; targeted.json). This replaces the untested hypothesis about the five prompts the tap changed. It gives the code path at the pin: after prefill the request's KV is repointed to the tree's copy, which is equal in value but not bitwise. The deterministic stock reproduction: with the cache on, plain and MTP s3 keep every token but change log-probabilities for 2 of 12 prompts (from output index 2, and 5); for plain decoding with the cache off all 12 are identical in tokens and log-probabilities. KV-level confirmation stays pending (state-mech).
  • H5 targeted tests (D.5). These compare output token IDs only; log-probabilities and state are not compared (Codex review):
    • Truncation inside a verify cycle: 157/157 (MTP s3) and 240/240 (s5) outputs are token-identical to the untruncated prefix.
    • A stop token at every index: 160/160 and 240/240 are token-identical, with 120 and 200 stops inside the draft block.
    • Warm against cold continuations are identical in 139/160 and 210/240; the rest diverge at ties (19, 30) or within one BF16 step (2).
    • The remaining tests stay pending: tree and plain, checkpoint reuse, aborts, chunked prefill, repeats and drift by rejection position.
  • Register and status.
    • New entry targeted; state-mech now lists first_difference_by_module.csv and analyze_all.sh.
    • state-targeted narrows to the remaining tests.
    • The H5 row reads "Truncation and stop tokens at every index of an MTP verify cycle leave the output token-identical to the untruncated prefix (397 and 400 cases; log-probabilities and state not compared); the other tests pending".

Every number was checked against targeted.json, noise_floor.csv and the state README.

Validation

  • latexmk -pdf builds 72 pages with no LaTeX or BibTeX warnings. The main text ends on page 10. The rebuilt paper.pdf is committed, and I compared the redrawn Figure 5 with the previous one and looked at the changed pages.
  • python scripts/check_paper_references.py passes: no uncited or missing keys, and every register path exists on origin/main.
  • The repo's hooks exclude paper/; there are no other changed files.

Figure 5 is now drawn from first_difference_by_module.csv instead of
typed counts; the counts are unchanged. Appendix D.4 adds the
fresh-server repeats: batch 1 is bitwise reproducible, and at
concurrency 32 24 of 320 outputs diverge at ties, 0.35 per 1,000.
The tap-changed prompts are now explained by history dependence
through the prefix cache, with the deterministic stock reproduction:
logprobs change for 2 of 12 prompts with the cache on and none with it
off. KV-level confirmation stays pending.

Appendix D.5 reports the completed H5 tests. Truncation (157/157,
240/240) and stop tokens at every index of an MTP verify cycle
(160/160, 240/240) reproduce the untruncated output bitwise, and warm
against cold continuations match except at ties. A new register entry
"targeted" covers them; state-targeted narrows to the remaining tests;
and the H5 status row is updated.
@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-01T04:01:09.965959Z 7d2777f 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.

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: REQUEST CHANGES

Reviewed head 7d2777f: one commit on a6a1850 that integrates #59 into Appendix D. Everything checks out except one claim, which goes further than the evidence.

Checked and correct

  • Figure 5. The figure is now drawn from first_difference_by_module.csv. Its 16 rows equal the counts that were typed in before: gated RMSNorm at layers 0/5/10/14/16/18/20/21/24/25/26/28/29 with counts 3/1/1/3/1/4/2/3/1/3/1/4/2, attention at layer 3 (6), the down-projection at layer 0 (5), and the GDN recurrence at layer 0 (167). I rendered page 39 against main's PDF: same layout, same markers and labels, and the legend shifted slightly.
  • Fresh-server repeats. Batch 1 reproduces 0/320, and concurrency 32 gives 24/320 at 0.35/1K, all ties. These match noise_floor.csv.
  • The history reproduction. It matches targeted.json: 2/12 log-probabilities change with the prefix cache on, from output index 2 (and 5 for one MTP prompt), and 0/12 with it off. All tokens are identical.
  • H5. Truncation 157/157 and 240/240, stops 160/160 and 240/240 (397 and 400 cases), inside the block 120 and 200, warm/cold 139/160 and 210/240 with 19 + 2 and 30 ties. The configuration is stated (MTP 3 and 5 steps, top-k 1, cache, overlap and graphs on, one in flight, first 40 prompts).
  • Register. targeted cites files and scripts that exist on main. state-mech adds the CSV and analyze_all.sh. state-targeted is narrowed to the remaining tests.
  • Build. I rebuilt from source: 72 pages, no warnings, and the text matches the committed PDF. The main text ends on page 10, and check_paper_references.py passes.

Blocking

B1. The five tap-changed prompts are "traced" to the prefix cache, but that link has not been confirmed (app_exactness.tex).

  • Two places make the claim:
    • "the five exceptions are traced below to history dependence through the prefix cache";
    • "The five prompts whose output the tap itself changed have a stock explanation".
  • What the evidence shows:
    • The stock reproduction shows that history dependence exists, but on two other prompts (mt_bench-0056 and humaneval-0008).
    • For the five tapped prompts, the evidence is the mechanism read from the code plus the layer-3 attention signature.
    • The cache-level hash that would confirm it is pending; this paragraph's last sentence says so, as does evidence/state_safety/README.md, whose neutrality bullet still calls the five "an open question".
  • Fix: write "the five exceptions are consistent with history dependence through the prefix cache (below)" and "have a likely stock explanation". Then keep the closing sentence, which makes the confirmation for these five pending (\pend{state-mech}).

Codex was still running when I posted. I'll check its comments with the fix.

Address review B1 on #74. The stock reproduction shows the effect on
other prompts. For the five tapped prompts there is only the attention
signature and a code reading, and the KV-level confirmation is pending.
The text now says "consistent with" and "a likely stock explanation".
@SamMausberg

Copy link
Copy Markdown
Owner Author

B1 is fixed in a71fff9. The neutrality sentence now reads "the five exceptions are consistent with history dependence through the prefix cache, discussed below". The paragraph opens with "have a likely stock explanation" and adds that "the tapped prompts themselves show only the attention signature, and the mechanism is a code reading" before the 12-prompt stock reproduction. The pending KV-level confirmation sentence is unchanged. Build: 72 pages, 0 warnings, main text ends on page 10.

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE

Re-reviewed head a71fff9 (one commit on 7d2777f). B1 is fixed.

  • The wording. The five tap-changed prompts are now "consistent with history dependence through the prefix cache", with "a likely stock explanation".
  • The basis. The text says the tapped prompts themselves show only the attention signature and that the mechanism is a code reading. The reproduction is described as "of the effect", with "other" dropped from "12 prompts" because overlap with the five cannot be ruled out.
  • Pending. The cache-level confirmation stays pending.
  • Build. I rebuilt from source: 72 pages, no warnings, and the text matches the committed PDF. The main text ends on page 10.

Merge note. #75 has merged (13368f4) and also changed paper.pdf. Merge main and rebuild the PDF; I'll confirm the merge commit contains only the merge and the rebuild.

@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: 7d2777fea3

ℹ️ 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 paper/sections/app_exactness.tex Outdated
\paragraph{How often} In plain decoding at concurrency 1 against 32, 167 of 320 prompts diverge within 256 tokens, 3.42 divergences per 1,000 compared tokens, with a largest margin at the divergence of 0.375 nats. Repeating either configuration on the same server reproduces every token of all 320 prompts, and every log-probability except those of one 128-token prompt, which differ from its prefill onward in both repeats. A fresh server at batch 1 reproduces the first pass bitwise on all 320 prompts, that one included, so its difference on the same server comes from what the prefix cache already held (below). A fresh server at concurrency 32 reproduces 296 of the 320 outputs; the other 24 diverge at exact ties, 0.35 per 1,000 compared tokens, because request arrival, and with it batch composition, differs between sessions~\ev{state-noise}. Plain decoding at batch 1 has an exact BF16 tie between its top two logits at 11.3 of every 1,000 positions and a nonzero gap of at most 0.125 at another 22.2, and no run committed a token that was not its own top-1~\ev{state-noise}. SGLang's deterministic mode, which replaces the default matrix multiplication with a batch-invariant one (DeepGEMM's deterministic BF16 GEMM at the pin's defaults on this GPU, a persistent Triton kernel otherwise)~\cite{sglangdeterministic} and, with the FlashInfer backend, also switches sampling to PyTorch and disables the prefix cache, made plain decoding batch-invariant in an 8-prompt, 128-token check (concurrency 1 against 8: identical tokens and bitwise-identical log-probabilities) but not MTP speculation (2 of 8 prompts diverged). Passing the deterministic KV split to FlashInfer's target-verify plan, as an engine patch (\path{engine/sglang/patches/state/0002-verify-kv-split-deterministic.patch}), left 28 of 96 MTP prompts diverging between concurrency 1 and 32, 1.55 per 1,000 compared tokens, all at exact ties~\ev{state-noise}. A plausible reason, not tested, is that the draft is not batch-invariant, so accepted lengths, and with them a position's offset inside its verify block, differ between batch sizes.

\paragraph{Open questions} The remaining configuration pairs (MTP with one, three and five steps and a tree at both concurrencies, prefix cache and overlap scheduler off, deterministic mode and the FP32 head in full) and the cache-level check are \pend{state-mech}. So is an explanation of the five prompts whose output the tap itself changed: in each, the tapped run differs from output index 2 on, and the first differing module there is layer 3's attention output while its QKV projection and every earlier module agree, so the attention read different KV~\ev{state-tap}. The untested hypothesis is that inserting the prompt into the prefix cache repoints the running request's prefix KV to an equal-valued but not bitwise-equal copy computed in another request's prefill, and that the tap's per-forward synchronization changes whether decode step 2 reads the repointed copy.
\paragraph{Open questions} The remaining configuration pairs (MTP with one, three and five steps and a tree at both concurrencies, prefix cache and overlap scheduler off, deterministic mode and the FP32 head in full) and the cache-level check are \pend{state-mech}. \paragraph{History dependence through the prefix cache} The five prompts whose output the tap itself changed have a stock explanation~\ev{state-tap,targeted}. In each, the tapped run differs from output index 2 on, and the first differing module there is layer 3's attention output while its QKV projection and every earlier module agree, so the attention read different KV. At the pin, after a request's prefill, SGLang inserts its prefix into the prefix cache, matches it again and repoints the request's KV slots to the tree's copies, freeing its own. For tokens the tree already held, such as a chat-template prefix shared with an earlier request, the request then attends over the earlier request's copy of that KV, valid values for the same tokens at the same positions but computed in a prefill of another shape and not bitwise equal; under the overlap scheduler decode step 1 is already in flight with the request's own KV, so the switch shows from output index 2 (code reading at the pin). A deterministic reproduction on stock SGLang serves each of 12 prompts on an empty cache and again right after the earlier prompt that shares the longest prefix with it. With the prefix cache on, plain decoding and MTP with three steps keep every token but change log-probabilities for 2 of the 12 prompts, from output index 2 (and 5 for one MTP prompt); with the prefix cache off all 12 are bitwise identical. So with the prefix cache on, a request's output at a fixed configuration and batch shape depends on which earlier request computed its shared prefix, and under overlap scheduling on timing. The values involved are valid, no case changed more than a near-tie decision, and it is not state corruption; the confirmation at the level of the cached KV is \pend{state-mech}.

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 Keep the five tap exceptions pending

The cited history experiment establishes that prefix-cache history can alter outputs, but it does not trace all five tap-induced exceptions to that mechanism: targeted.json reports differences for only two of the 12 history prompts, the cache-disabled control was run only for plain decoding, and the cached-KV comparison is explicitly still pending later in this paragraph. When explaining the five tapped prompts or the MTP case, this should remain a hypothesis until those prompts are individually reproduced or their entering KV is confirmed.

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 a71fff9. The five prompts are now "consistent with history dependence through the prefix cache", with "a likely stock explanation". The text adds that the tapped prompts show only the attention signature and that the mechanism is a code reading. The KV-level confirmation stays pending (state-mech).

Comment thread paper/sections/app_exactness.tex Outdated
\paragraph{What SGLang does, and how it is tested (H5)} During verification SGLang computes the recurrent state and the convolution window after every draft position into per-position buffers and leaves the live state untouched; after acceptance a fused scatter copies the buffers of the last accepted position (for a tree, the last accepted node) into the request's slot (code reading at the pin). The emitted prefix includes the bonus token while the materialized state does not; the bonus token is the first input of the next cycle. Prefix reuse checkpoints the recurrent state every 256 tokens of sequence length into a ping-pong pair of slots, including checkpoints that fall inside a verify cycle, and a freshly allocated slot is cleared by the next forward on the same stream, after any in-flight verification by its previous owner. The MTP draft layer is a full-attention layer, and under greedy verification every committed token is the target's argmax, so an error in draft-side state could lower acceptance but not change the output.

Each point where a speculative cycle touches this state is tested against a reference that isolates it. Truncation by \code{max\_new\_tokens} and stop tokens at every index inside a verify cycle must reproduce the untruncated run bitwise on the same server. Checkpoints taken during speculative decoding, including in the cycle that finished the request, are restored for a continuation and compared with a cold prefill of the same prefix. Requests aborted mid-stream with a recurrent pool of exactly four slots force the next request onto the freed slot while the aborted request's last verification may still be in flight. Chunked prefill at 200 and 256 tokens is compared with an unchunked prefill. And the log-probability drift of every MTP run against plain decoding is bucketed by the draft position that the previous cycle rejected. Small debug runs of each test passed their checks; the outcome of each full test is \pend{state-targeted}.
Each point where a speculative cycle touches this state is tested against a reference that isolates it. Truncation by \code{max\_new\_tokens} and stop tokens at every index inside a verify cycle must reproduce the untruncated run bitwise on the same server. Checkpoints taken during speculative decoding, including in the cycle that finished the request, are restored for a continuation and compared with a cold prefill of the same prefix. Requests aborted mid-stream with a recurrent pool of exactly four slots force the next request onto the freed slot while the aborted request's last verification may still be in flight. Chunked prefill at 200 and 256 tokens is compared with an unchunked prefill. And the log-probability drift of every MTP run against plain decoding is bucketed by the draft position that the previous cycle rejected. The first two tests are complete~\ev{targeted}, for MTP with three and five draft steps, top-$k$ 1, the prefix cache, overlap scheduler and CUDA graphs on, one request in flight and the first 40 prompts. Truncation leaves every truncated run bitwise equal to the untruncated run's prefix: 157 of 157 with three steps, keeping 1 to 4 tokens of the final cycle, and 240 of 240 with five steps, keeping 1 to 6. A stop token at every index of a verify cycle also reproduces the untruncated prefix bitwise, in 160 of 160 and 240 of 240 cases. In 120 and 200 of them the stop falls inside the draft block, so drafts after it were accepted and folded into the recurrent state before the stop was detected, and none of that state reaches the output. Extending each stopped conversation with a new user turn, served warm from the restored checkpoint and cold after a flush, gives identical continuations in 139 of 160 and 210 of 240 cases; the rest diverge at exact ties (19 and 30) or within one BF16 step (2), consistent with the warm path's different prefill computation and with the history dependence above. The same two tests for the tree and for plain decoding, checkpoint reuse, aborts with slot reuse, chunked prefill, run-to-run repeats and the drift by rejection position are \pend{state-targeted}.

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 Report token-prefix equality instead of bitwise equality

The targeted harness marks truncation and stop cases identical solely by comparing output_ids with the reference prefix (targeted.py lines 115 and 177); it does not compare log-probabilities, logits, or recurrent-state bits. Therefore these runs establish matching greedy token prefixes, not bitwise reproduction or that post-stop state had no observable numerical effect—a state/logit difference that preserves the argmax would pass every reported case. Either narrow these claims to token equality or add a bitwise state/logit comparison.

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 64880c6 and 9a69a75. targeted.py compares output_ids only, so the truncation and stop results are now "token-identical" to the untruncated prefix. The text says log-probabilities and state are not compared, and "none of it changed an output token" replaces the state claim. The H5 register row has the same wording. The history control is scoped to "plain decoding with the prefix cache off" and to "identical in tokens and log-probabilities", which is what that test compares.

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE

Approving head ad8c346. It merges main at 13368f4 (#75) into the approved a71fff9.

  • Pure merge. I re-did the merge locally. The only conflict is paper/paper.pdf, and every other path is identical to ad8c346.
  • Diff against main. Against main the PR changes only divergence.tex, app_exactness.tex, app_register.tex and the PDF.
  • PDF rebuild. I rebuilt the PDF from ad8c346: 72 pages, no warnings, and the text matches the committed PDF. The main text ends on page 10, and check_paper_references.py passes.

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: REQUEST CHANGES

I am withdrawing my approval of ad8c346. Codex's second P2 on 7d2777f still applies, and I missed it. Codex was still running when I first reviewed, and I approved a71fff9 and ad8c346 without going back to its comments.

B2. The H5 tests compare tokens, not bits (app_exactness.tex:114; the register's H5 row).

  • targeted.py marks a truncation or stop case identical only by comparing output_ids with the reference prefix (lines 115 and 177, and diff() at line 61). It does not compare log-probabilities, logits or state bits.
  • So 157/157, 240/240, 160/160 and 240/240 establish matching greedy token prefixes. They do not establish bitwise reproduction, and they cannot show that "none of that state reaches the output" beyond the argmax.
  • Fix:
    • Replace "bitwise" with "token-identical" (or "the same greedy tokens") in the three sentences at line 114 and in the H5 status row ("reproduce the untruncated output bitwise (397 and 400 cases)").
    • Change "none of that state reaches the output" to "none of it changes an output token".
    • Alternatively, add a log-probability comparison to the harness and rerun.

B3. The prefix-cache-off control ran for plain decoding only (app_exactness.tex:91).

  • "With the prefix cache off all 12 are bitwise identical" reads as covering MTP too. targeted.json has history__plain_noradix only.
  • Fix: write "for plain decoding with the prefix cache off, all 12 are bitwise identical". The history test compares log-probabilities, so "bitwise" is supported there.

Codex's first P2 (keeping the five tap exceptions pending) was addressed in a71fff9.

The same token-only wording is in the merged state README (#59), which I also approved without catching it. The state workstream is fixing it in a separate PR.

Address the Codex review of #74. targeted.py compares only output token
IDs with the reference prefix, not log-probabilities or state, so the
results are now token-identical, not bitwise; the same goes for the H5
status row. The prefix-cache-off history result is stated as identical
in tokens and log-probabilities, which is what that test compares.
Address review B3 on #74: only plain decoding ran with the prefix cache
off (history__plain_noradix).
The deterministic-mode run predates the patch's environment switch,
which is off by default, and had the change on (state README).
@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE

Approving head c94128e (64880c6, 9a69a75 and c94128e on ad8c346).

  • B2 (fixed).
    • The H5 tests are now "token-identical", with "Both tests compare output token IDs with the reference prefix; log-probabilities and state are not compared".
    • The design sentence reads "must reproduce the untruncated run's tokens", and the state claim is now "none of it changed an output token".
    • The H5 register row reads "leave the output token-identical to the untruncated prefix (397 and 400 cases; log-probabilities and state not compared)".
    • No "bitwise" claim remains for these tests.
  • B3 (fixed). "For plain decoding with the prefix cache off all 12 are identical in tokens and log-probabilities", which matches history__plain_noradix.
  • c94128e. It adds that patch 0002 is now behind a switch that is off by default and that the committed deterministic run predates the switch with the change on. Both facts are in the merged State safety: H5 truncation and stop tests, radix history dependence #59 README.
  • Codex. The only review is on 7d2777f, with two P2 comments: the five tap exceptions (fixed in a71fff9) and token equality (fixed in 64880c6 and 9a69a75). Both are answered on the PR, and no new comments exist on later heads.
  • Build. I rebuilt from source: 72 pages, no warnings, and the text matches the committed PDF. The main text ends on page 10, check_paper_references.py passes, and the branch contains main.

Nit (not blocking). "gives identical continuations in 139 of 160" compares tokens too. "Token-identical" would match the state README's wording.

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