Repository navigation
Real-head replay: head-input capture, transport and self-evidence bounds - #16
Conversation
A capture-only SGLang patch records the exact LM-head inputs (draft and target, BF16 bits) with the draft tokens, target argmax and accept lengths of each verify step, for NEXTN/MTP, DFlash and plain decode. Adds the seeded public prompt set (320 prompts, split by prompt before any fitting), the capture driver and client, record loaders and an alignment check that recomputes both argmaxes from the captured inputs. The whitespace hooks now skip engine/sglang/patches/*.patch so that format-patch files stay applicable.
bounds.py implements tilings (contiguous, random, k-means), the paper's scalar, coordinate, grouped and low-rank transport radii and the static screen, integer and FP8 quantized heads with row, blockwise and Hoelder envelopes, outlier-exact, rotated and two-plane (cascade) variants, and the accumulation terms from the theory notes. The analysis scripts evaluate candidate sets, skip fractions, partition widths, P_? and real-batch unions on held-out captures. Tests check that every bound encloses exact values on random BF16 heads.
analyze_rho.py computes rho = ||h_t - h_d||/||h_t|| on aligned pairs, the per-row threshold ||e_i||/r_c(i) from 64-row mean-centred tiles (the PR #7 definition), head-metric drift ratios, realized per-tile errors of both mechanisms and the resulting certification rates. The transport analysis gains oracle (realized) tile radii as a ceiling and a drift-scaling replay h_d(s) = h_t - s Delta that shows how much drift reduction transport needs. Adds the DFlash-4B arm and CPU execution for the analyses.
analyze_rho.py now writes a per-pair CSV (position, outcome, domain, context, rho) and a quantile table with the weight-only per-row thresholds, and export_candidate_ccdf.py turns a self-evidence run's per-position candidate counts into CCDF columns for the paper's figures.
Plain decode: the captured head inputs reproduce the engine's greedy token at 99.51% of 105,269 positions, every mismatch within one BF16 spacing. Self-evidence on 6,005 held-out positions: int8 heads certify with 1.3-1.6 candidate rows on average at about half the BF16 bytes; FP8 and int4 do not. P1 kill test: an INT8 final-FFN surrogate adds little beyond certifying the head alone.
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. |
stats_plain4b.json records norms, margins, top-m mass, hidden-dimension energy and head statistics, and for each quantizer the rigorous row envelope against the realized error (about 75x wider) and why mean-row centring enlarges the errors of the rows that compete for the argmax.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 277d392af6
ℹ️ 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".
| max_new="${MAX_NEW_TOKENS:-384}" | ||
| export SGLANG_WORKTREE="${SGLANG_WORKTREE:-$HOME/sglang-wt/geometry}" | ||
| # shellcheck source=/dev/null | ||
| source "$HOME/verified-progress/scripts/sglang_env.sh" |
There was a problem hiding this comment.
Source the environment from the detected repository
In the checked /workspace/verified-progress environment, HOME is /root and /root/verified-progress/scripts/sglang_env.sh does not exist, so every documented capture invocation exits here under set -e before launching SGLang. The script already computes repo from its own location on line 16; source $repo/scripts/sglang_env.sh instead so the required environment setup works regardless of checkout location.
AGENTS.md reference: AGENTS.md:L7-L10
Useful? React with 👍 / 👎.
For dense BF16, int8 self-evidence, transport and the static screen, count weight, metadata and evidence bytes, kernels and fallbacks on the captured batches, and price them with the profile workstream's measured head chain. Outputs are labelled model predictions.
work_model.py accepts the kernel workstream's measured int8 envelope-pass sweep and models both a batch-level dense fallback and per-row resolution of undecided rows.
|
Verdict: REQUEST CHANGES Reviewed at What I ran and checked
Blocking1. Committed files cite the theory notes and use the retired contract name "C1".
2. The H3 numbers are R-real only; the adopted contract is R-stock, and its fallback rate is not reported.
3. The capture configuration is not stated with the evidence.
4. An unverified mechanism claim.
Suggestions (non-blocking)
|
The accumulation gammas now come from the Accumulator models of src/precision_reference.py (fused tensor-core adder, blocked FP32 tree). The self-evidence analysis names its reference R-real and also reports the R-stock fallback share: positions whose R-real winner fails the stock_gap condition against some row. Alignment is reported per draft position, and the transport CSV breaks down only the headline tilings and bounds.
- The capture patch is regenerated from an SGLang commit authored with the configured git identity (same content). - READMEs name the R-real and R-stock references from the merged src/precision_reference.py instead of coordination notes, state the capture server flags, label batch unions as capture-run batches, describe the two unexplained plain-decode positions as consistent with (not proven to be) cuBLAS rounding, and justify the 4-step MTP capture against the 3-step arms. - The DFlash-4B arm uses block size 16 with FlashInfer linear-attention backends, the configuration validated by the drafter workstream.
|
Verdict: REQUEST CHANGES Re-reviewed at Resolved.
Also checked:
Still blocking: item 2, the R-stock fallback. The README now says R-real and R-stock differ on about 0.5 % of positions, but the H3 section still reports only R-real candidate counts. It does not say what R-stock costs. Under the adopted contract, every position whose exact top-2 margin is at most
Non-blocking.
|
Rerun of the self-evidence analysis with the reference accumulation models: R-real candidate counts are unchanged up to the last digit, and the new R-stock measurement shows the gap condition fails at 1.9-3.0% of positions (15-22% of capture-run batches), a floor set by the BF16 spacing.
|
Verdict: REQUEST CHANGES Re-reviewed at
One new sentence blocks. "Resolving those rows one at a time keeps the cost small; running the dense head for the whole batch would not" (README, end of the R-stock section) has two problems:
Replace the sentence with a statement of what the table shows: the fallback runs the stock head at the served shape, for 15-22 % of capture-run batches. Say that a cheaper per-row resolution would need either a batch-invariant stock reference or a different contract, and that its cost is not yet measured. |
|
Verdict: REQUEST CHANGES Re-reviewed at One clause remains. "the kernel workstream has measured that for M = 1-256 on this stack but has not yet committed it as evidence" states a result, and a range, that rests on uncommitted work. That is the same standing rule applied to PR #6, where team measurements without committed evidence were removed. Replace the clause with "whether it is on this stack is pending the kernel workstream's evidence", or cite the committed file once it lands. Everything else in the PR is approved on my side. |
analyze_rstock.py compares the stock_gap sufficient condition with a bucket-exact rule that rounds each row's admissible accumulator interval to BF16 and applies the first-index tie rule. On the same 6,005 positions the bucket rule needs the stock kernel at 0-1.4% of positions depending on the accumulation model, against 1.95-3.03% for the gap rule, and no certified token differs from the engine's. The README no longer states the kernel workstream's uncommitted invariance result.
|
Verdict: APPROVE Re-reviewed at New scope: the bucket-exact R-stock rule (
Suggestion (non-blocking, before these numbers reach the paper): label which gamma a certifying kernel may rely on.
|
Real-head replay for H2 (transport) and H3 (self-evidence) on Qwen3.5-4B, with the capture patch, the bound library, the analyses and the first committed evidence. The PR stays open while the MTP-4B and DFlash-4B captures, which wait in the GPU queue, add the transport numbers.
What is here
engine/sglang/patches/0001-head-capture-replay-dumps.patch, capture only, inert unlessSGLANG_HEAD_CAPTURE_DIRis set).LogitsProcessorstashes the exact tensor it hands to the LM head. The NEXTN/MTP, DFlash and plain-decode paths write one record per step with aligned draft and target head inputs (BF16 bits), the tokens, the engine's argmax and the accept lengths.return_hidden_stateswas not enough: it exposes neither the MTP draft's head input nor the DFlash target's head input, and it carries no per-step decisions. The patch applies cleanly to the pin (git apply --check) and is authored with the configured identity.experiments/head_geometry/:bounds.py: tilings; the paper's scalar, coordinate, grouped and low-rank transport radii; the static screen; int8, int4 and FP8 heads with row, blockwise and Hoelder envelopes; outlier-exact, rotated, centred and two-plane cascade variants. The accumulation terms are taken from theAccumulatormodels ofsrc/precision_reference.py.tests/test_head_geometry_bounds.pychecks that every bound encloses exact values on random BF16 heads. It skips without torch.Findings so far (committed evidence)
alignment_plain4b.json): the captured plain-decode head inputs reproduce the engine's greedy token at 99.51% of 105,269 positions. Every mismatch lies within one BF16 spacing of the FP64 winner, and BF16-rounding the exact logits reproduces the engine at 99.998%.selfevidence_plain4b.*, 6,005 held-out positions, 0 envelope violations):stock_gapcondition except at 1.9-3.0% of positions, depending on the accumulation model for the stock GEMM. Those rows need the stock kernel. The ~2% floor is set by the BF16 spacing: those positions have an exact top-2 margin below one spacing.stats_plain4b.json): the rigorous int8 envelope is about 1 logit, 75 times the realized error, but the median top-1/top-2 margin is 7.3 logits.tail_killtest.json): an INT8 surrogate of the final FFN, even with an oracle error radius, lowers the single-candidate certification rate (71.8% versus 79.3% for the INT8 head alone). It can save at most 0.071 of the 1.41 GB tail, so certify the head alone.Checks
pre-commitpasses on every changed file, including mypy on the whole tree after mergingmain. Earlier commits on this branch usedSKIP=mypybecause of 9 errors then pre-existing onmain, none in the new files.pytest tests/test_head_geometry_bounds.pypasses (6 tests) in the SGLang venv..pre-commit-config.yamlnow also excludesengine/sglang/patches/*.patchfrom the auto-fixing hooks. The whitespace hooks were rewriting the format-patch file, which must stay byte-exact to apply.Not yet done
--max-mamba-cache-size 24, since otherwise the 0.25 memory fraction leaves one running request.