Skip to content

State safety: H5 truncation and stop tests, radix history dependence - #59

Merged
SamMausberg merged 7 commits into
mainfrom
state/results
Oct 1, 2026
Merged

SamMausberg merged 7 commits into
mainfrom
state/results

Conversation

@SamMausberg

Copy link
Copy Markdown
Owner

This follows #37 with the first H5 state-test results, a stock reproduction of a radix-cache history dependence, and the fixes and tools requested in review. More results will be pushed to this PR as queued GPU holds complete; anything not yet measured is marked pending in evidence/state_safety/README.md.

H5: truncation and stop tokens inside a verify cycle

  • max_new_tokens ending after every possible number of tokens of the final verify cycle: MTP steps 3 gives 157/157 truncated runs bitwise equal to the untruncated prefix; steps 5 gives 240/240.
  • A stop token at every index of a cycle:
    • Steps 3: 160/160 outputs bitwise equal. In 120 of these the stop sits inside the draft block, so drafts after it were already committed to the GDN state.
    • Steps 5: 240/240 equal (200 inside the block).
    • None of the post-stop state reaches the output.
    • Warm and cold multi-turn continuations agree in 139/160 and 210/240 cases. The rest diverge at ties or within one BF16 step.

Radix-cache insertion makes output depend on history

After a prefill, cache_unfinished_req rewrites the running request's req_to_token row with the radix tree's indices. For tokens the tree already held, the request then attends over another request's copy of their KV. That copy is valid but not bitwise equal, because it was computed in a prefill of another shape.

A deterministic stock reproduction (targeted.py history) serves each of 12 prompts alone and after the earlier prompt sharing the longest prefix:

Configuration Prompts whose logprobs change
Plain, radix cache on 2/12, from output index 2
Plain, radix cache off 0/12
MTP, radix cache on 2/12

This explains the five prompts in #37 where the tap changed the output: the tap's timing decides whether the switch lands before decode step 2. It is a choice between valid copies, not state corruption, so I have not changed the engine. The KV-level confirmation is queued.

Noise floor additions

  • A fresh server reproduces the batch-1 pass bitwise on all 320 prompts.
  • At concurrency 32 it reproduces 296/320 (24 divergences, all ties), because batch composition depends on arrival timing.

Tools and review follow-ups

  • The state tap now hashes, before each tapped forward, the KV, convolution and SSM caches that forward reads. A first run crashed on 524,288-element SSM rows; this is fixed by hashing long rows in chunks, and 0001-state-tap.patch is regenerated.
  • mechanism.py gains --repeat-of, for repeats of one prompt within a run, and --start-output-index.
  • analyze_all.sh regenerates the light evidence; it reproduces the committed files byte for byte. It also writes first_difference_by_module.csv for the paper figure.
  • "c32" comparisons are relabelled as concurrency 32 with at most 16 running.

Validation

  • pytest tests/test_state_safety_*.py: 10 passed.
  • Hooks pass on all changed files except mypy, whose 9 errors on main are pre-existing; the new files are mypy-clean.

Pending, queued

  • Truncation and stops for the tree and plain decode.
  • Checkpoint reuse, aborts with slot reuse, chunked prefill, and repeats.
  • The rest of the configuration matrix.
  • The KV-level radix confirmation and the humaneval-0044 test.

analyze_all.sh regenerates the noise floor, rejection-position drift and
the targeted summary from the raw runs (it reproduces the committed
evidence byte for byte). mechanism.py --repeat-of compares the tapped
repeats of one prompt inside a run.
…r figure

analyze_all.sh derives evidence/state_safety/first_difference_by_module.csv
(pair, module, layer, kind, count) from the mechanism summaries, which
now keep every module rather than the top 20.
Every c32 run used --max-running-requests 16, so decode batches had at
most 16 rows; the pair labels and the README now say concurrency rather
than batch size.
The cache hashing crashed on a layer's SSM state (524,288 elements per
slot); rows longer than the coefficient vector are now hashed in chunks.
…ence

Truncation and stop tokens at every index inside a verify cycle are
bitwise exact for MTP steps 3 and 5 (157/157, 240/240; 160/160,
240/240). A stock reproduction shows that with the radix cache on a
request's output depends on which earlier request computed its shared
prefix (2 of 12 prompts from output index 2, plain and MTP; 0 of 12 with
the radix cache off), through the req_to_token rewrite in
cache_unfinished_req. Fresh-server repeats: bitwise at batch 1, 24/320
ties at concurrency 32.
@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-01T03:20:36.938440Z e49177d 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: e49177dc26

ℹ️ 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/state_safety/analyze_all.sh Outdated
runs="$HOME/vp-data/state/runs"
export OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 MKL_NUM_THREADS=1
# shellcheck source=/dev/null
source "$HOME/verified-progress/scripts/sglang_env.sh"

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 Source the environment from the actual checkout

When this script is run from the documented checkout at /workspace/verified-progress, it exits immediately because $HOME/verified-progress/scripts/sglang_env.sh does not exist. Since here already identifies the script's location, derive the repository root from it and source that checkout's scripts/sglang_env.sh; otherwise the new evidence-regeneration command only works when the repository happens to be cloned under that hard-coded home-directory name.

AGENTS.md reference: AGENTS.md:L7-L10

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 395ee94. The script derives the repository root from its own location (repo="$(cd "$here/../.." && pwd)") and sources $repo/scripts/sglang_env.sh, so it works from any checkout.

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: REQUEST CHANGES

Reviewed head e49177d against main (merge base 9932235). The radix finding is stated well, and the relabelling and the module CSV are correct. Three items block: the H5 configurations, patch 0002's gate, and one Codex comment.

Checked and correct

  • Radix history dependence (integrator check 1).
    • The README describes it as a choice between valid KV copies that depends on history and timing.
    • The mechanism matches the pin: UnifiedRadixCache.cache_unfinished_req (python/sglang/srt/mem_cache/unified_radix_cache.py:1161) rewrites the request's req_to_token row (req_to_token_pool.write, line 1263).
    • "Not state corruption" is supported. "We found no case where this produced more than a near-tie flip" is worded as an observation on these runs, not a bound.
    • The KV-hash confirmation is marked pending.
    • The reproduction in targeted.json matches the table: logprobs identical for 10/12 with the radix cache on, 12/12 off, and 10/12 for MTP; tokens identical 12/12 throughout.
  • Relabelling (check 3). "c32" is defined once as 32 requests in flight on a server capped at 16. The tables and the mechanism headings say "client concurrency 1 vs 32 (at most 16 running)". noise_floor.csv uses "concurrency 1 vs 32 (cap 16)". No "batch 32" remains in the README, the CSVs or the JSON.
  • first_difference_by_module.csv (check 4). The README documents its columns (pair,module,layer,kind,count) and the kind values, and they match the file's header and rows.
  • H5 numbers. These match targeted.json:
    • truncation: 157/157 (1-4 tokens kept) and 240/240 (1-6);
    • stops: 160/160 with 120 inside the block, and 240/240 with 200 inside;
    • extensions: 139/160 (19 ties, 2 one-ulp) and 210/240 (30 ties).
  • Noise-floor additions. The fresh-server rows are 0/320 at concurrency 1 and 24/320 at 0.35/1K for concurrency 32.

Blocking

B1. The H5 claims do not name their configurations (integrator check 2; README "Results so far" and the PR body).

targeted.json records:

  • flags --speculative-algorithm EAGLE --speculative-num-steps 3|5 --speculative-eagle-topk 1 --speculative-num-draft-tokens 4|6;
  • no --disable-radix-cache, so the radix cache was on;
  • concurrency 1, targeted.py's default;
  • 40 prompts per test.

Fix: state all of that next to each count, for example "MTP steps 3, top-1, radix cache on, concurrency 1: 157/157". The radix setting matters here, because the warm/cold extension result depends on it.

B2. Patch 0002 has no gate of its own (integrator check 5; engine/sglang/README.md, the state section).

  • The section says "Both patches ... change nothing unless the variables below are set". But 0002-verify-kv-split-deterministic.patch has no variable: it changes FlashInfer's target-verify plan whenever --enable-deterministic-inference is on, because prefill_split_tile_size is set then.
  • So any deterministic-mode run on this engine branch differs from stock deterministic mode.
  • Fix: gate it behind an environment variable that is off by default (for example SGLANG_STATE_VERIFY_FIXED_SPLIT=1), regenerate the patch, and give it its own row in the README's table of variables. Say which committed run used it, with the variable set.

B3. Codex P2: analyze_all.sh sources a hard-coded path (experiments/state_safety/analyze_all.sh:15).

  • It sources $HOME/verified-progress/scripts/sglang_env.sh, so it fails in any other checkout.
  • Fix: derive the repository root from here and source that checkout's script.

Suggestions (not blocking)

…lyze_all

Address review of PR #59: patch 0002 now applies only with
SGLANG_STATE_VERIFY_FIXED_SPLIT=1 under deterministic inference (engine
README lists every variable); each H5 count states its configuration
(MTP steps, top-k 1, radix on, concurrency 1, 40 prompts); the radix code
path cites file and line; analyze_all.sh sources the env script from its
own repository root.
@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE

Re-reviewed head 395ee94 (f37ccdb and 395ee94 on e49177d). All three blocking items and both suggestions are fixed.

  • B1 (fixed). Every H5 count now names its configuration, which matches targeted.json's flags: native MTP (EAGLE) with 3 or 5 steps, top-k 1, radix cache on (extra_buffer), overlap and graphs on, one request in flight, the first 40 prompts. The truncation test notes the flushed cache, and the warm extension notes the restored GDN checkpoint. The history reproduction states its setup (one request in flight, 64 new tokens). run_targeted.sh now matches the runs as executed, history included.
  • B2 (fixed). Patch 0002 sets verify_split_tile_size only when SGLANG_STATE_VERIFY_FIXED_SPLIT=1. Without it the verify plan passes None, as stock does, so the patch is off by default even in deterministic mode. git am of 0001-0002 at bd66ce343e gives tree 7355701304, the tree of engine 9341fb82f7. flashinfer_backend.py already imports os. The engine README has a variable table for both patches. Both READMEs say that the committed verifyfix run predates the gate, with the change on unconditionally, which setting the variable reproduces.
  • B3 (fixed). analyze_all.sh derives the repository root from its own path.
  • Suggestions (taken). The README cites unified_radix_cache.py:1161 and line 1263, and "as expected" now reads "consistent with".
  • Merge and checks. Pre-commit passes on the changed files. A test merge into current main is clean. The branch is behind main but has no conflicts. There are no new Codex comments; the earlier one is addressed.

@SamMausberg
SamMausberg merged commit 9ad5344 into main Oct 1, 2026
SamMausberg added a commit that referenced this pull request Oct 1, 2026
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.
SamMausberg added a commit that referenced this pull request Oct 1, 2026
Appendix D: integrate the state-safety results (#59)
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