Skip to content

Round the Hopper accumulation constant up and rerun its replays - #139

Merged
SamMausberg merged 4 commits into
mainfrom
precision/hopper-gamma
Oct 1, 2026
Merged

SamMausberg merged 4 commits into
mainfrom
precision/hopper-gamma

Conversation

@SamMausberg

Copy link
Copy Markdown
Owner

The defect

The paper's Hopper accumulation model (Khattak and Mikaitis's BF16 wgmma adder, k = 16, F = 25, truncation, plus an FP32 split-K allowance) gives

gamma = (1 + u_v)^160 (1 + 2^-23)^160 - 1, u_v = 17 * 2^-25 + 2^-23,

which is 1.192163627848e-4 as an exact rational. The paper quoted it as \ghop = 1.19e-4, and the replays hard-coded that value (analyze_rstock.py, analyze_selfevidence.py key gamma_1.19e-4, mechanism.py 'hopper': 1.19e-4). That is 0.18% below the derived value, so every share reported "under the Hopper model" was computed with a bound smaller than the one the model gives. app_proofs.tex disclosed this; a certificate's error bound has to cover the derived value instead.

The fix

  • src/precision_reference.py: hopper_wgmma_gamma(n) computes the model's gamma exactly (Fractions) for an n-term dot product; float_up(x) rounds a Fraction up to binary64. At n = 2560 the result is 0.00011921636278483056, which here coincides with round-to-nearest.
  • experiments/head_geometry/bounds.py: hopper_gamma(dim) wraps the two for the stock head GEMM (no scale multiply). analyze_rstock.py and analyze_selfevidence.py use it.
  • experiments/state_safety/mechanism.py: error_models takes the Hopper value from the same helper (it now puts src/ on sys.path, as bounds.py does).
  • The evidence key gamma_1.19e-4 keeps its name for stability; it still names the value to three digits, and gammas/rstock_gammas record it exactly. The geometry README says so.
  • tests/test_state_safety_mechanism.py: derives the constant independently from its definition and checks that the value the analysis uses is the smallest binary64 at or above it.
  • Paper: \ghop = 1.193e-4 (rounded up at the quoted precision). The Hopper bullet in Appendix A.2 drops the "used exactly that rounded value" disclosure and says the replays compute the value exactly and round it up to the next double; the wgmma-only intermediate (about 1.0014e-4) is now written with \approx. At the integrator's request, \gcons also moves from 6.1e-4 to 6.11e-4, since gamma_2D(2^-23) = 6.1072e-4 and no displayed bound constant should be rounded down. The replays already used 6.1120e-4 (conservative fused-adder maximum plus one scale multiply) and 6.1072e-4 (mechanism.py), so no rerun was needed for it.

What was rerun

Code first (commit 0769b2b), then each analysis from its recorded command at that commit, CPU only, under gpu_lock.sh -s (priority granted by the integrator). The branch was then merged with main rather than rebased, so 0769b2b stays in its history; the generator files are identical at the head.

Head geometry, from experiments/head_geometry/:

python analyze_rstock.py --device cpu --out ../../evidence/head_geometry/rstock_plain4b.json
python analyze_selfevidence.py --device cpu --threads 40 --sets plain --max-rows 6000 --chunk 64 --out ../../evidence/head_geometry --tag plain4b
python analyze_selfevidence.py --device cpu --threads 40 --sets verify draft --max-rows 4000 --chunk 64 --heads int8_row int8_g128 int8_g32 fp8_row int4_g128 int4_g32 --out ../../evidence/head_geometry --tag mtp4b
python analyze_selfevidence.py --device cpu --threads 40 --sets dflash_verify dflash_draft --max-rows 4000 --chunk 64 --heads int8_row int8_g128 int8_g32 fp8_row int4_g128 int4_g32 --out ../../evidence/head_geometry --tag dflash4b
python export_candidate_ccdf.py --tag {plain4b,mtp4b,dflash4b} --out ../../evidence/head_geometry/selfevidence_{tag}_ccdf.csv

State, from experiments/state_safety/: mechanism.py for all nine summaries that record the Hopper model (mechanism_plain_c1_vs_{mtp_s3_c1,c32}.json, tap_control_{down9,core13,core13_decode}.json, cachecheck_v4_*.json, history_v4_*.json). The v3 commands were not recorded anywhere; I reconstructed them from each summary's run paths and options and added them to evidence/state_safety/README.md ("Regenerating the classification"). The v4 commands are the analysis lines of run_tap_v4.sh.

Before and after

No count changed in any file. The same rows fail the gap and interval rules, and the same divergences fall in each class, so every quoted number is unchanged, not only at the quoted precision.

Quantity (Hopper model) gamma = 1.19e-4 gamma = 1.19216e-4, rounded up
Plain decode, gap rule: rows / decode steps 2.18% / 16.0% identical
Plain decode, interval rule: rows / decode steps 0.35% / 2.8% identical
Certified tokens differing from the engine's 0 0
MTP-4B gap rule: verify / draft rows 2.84% / 4.20% identical
DFlash-4B gap rule: verify / draft rows 5.675% / 9.23% identical
Plain vs MTP classes: rounding / order / ambiguous 89 / 16 / 24 identical
Plain c1 vs c32 classes 14 / 17 / 9 identical
Tap v4 plain vs MTP classes 21 / 4 / 5 identical

What did change in the regenerated files:

  • the recorded gamma (gammas, rstock_gammas), and every Hopper gap_bound_* in the state cases, which grew by exactly 1.19216.../1.19 = 1.0018;
  • elapsed_s;
  • from code that landed after these files were last generated, unrelated to gamma: selfevidence_plain4b.json gains reached_rows (6005), and the v3 state summaries now record data paths relative to ~/vp-data/state, carry first_logprob_difference per case, and list the five tap-changed prompts as mismatched_ids (the five already named in the README).

The CSVs, CCDF files, history_v4_*.json and the per-row arrays in ~/vp-data/geometry/analysis are byte-identical. pools.json regenerated from the new summaries is identical too, and first_difference_by_module.csv reads only fields that did not change.

Paper text that quotes Hopper-model results (Table 4's Hopper row, Section 4.4, the introduction's 0.35%, the discussion's 5.7% and 2.8%, Figure 2(b)'s \phop, Table 14's class counts) needed no change beyond the \ghop macro.

PR #45 check (not edited)

On #45 at 647427e, every kernel-facing constant rounds upward: KernelConstants and the envelope coefficients use float_up, f32_up and round_up_f32 (bounds.py around lines 212-226, 280-281, 343-347), and fallback_vs_model.py passes f32_up of each gamma. Its Hopper value bounds both factors with Higham's gamma_n, giving 1.1922159e-4, 5.2e-9 above the exact product used here, so the kernel's constant covers the replays'. Four float() round-to-nearest conversions remain (stock_invariance.py:127-128, reporting only; selftest.py:67 and tma_candidates.py:75,239, test tolerances from the conservative model). Each converts a Higham bound n u / (1 - n u), which exceeds (1 + u)^n - 1 by far more than one ulp, so they stay sound. The kernel agent has fixed the stale "1.19e-4" in fallback_vs_model.py's docstring on its branch.

The same argument covers the replays' existing conservative and FP32-tree values from bounds.accumulation_gamma, which also use float(): both are at or above the model's (1 + u)^d - 1.

Validation

  • pytest tests/test_state_safety_mechanism.py: 5 passed, including the new test.
  • pre-commit run on every changed file: passed (ruff, mypy, codespell, host-identity guard).
  • latexmk: 0 warnings, 81 pages, main text ends on p10, References on p11. scripts/check_paper_references.py: clean.
  • Not run: the GPU tests, which this change does not touch.

The R-stock and self-evidence replays and the divergence classification
hard-coded the Hopper wgmma model's gamma as 1.19e-4. The model's value,
(1 + 17 * 2^-25 + 2^-23)^160 (1 + 2^-23)^160 - 1, is 1.19216e-4, so the
replays used a bound 0.18% below the one they claim.

precision_reference.hopper_wgmma_gamma now computes it as an exact rational
and float_up rounds it up to binary64; analyze_rstock.py,
analyze_selfevidence.py (through bounds.hopper_gamma) and mechanism.py use
that value. The R-stock evidence key 'gamma_1.19e-4' keeps its name, which
still names the value to three digits. A test derives the constant
independently and checks it is the smallest binary64 value at or above it.
Reran from their recorded commands at 0769b2b: analyze_rstock.py, the three
analyze_selfevidence.py sets (plain4b, mtp4b, dflash4b) with their CCDF
exports, and mechanism.py for every state summary that records the Hopper
model. No share, batch share, candidate count or divergence class changed;
the CSV, CCDF and history_v4 files and the per-row arrays are byte-identical.
Only the recorded gamma, the Hopper gap bounds (up 0.18%) and elapsed times
moved. The rerun of the current mechanism.py also records data paths
relative to ~/vp-data/state, adds first_logprob_difference per case and
mismatched_ids to the v3 tap checks. The READMEs record the commit, the
regeneration commands, and the Hopper constant rounded up (1.1922e-4).
\ghop was 1.19e-4 against the derived 1.19216e-4, and the proof appendix
disclosed that the replays used that rounded-down value. The replays now
use the derived value rounded up (previous commits), so \ghop becomes
1.193e-4 and the Hopper bullet says how the replays compute it. \gcons
moves from 6.1e-4 to 6.11e-4 for the same reason: gamma_2D(2^-23) is
6.1072e-4. The wgmma-only intermediate is marked as approximate. No quoted
share or class count changes: the reruns left every count identical.
@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-01T15:23:45.605274Z bdf011b 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: APPROVE

Review of the exact head bdf011b: 0769b2b (code), e35258a (evidence), a main merge (122f494), and bdf011b (paper).

  • The γ values are right.
    • In exact rational arithmetic, (1 + 17·2⁻²⁵ + 2⁻²³)¹⁶⁰ (1 + 2⁻²³)¹⁶⁰ − 1 = 1.192164e-4. Its binary64 rounding is already at least the exact value, so float_up returns it unchanged, and the old 1.19e-4 was 0.18% low.
    • precision_reference.hopper_wgmma_gamma(n) computes exactly that with m = ⌈n/16⌉, and float_up rounds up to binary64. bounds.hopper_gamma and mechanism.py take the value from there instead of a hard-coded constant.
    • The paper's displays round up: \ghop 1.193e-4 ≥ 1.19216e-4, and \gcons 6.11e-4 ≥ the exact conservative (1 + 2⁻²³)^(2·2560) − 1 = 6.1054e-4.
  • No count changed. I compared every regenerated evidence JSON with main, leaf by leaf, ignoring only the added keys.
    • Only gamma_1.19e-4, elapsed_s, gap_bound_a/b and the run paths changed. The run paths now record tap/... and runs/... relative to the data root; they are the same runs.
    • The added keys are first_logprob_difference, tap_check.mismatched_ids and reached_rows, from code that postdates the original runs.
    • The class counts are identical under both models in both mechanism files. For example, plain vs MTP-3: conservative 93/38/7/29, Hopper 89/24/38/16.
    • The kept key name gamma_1.19e-4 is documented in the geometry README and in comments beside each use.
  • Provenance. 0769b2b is an ancestor of the head (merge, not rebase), and both READMEs name it as the regenerating commit. The reconstructed v3 mechanism.py commands in the state README reproduce every pre-existing count, which validates the reconstruction.
  • Tests. tests/test_state_safety_mechanism.py plus the head-geometry and precision tests pass, 26 passed and 1 skipped, on one core.
  • Rebuild in place. latexmk -g on one core finished with 0 warnings, wrote 81 pages, and its text is identical to the committed PDF. References start on p11, and check_paper_references.py is clean.
  • Codex completed on bdf011b with no comments.

@SamMausberg
SamMausberg merged commit 6135d9d into main Oct 1, 2026
SamMausberg added a commit that referenced this pull request Oct 1, 2026
Review of #135 at 9b96d40: with the plot 0.2 cm shorter, the rotated labels "plain step"
and "MTP cycle" ran into each other at the left edge. They now read "plain" and "MTP";
the bar labels and the caption carry the rest. Rebased on main after #139, PDF rebuilt.
SamMausberg added a commit that referenced this pull request Oct 1, 2026
Review of #135 at 9b96d40: with the plot 0.2 cm shorter, the rotated labels "plain step"
and "MTP cycle" ran into each other at the left edge. They now read "plain" and "MTP";
the bar labels and the caption carry the rest. Rebased on main after #139, PDF rebuilt.
SamMausberg added a commit that referenced this pull request Oct 1, 2026
Review of #135 at 9b96d40: with the plot 0.2 cm shorter, the rotated labels "plain step"
and "MTP cycle" ran into each other at the left edge. They now read "plain" and "MTP";
the bar labels and the caption carry the rest. Rebased on main after #139, PDF rebuilt.
SamMausberg added a commit that referenced this pull request Oct 1, 2026
Review of #135 at 9b96d40: with the plot 0.2 cm shorter, the rotated labels "plain step"
and "MTP cycle" ran into each other at the left edge. They now read "plain" and "MTP";
the bar labels and the caption carry the rest. Rebased on main after #139, PDF rebuilt.
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