Skip to content

Real-head replay, H2: drift ratio and transport on DFlash-4B and MTP-4B - #35

Merged
SamMausberg merged 12 commits into
mainfrom
geometry/h2-transport
Sep 30, 2026
Merged

SamMausberg merged 12 commits into
mainfrom
geometry/h2-transport

Conversation

@SamMausberg

@SamMausberg SamMausberg commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

H2 on real hidden states: the transport-versus-self-evidence comparison on aligned draft/target head inputs from the public DFlash drafter for Qwen3.5-4B, with the native MTP capture to follow. The PR also carries follow-ups to #16 (patch location, start-up lock, R-stock labels) and the Codex review fixes.

Results so far (committed; held-out prompts)

  • Alignment (alignment_dflash4b.json): the capture (z-lab/Qwen3.5-4B-DFlash @9a1996cc, block 16, 320 prompts, 24,020 verify blocks) reproduces the engine's decisions from the captured head inputs.
    • Draft tokens: 98.2% of 360,300 slots. Every mismatch lies within one BF16 spacing.
    • Target argmax: 98.9%, with the same property.
    • Accept lengths match on every block.
  • Drift ratio (rho_dflash4b.*, 40,000 pairs): rho = ||h_t - h_d||_2 / ||h_t||_2 has median 0.92 and smallest value 0.82.
    • The per-row int8 threshold ||e_i||_2 / r_c(i) has median 0.0085.
    • The draft's head input has a fixed norm of 50.6 against about 159 for the target, and a median cosine of 0.41 with it (stats_dflash4b.json).
  • Transport (transport_dflash4b.*, 4,000 pairs):
    • Greedy: across every certified family (scalar, coordinate, grouped, low-rank, best-of) and tiling (contiguous, random or k-means; 64 to 1,024 rows), the bounds skip at most 0.6% of the vocabulary on average (p90 0.8%). That is no better than the static screen.
    • Sampled acceptance stays undecided with probability 0.92-0.96 on average.
    • Real verify-batch unions need at least 99.5% of the head.
    • Oracle radii lose to the batch union at 16 rows.
    • Drift scaling, a model extrapolation, shows rho would have to fall about 10x before half the rows are skipped.
  • Self-evidence (selfevidence_dflash4b.*): on the verify rows a greedy verifier needs, int8 per-row needs 1.57 candidate rows on average (p99 8) and int8 g128 needs 1.35. This matches plain decode.

The evidence README (evidence/head_geometry/README.md) gives the command and code commit for every file, a decision summary scoped to what was tested, and a per-tiling transport table.

Review follow-ups

  • Real-head replay: head-input capture, transport and self-evidence bounds #16 and the reviewer: the patch moved to engine/sglang/patches/geometry/. The R-stock tables label which accumulation models are justified for the stock tensor-core GEMM. R-bf16 is no longer described as the stock computation.
  • Codex, env path: run_capture.sh sources scripts/sglang_env.sh from its own checkout.
  • Codex, held-out split: rho statistics and plot data use held-out prompts only, and the per-pair CSV carries prompt id and split. The rerun moved the quantiles by at most 0.003.
  • Codex, start-up memory: the free-memory check runs inside scripts/gpu_startup_lock.sh, immediately before the launch. If memory is short, the lock is released and the check retried.
  • Codex, shutdown: the server runs in its own process group. Shutdown escalates from SIGTERM to SIGKILL on the group, and the script fails if the group survives.
  • analyze_selfevidence.py can evaluate a subset of heads, and splits verify rows into those the verifier needs and those after the first rejection.

Still to come in this PR

Checks

pre-commit passes on the changed files, and pytest tests/test_head_geometry_bounds.py passes.

…art-up

- engine/sglang/patches/geometry/0001-head-capture-replay-dumps.patch, with a
  geometry section in engine/sglang/README.md (the new per-workstream layout).
- run_capture.sh launches the server and waits until it is healthy under
  scripts/gpu_startup_lock.sh, so concurrent shared jobs no longer race in
  SGLang's free-memory probe; the cleanup trap waits for the server to exit.
- The R-stock tables label which accumulation models are justified for the
  stock BF16 tensor-core GEMM.
DFlash-4B (z-lab/Qwen3.5-4B-DFlash @9a1996cc, block 16): the captured draft
and target head inputs reproduce the engine's draft tokens at 98.2% and
target argmax at 98.9% of 360,300 slots, every mismatch within one BF16
spacing, and accept lengths match on all 24,020 blocks. rho is 0.92 median
(minimum 0.82 over 40,000 pairs), about 100 times the per-row int8
threshold. analyze_rho.py reports the minimum and caps its per-pair CSV.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 30, 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-09-30T20:57:00.426775Z 63c70f6 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.

…reach

--heads restricts the evaluated low-precision heads (the plain-decode run
showed the outlier, rotated and centred variants change little), and verify
and draft sets report candidate counts separately for rows the verifier needs
(all earlier drafts accepted) and rows after the first rejection.
…ifts

The DFlash draft's head input has a fixed norm of 50.6 (unit-gain final
norm) against about 159 for the target, and a median cosine of 0.41 with it,
so rho stays near 0.9 at every block position, outcome, domain and context
length.

@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: 63c70f6cec

ℹ️ 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 on lines +226 to +229
rows_out = np.arange(len(keep))
if len(rows_out) > args.csv_pairs:
rng_csv = np.random.default_rng(args.seed)
rows_out = np.sort(rng_csv.choice(rows_out, args.csv_pairs, replace=False))

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 Restrict the plot sample to held-out prompts

The new sample is drawn from every entry in keep, which only excludes unknown prompt IDs and still contains both analysis and held-out prompts. The committed JSON confirms that only 19,858 of the 40,000 analyzed pairs are held out, so this plot CSV mixes the fitting split into an H2 result whose protocol requires held-out prompts (paper/sections/transport.tex:124). Because the CSV exports neither the split nor a prompt ID, downstream plotting cannot filter the analysis rows back out; select held-out indices before sampling or include enough metadata to filter them.

Useful? React with 👍 / 👎.

Comment on lines +122 to +124
CAPTURE_DIR="$out/heads" "$HOME/verified-progress/scripts/gpu_startup_lock.sh" \
bash -c 'launch_and_wait "$@"' _ "$out/server.pid" "$port" "$out/server.log" \
--model-path "${model[0]}" --revision "${model[1]}" "${common[@]}" "${args[@]}" || {

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 Recheck free memory after acquiring the startup lock

When two shared runs reach the free-memory check before either server allocates, both can pass NEED_FREE_MIB; the first then launches and consumes HBM, and the second acquires this lock and starts without rechecking. Its --mem-fraction-static probe can therefore see less than the amount required for weights and caches and fail, which is the concurrent-start race this change is meant to prevent. Perform a final wait/check inside the locked command immediately before spawning the server.

Useful? React with 👍 / 👎.

Comment on lines +116 to +119
for _ in $(seq 1 120); do
kill -0 "$server" 2>/dev/null || return 0
sleep 1
done

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 Force termination after the cleanup timeout

If SGLang is slow or hung during shutdown and remains alive for more than 120 seconds after SIGTERM, this loop simply exhausts and stop_server returns successfully. Since the launcher was deliberately orphaned when the lock shell exited, the script then leaves a server holding the GPU allocation and port, which can break or misdirect later captures. Escalate to killing the process tree after the timeout, or continue waiting rather than silently completing cleanup.

Useful? React with 👍 / 👎.

…nputs

4,000 held-out rows per set, int8, FP8 and int4 heads: on the verify rows a
greedy verifier needs, int8 per-row needs 1.57 candidate rows on average (p99
8), as on plain decode; rows after the first rejection sit on wrong prefixes
and need more. No envelope violations.
Every certified family (scalar, coordinate, grouped, low-rank) on every
tiling (contiguous, random, k-means; 64-1,024 rows) skips at most 0.5% of the
vocabulary for greedy verification, no better than the static screen; the
partition interval spans about 138 nats, so the acceptance test is never
decided. Oracle (realized) radii would skip 96% for one row but need 97% of
the vocabulary over random batches of 16. Drift scaling shows rho must fall
about 10x before half the rows are skipped.
…shutdown

- run_capture.sh sources scripts/sglang_env.sh from its own checkout.
- The free-memory check now runs inside the start-up lock, just before the
  launch; if memory is short the lock is released and the check retried.
- The server runs in its own process group; shutdown escalates from SIGTERM
  to SIGKILL on the group and fails if the group survives.
- analyze_rho.py reports held-out prompts only by default and writes prompt
  id and split into the per-pair CSV.
The rerun on 40,000 held-out pairs changes the rho quantiles by at most
0.003; the plot sample now carries prompt id and split.
@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: REQUEST CHANGES

Reviewed head 2f1e17b (54 behind main). A trial merge into main is clean; engine/sglang/README.md auto-merges. This covers the DFlash-4B half; the MTP-4B half will be reviewed when it lands.

The held-out discipline is now right everywhere, and the three Codex comments are addressed. The problems are in the "Decision so far" summary: three numbers are stated more strongly than the committed evidence supports, and "refuted" is not scoped.

Blocking

B1. "no certified bound family or tiling skips more than 0.5% of the vocabulary" is wrong (evidence/head_geometry/README.md:25).

  • The evidence. In transport_dflash4b.csv (group all, non-oracle, non-drift rows), k-means tiles of 64 rows skip the most:
    • kmeans64|best|transport|rows_skipped: mean 0.591%, p90 0.771%.
    • kmeans64|coord|transport: 0.590%.
    • rowlevel_rows_skipped: 0.594%.
  • Fix. Say "at most 0.6% of the vocabulary on average (p90 0.8%)".
  • Possible note. It is worth adding that the same k-means tiling skips 36% of its tiles, which are almost all near-singleton tiles. That is why its tile and row fractions differ so much.

B2. "sampled acceptance is never decided" overstates the evidence (README:26).

  • The evidence. For the best certified family (kmeans64|best), the acceptance-uncertainty probability P_? at the draft token has median 1 and p10 1, so at least 90% of pairs are fully undecided. The mean is 0.935 at T = 1 and 0.919 at T = 0.7, so the test is decided about 6-8% of the time on average.
  • Fix. "sampled acceptance stays undecided with probability 0.92-0.94 on average (median 1) under every certified family". Oracle radii give 0.52-0.57, if you want the contrast.

B3. "H2, transport: refuted on DFlash-4B" needs its scope (README:23).

  • The problem. The result covers the bound families and tilings that were tested, this drafter, and greedy plus T = 1 and 0.7. As written it reads as a refutation of transport in general.
  • Fix. Name the scope in the bullet:
    • bound families: scalar l_inf, coordinate, grouped l2 (32 and 128), low-rank (d64, d256, w64) and their best;
    • tilings: contiguous 64/256/1,024, random 256, k-means 64/256/1,024;
    • the z-lab DFlash-4B drafter, on the 160 held-out prompts.
      For example: "refuted for these bound families and tilings on DFlash-4B".

B4. "the union over real verify batches needs 99.9% of the head" is slightly high (README:26).

  • The evidence. Across tilings and families, the real-batch union needs 99.48% to 100% of rows (real_batch_unions). The lowest is k-means 64 on batches of 9-16 rows (99.48%), and the contiguous tilings are at 99.93% and above.
  • Fix. Say "at least 99.5% of the head".

Checked and correct

  • Held-out prompts only. Every H2 and H3 statistic uses them:
    • rho_dflash4b.json records split: heldout with 40,000 pairs from 160 prompts, and all 15,000 rows of rho_dflash4b_pairs.csv are heldout. This closes Codex's comment on the plot sample.
    • analyze_transport.py fits its Delta-PCA bases on the analysis split and evaluates on held-out pairs only (4,020 pairs, 110 prompts).
    • analyze_selfevidence.py and analyze_stats.py (the held() filter) are held-out too.
    • The alignment check uses all 320 prompts, which is right for a data-validity check.
  • Codex on run_capture.sh.
    • The free-memory check now runs inside the start-up lock, and the launcher returns 2 so the retry waits outside the lock.
    • Shutdown signals the setsid process group, escalates to SIGKILL after 120 s, and fails loudly if the group survives.
    • The environment is sourced from $repo.
  • Numbers checked against the committed files.
    • rho quantiles: 0.823 / 0.875 / 0.917 / 0.964 / 1.039.
    • Real-batch unions for the contiguous tilings need 99.93-99.95% of rows.
    • Oracle radii with random batches of 16 need 96.8% of rows.
    • The DFlash-4B self-evidence table matches by_reached: verify-needed int8 per-row 1.573 / 1 / 8 / 22 / 75.9%, g128 1.354 / 1 / 6 / 17 / 81.6%, after-rejection 4.031, draft-needed 1.281 and 1.174; 1,162 reached rows.
  • Hooks and attribution. Pre-commit (ruff, mypy, codespell, shellcheck) passes on the changed code, and there are no AI co-author lines.

Drift scaling (not stated in the README yet; blocking when it is)

transport_dflash4b.csv contains the drift-scaling replay h_d(s) = h_t - s Delta. When the README or the paper quotes it:

  • Label it as a model extrapolation. It scales the realized drift of this drafter; it does not measure a drafter that exists.

  • Use one statistic. For kmeans256|best, the mean share of rows skipped is:

    • s = 0.1 (10 times smaller rho): 49.2% (median 49.4%);
    • s = 0.03: 76.9% (median 96.5%).

    For contig256|best the same figures are 57.3% (median 75.7%) and 83.1% (median 99.3%).

  • Don't mix statistics. "10x for 49%, 30x for 96%" pairs a mean with a median. The distribution at s = 0.03 is bimodal (p10 7%), so quote both or the mean.

  • Batch unions. Say that batch unions then apply: even oracle radii need 96.8% of rows at B = 16.

Suggestions (not blocking)

  • A transport section in the README. The decision rests on transport_dflash4b.*, but the README has no section presenting them. A short table would let a reader check the decision without the 4,760-row CSV: best family per tiling (mean and p90 skip), P_? at T = 1 and 0.7, and unions at B = 1, 16, 128 including oracle.

  • The R-stock sentence in the "For kernels" bullet. "about 2% of positions (bucket-exact rule with the conservative model: 1.4%)" mixes rules. The paper's figures are:

    • gap rule: 2.18% (1.19e-4) or 3.03% (conservative);
    • bucket rule: 0.35% or 1.40%.

    Stating it as "gap rule 2.2-3.0%, bucket rule 0.35-1.40%" would match the paper.

  • PR body. It still lists transport and self-evidence as "still to come". Update it before merge.

The decision summary now names the tested families, tilings, drafter and
prompts; gives the largest certified skip as a mean (0.6%, p90 0.8%), the
undecided probability of sampled acceptance as 0.92-0.96 on average, and the
real-batch union as at least 99.5%; labels drift scaling as a model
extrapolation with one statistic per claim; and adds a per-tiling transport
table.
@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE

This re-review covers head 61ce255 and the DFlash-4B half. B1-B4 are fixed, and I checked every new number against transport_dflash4b.csv and .json.

  • B1. "at most 0.6% on average (p90 0.8%, k-means 64-row tiles), no better than the static screen" matches: transport 0.591% and static 0.577%.
  • B2. "undecided with probability 0.92-0.96 on average (median 1)" covers P_? at the draft token (0.935 at T = 1, 0.919 at T = 0.7) and averaged over x ~ q (0.964 and 0.930). The added retained-tail figure, 0.58 on average with median 1, is kmeans64|best|transport|p_unresolved_x_retain64|t1.0 = 0.583.
  • B3. The verdict is now scoped to the listed bound families and tilings, to z-lab/Qwen3.5-4B-DFlash @9a1996cc and to the 160 held-out prompts. MTP-4B is marked pending.
  • B4. "at least 99.5%", with the range 99.48-100% in the table note.
  • The new transport table. All 7 rows match: transport and static skip, oracle mean and median, median log(Z+/Z-) at T = 1, and E_q P_? mean and median.
  • Random groups. Oracle radii on k-means 256-row tiles need 63%, 97% and 99.9% at 4, 16 and 64 pairs, which matches.
  • Drift scaling. It is labelled a model extrapolation (h_d = h_t - s Delta).
    • The means 1.6%, 49%, 77% and 84% and medians 0.3%, 49%, 96% and 99% match kmeans256|best at s = 0.3, 0.1, 0.03 and 0.01.
    • E_q P_? of 1.00, 1.00, 0.96 and 0.66 matches.
  • The R-stock line. It now separates the bucket-exact rule (1.4% and 0.35%) from the stock_gap condition (2-3%).
  • Hooks. Pre-commit passes.

The held-out discipline and the Codex fixes verified in my first review are unchanged. This approval covers 61ce255. The MTP-4B commit needs its own review before merge.

@SamMausberg
SamMausberg merged commit 471ac85 into main Sep 30, 2026
SamMausberg added a commit that referenced this pull request Sep 30, 2026
…nel contract

The paper now argues in dependency order: setting and what the stock engine
computes, the five contracts and the R-stock gap and interval theorems, the
certified low-precision head with its measured candidate sets and fallback
shares, sampled decisions, transport and its measured failure, exactness under
speculation, the stack, drafting and repair hypotheses, the serving protocol,
related work, and a discussion that merges the hypothesis and failure tables.
Secondary derivations, untested mechanisms, engine notes, CPU evidence,
reproduction and attribution move to appendices. Evidence paths, pull request
numbers and pending work move to an evidence register and a development record
(Appendix A); the text cites [En] for committed evidence and [pending Dn] for
designed work, with the scientific status in the prose.

Integrates merged evidence: H2 on DFlash-4B (#35) and MTP-4B (#47), the
overlapped roofline (#44), the frontend diagnosis (#46), the fifth contract
witness (#41) and the precision counts after #43. Folds in the Codex items on
#21 (quantiles over all rows), #32 (pooled tau, GSM8K series) and #36.

Typography: Charter text, a plain title block with the repository URL,
greyscale-safe figures, a new mechanism figure (Figure 1) replacing three
overlapping flowcharts, a drift figure and transport table, two-panel
candidate and acceptance figures, and tables reorganized instead of shrunk.
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