Repository navigation
State safety: differential harness and tensor-level divergence mechanisms - #37
Conversation
Launch SGLang configurations that should give identical greedy output (plain decode, native MTP with several step counts and a small tree, radix cache and overlap scheduling on or off, deterministic mode, FP32 LM head), send a fixed prompt set built from pinned public datasets, and record tokens, top-5 target logprobs and verify-cycle boundaries. compare.py locates first divergences and classifies them by the margin between the competing tokens in BF16 units; cycles.py buckets drift by the rejection position of the previous verify cycle. targeted.py adds truncation, stop-token, prefix-reuse, abort and chunked-prefill tests.
…etraction runs Each warm prefix case now regenerates the seeding request after a flush, so the GDN state it restores is the one checkpointed during speculative decode, and each cold case starts from an empty cache. Finishing-cycle checkpoints are also exercised with a stop token. Add a run-to-run repeat test at batch 1, a retraction group to the matrix, run metadata output, and make the batch-cap retry opt-in.
The shared lock queues behind exclusive benchmark jobs, so every separate hold waits its turn. Run several configurations or tests per hold (each under ~30 minutes) and drop the MTP same-server repeat passes, which the targeted repeat test covers.
tap_runs.py serves prompts from an SGLang tree with the state tap (engine patch), dumping per-module output hashes, head inputs and argmax logits for tagged requests. mechanism.py aligns the committed rows of two runs, finds the first module whose output bits differ, and at the token divergence checks whether the logits and head inputs are bitwise equal and whether the float64 logit order of the competing tokens agrees.
… errors Cover FlashInfer linear-attention decode and verify and both ReplaySSM paths in a 'paths' matrix group. Retry a server start only when it failed on memory, which other shared jobs can cause; any other startup failure is raised at once. tap_runs.py gains --repeats and --flush-each.
Slot numbers differ between runs, so compare by module name and order modules as the model executes them (children before parents, GDN convolution and recurrence before the gated norm). Classify a divergence by the exact logit order of the competing tokens and flag gaps inside the FP32 accumulation bound. tap_runs.py takes per-prompt generation limits.
A server left behind on the same port answers the health check, so the client would silently talk to the wrong configuration.
Concurrent SGLang start-ups by shared jobs race in the free-memory probe; take the same lock as scripts/gpu_startup_lock.sh around launch.
…ine patches engine/sglang/patches/state/0001-state-tap.patch is the bit-exact tensor tap used for divergence forensics; 0002 passes the deterministic KV split to FlashInfer's target-verify plan, which did not make MTP batch-invariant and is kept because a committed run used it. Both apply to bd66ce343e.
Plain decode vs MTP at batch 1 (167 prompts) and batch 1 vs 32 (40 prompts), analysed with the v3 tap: first differing module and mode per prompt, and at each divergence whether logits and head inputs agree and whether the float64 order of the two competing tokens agrees. Controls: a one-ulp perturbation at layer 9 down_proj and at layer 13's GDN recurrence. Classes are now decided by the exact order alone; the FP32 accumulation bound is reported as a flag.
Mechanism method, checks on the tap (neutrality, positive controls, the withdrawn first-version attributions), class definitions and results; plain-decode batch and same-server-repeat rates; the top-2 BF16 tie frequency; deterministic-mode observations; open questions. Pending runs are marked as pending.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…ng its prefix Radix insertion after a prefill can repoint a running request's prefix KV to another request's copy of the same tokens. Serve each chosen prompt on an empty cache and after the earlier prompt with the longest common prefix, and compare its tokens and logprobs.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9d561a4c3b
ℹ️ 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".
| out['exact_gap_within_accumulation_bound'] = bool(min(abs(ga), abs(gb)) <= bound) | ||
| if la[0] is not None and la[1] is not None and lb[0] is not None and lb[1] is not None: | ||
| out['bf16_gap_a'], out['bf16_gap_b'] = la[0] - la[1], lb[0] - lb[1] | ||
| if np.sign(ga) != np.sign(gb): | ||
| out['cls'] = 'order_flip' |
There was a problem hiding this comment.
Exclude accumulator-ambiguous gaps from flip classes
When exact_gap_within_accumulation_bound is true, the FP32 GEMM accumulator may order the competing logits differently from the float64 dot product, so ga/gb cannot distinguish an upstream order flip from accumulation or output rounding. The code records that ambiguity but still unconditionally assigns order_flip or rounding_flip; this affects 36 of the 129 divergent plain-vs-MTP cases in the committed evidence, making the reported 102/27 mechanism counts unsupported. Return an unknown/accumulator-ambiguous class before applying the sign test.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, fixed in eca6eb8. The class is now decided by the FP32 accumulator order in each run. Where a run's BF16 logits for the two tokens differ, that order is read from them (rounding to nearest is monotone). Where they tie, the float64 stand-in is used only if its gap exceeds the conservative accumulation bound; otherwise the case is accumulator_ambiguous. Corrected counts: plain vs MTP 85 rounding / 13 order / 31 ambiguous (was 102 / 27); batch 1 vs 32 13 / 17 / 10 (was 19 / 21). Where both the BF16 order and an out-of-bound float64 gap exist, they never disagree (float64_contradicts_bf16 is false in every case).
| in execution order, the first module whose output bits differ. Before that point every | ||
| tensor, and therefore every cached KV and GDN state, is bitwise equal, so the module | ||
| it names is the kernel where the two runs part. At the token divergence it then |
There was a problem hiding this comment.
Avoid inferring equality of unmeasured cache state
For paths involving verification rollback, radix-cache repointing, or batch-dependent cache writes, equal module-output hashes do not prove that the KV, convolution, or SSM cache buffers are equal: the tap hashes module outputs and core_attn_out, but never hashes those mutable buffers after updates. A latent cache difference can therefore appear only when a later kernel reads it, making that kernel the first observed divergence rather than necessarily where the runs parted. The attribution conclusions should either instrument the cache state itself or be qualified accordingly.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed. In eca6eb8 the README scopes the committed results to the first differing module output, and says why that is not yet the point where the runs part. The tap (0001-state-tap.patch) now also hashes, before every tapped forward, the caches that forward reads: KV per cached position and attention layer through the request's req_to_token row, and GDN conv and SSM state per layer. mechanism.py reports the first forward whose entering caches differ, and sets origin to cache when that precedes the first differing module output. A queued run repeats the MTP comparison and the five non-neutral radix cases with the cache hashes; I'll update the README with the outcome.
…e tap Address review: (1) where a run's BF16 logits for the two tokens tie and the float64 gap is inside the FP32 accumulation bound, the accumulator's order is undetermined, so the case is now 'accumulator_ambiguous' rather than a rounding or order flip; the accumulator order is read from the BF16 values wherever they differ. Corrected splits: plain vs MTP 85 rounding, 13 order, 31 ambiguous; batch 1 vs 32 13, 17, 10. (2) The tap now hashes the KV, convolution and SSM caches each tapped forward reads, and mechanism.py reports the first forward whose entering caches differ and whether it precedes the first differing module output. The committed results predate cache hashing, so the README scopes them to the first differing module output until the queued rerun lands.
|
Verdict: REQUEST CHANGES Reviewed head eca6eb8 (42 behind main). Both Codex P1 comments were taken up in the right direction:
The class counts, however, rest on an accumulation bound that is looser than the README says, and two statements go beyond the committed evidence. BlockingB1. The accumulator-order bound is not the conservative model, and the class counts depend on it (
B2. Two statements go beyond the committed evidence.
Checked and correct
Suggestions (not blocking)
|
…ontrol Address review of PR #37: the accumulator-gap bound is now gamma * (A_a + A_b) under the project's conservative model gamma(2K, 2^-23) (primary) and the Hopper wgmma model (1.19e-4), both reported per case. Plain vs MTP: 29/7/93 rounding/order/ambiguous (conservative), 89/16/24 (Hopper); batch 1 vs 32: 3/15/22 and 14/17/9. The README no longer claims the GDN kernels saw the same entering state (pending the cache-hash rerun), and the layer-13 control now has a committed decode-position result (--start-output-index 1); the controls are regenerated with the current class names.
|
Verdict: APPROVE This re-review covers head e95f92d. B1 and B2 are fixed, and every new count matches the regenerated JSON.
The rest of my first review still holds. The cache-hash rerun, the five tap-affected prompts and the remaining matrix are correctly marked pending. |
# Conflicts: # engine/sglang/README.md
|
Verdict: APPROVE Still approved at 29b7fec, a merge of main into this branch. Its parents are e95f92d (the approved head) and 9dc3745 (main). I checked that it is a pure conflict resolution:
|
B1: the divergence method no longer says that cached state agrees before the first differing module output; the tap hashes module outputs, and the cache check is pending (D14). The classification is #37's three-way one: tie rule, head GEMM, then rounding flip, order flip or accumulator-ambiguous under the conservative and the Hopper error models. Section 7.1 now reports #37's findings, led by the model-independent ones (the tie rule and the head GEMM cause none of the divergences; the first differing module outputs per pair), with a new Table 8 giving the split per named model and a new Figure 4 placing the first differing outputs by layer. The sampling and discussion text, the contribution list, the register (E20-E22) and the ledger follow. B2: the kernel section describes the design and says that no performance statement rests on the implementation under review; the code conversion and the bandwidth- versus issue-bound claims are removed or marked pending (D11). The integer-pass theorem now holds for any activation scale with gamma_3 (gamma_2 for a power of two), and says that an implementation must bound the residual of the codes it produced.
…bound compare_outputs.py reuses experiments/state_safety/compare.py: both runs' margins between the two competing tokens (tie, one_ulp, near, large) when both recorded logprobs, otherwise a one-sided class from the reference run and 'unknown' when the test token is outside its top-k. The panel-v2 equality files are reclassified (DFlash: 47 ties and 28 within one BF16 spacing on the plain side, 2 unknown); the probe now records top-5 logprobs and run_equality.sh records them on every run for a two-sided rerun. The README states that U_K is an oracle bound per cycle on the stock trajectory, states the 207 excluded terminal cycles and the direction of their bias, and adds the environment setup to the support-screen command.
The class formerly called exact-up-to-floor is exact-up-to-rounding: every first divergence against the arm's matched stock reference is a tie, one_ulp or near event (#37's classes), over 320 prompts x 256 tokens. bench/README.md records the rule with its time (2026-10-01 05:20 UTC) and that it was set after the first equality results; rates and ratios to the floor are reported beside each class, never as a test, and stock MTP's 1.29x-floor rate at rounding level is stated as a finding. Applied: mtp-tuned and mtp-tuned-triton (against stock MTP s3) and plain-tuned-triton (against plain c1) are exact-up-to-rounding; plain-tuned-replayssm is lossy (one large first divergence) and joins the quality holds; the Triton DFlash arms stay pending until their comparison against stock DFlash block 16. Exact arms carry exactness_note instead of a lossy note, so a lossy note added in code always makes an arm lossy. The Pareto builder takes --divergence classes.json and annotates each arm with its rate against plain c1.
evidence/bench/equality/ holds the comparator's summary, the per-pair report with rates, intervals and #37 classes, every first divergence, the arm-to-reference map and classes.json; the README section tabulates them. Corrected in bench/README.md: stock DFlash block 16 diverges at 4.38 per 1,000 (not 4.39) and stock MTP's ratio interval is 1.04-1.58.
This PR adds the state-safety workstream's differential harness and a tensor-level explanation of why stock SGLang configurations that should produce the same greedy output disagree. It is the evidence behind H5 and the exactness baseline the certified head will be compared against.
Why every stock divergence happens
Both greedy paths use one decision rule: a BF16
torch.matmulhead widened exactly to FP32, thentorch.argmax(first index among equal maxima) in the plain-decode sampler and in MTP verification. Identical logits therefore cannot produce different tokens, so "it diverged at a BF16 tie" describes where a divergence shows up, not why it happens.A bit-exact tensor tap (
engine/sglang/patches/state/0001-state-tap.patch) hashes every module output inside the CUDA graphs, one row per token, plus the GDN convolution and recurrence. Since review, it also hashes the caches each tapped forward reads.mechanism.pyfinds the first position and module where two runs' outputs differ. It then classifies the flipped token by the order of the two tokens' FP32 head accumulator values in each run. That order is read from the BF16 logits where they differ. Where they tie, it comes from float64 if the gap exceeds gamma * (A_a + A_b) under a named error model (the conservative gamma(2K, 2^-23), or the Hopper model), and is left ambiguous otherwise.mlp.down_projin a batched prefill (5). Of the 40 divergences:mlp.down_projis named 4/4 times. One in layer 13's GDN recurrence is named at that op 4/4 times when the search starts at the first decode position (tap_control_core13_decode.json), and as the enclosing module in prefill, where the GDN backend runs eagerly.Definitions of rounding flip and order flip are in
evidence/state_safety/README.md, with per-prompt records inmechanism_*.json.Noise floor measured so far
Open items
These are stated as open, not resolved:
qkv_projoutput is identical. The hypothesis is that radix-cache insertion repoints the running request's prefix KV to another request's copy; a radix-off test is queued.humaneval-0044's prefill does not repeat bitwise; a tapped test is queued.0002-verify-kv-split-deterministic.patchdid not make MTP batch-invariant under deterministic inference: 28 of 96 prompts still diverge. It is kept because a committed run used it.Validation
pytest tests/test_state_safety_compare.py: 7 passed.mypyonmainalready reports 9 errors insrc/,tests/andscripts/, and commits usedSKIP=mypyfor that reason;mypy experiments/state_safety tests/test_state_safety_compare.pyis clean.bd66ce343ewithgit amand reproduce the worktree diff exactly.Review comments
Both Codex P1 comments are addressed in eca6eb8, and the reviewer's B1 and B2 in e95f92d:
Nothing new was installed.