Skip to content

Exact witnesses that separate the exactness contracts (P7) - #26

Merged
SamMausberg merged 2 commits into
mainfrom
paper/contract-witnesses
Sep 30, 2026
Merged

SamMausberg merged 2 commits into
mainfrom
paper/contract-witnesses

Conversation

@SamMausberg

Copy link
Copy Markdown
Owner

P7 (TASKS.md) asks the paper to separate five contracts:

  • identical internal state
  • identical greedy outputs
  • identical seeded samples
  • the exact sampling distribution
  • empirical quality equivalence

Its counterexamples were run outside this repository. This PR reproduces them as tests before the paper cites them, in the same way PR #20 did for P4 and P5.

What changed

tests/test_contracts.py has six test methods. Exact cases use Fraction. Floating-point cases use NumPy float32 scalar and elementwise arithmetic: IEEE binary32, round to nearest, ties to even, no FMA contraction. Every reduction is an explicit sequential loop, so the evaluation order is the one stated.

  • Reassociation flips a greedy winner. Row 1 is 1 + 2^-24 + 2^-24. Summed sequentially in FP32 it returns 1, which ties row 0, and the first-index argmax picks token 0. Regrouped, it returns 1 + 2^-23 and picks token 1, as real arithmetic does.
  • Distinct FP32 values share a BF16 cell. 1 and 1 + 2^-10 both round to 1 in BF16.
  • Same argmax, different law. Logits (1, 0) and (2, 0) give base-2 laws (2/3, 1/3) and (4/5, 1/5).
  • Same law, different seeded tokens. Two inverse-CDF samplers that list the tokens in different orders map the uniform 1/4 to different tokens.
  • Regrouped GDN recurrence. The recurrence is run sequentially and in the split form S_t = S_0 P_t + W_t, which is equal in exact arithmetic. Over 50 steps at width 32 (seed 7), 1,481 of 1,600 FP32 outputs differ, and 2 still differ after BF16 rounding. The sandbox figures in P7 (1,173 of 1,600, and 1) came from a different setup; this test reproduces the phenomenon, not those numbers.
  • Transition norm. (I - beta k k^T) has spectral norm at most 1 exactly when 0 <= beta ||k||^2 <= 2, which gives the state-error recursion ||E_t|| <= |alpha_t| ||E_{t-1}|| + ||eta_t||. At beta ||k||^2 = 5/2 the norm is 3/2.

The query-invisible witness (equal readout now, different later) already exists in tests/test_state_structure.py (PR #20).

evidence/contracts/ holds the JSON report and the log, both generated at 29c85d7, which the JSON records. The README gives the command and what each witness shows.

Scope

These witnesses show that the contracts are distinct in general. They are not engine measurements. How often each difference occurs in SGLang is the state workstream's divergence analysis.

Validation

  • python tests/test_contracts.py: 6 of 6 pass.
  • python -m pytest tests/test_contracts.py: 6 passed.
  • pre-commit run --files passes on the changed files: ruff, mypy and codespell. evidence/ is excluded from the hooks.
  • No new dependencies.

Six tests, in exact arithmetic or explicit-order float32, show that the
contracts P7 distinguishes are different: FP32 reassociation flips a
greedy winner; distinct FP32 values share a BF16 rounding cell; logits
(1, 0) and (2, 0) share an argmax but not a law; two inverse-CDF
samplers share a law but not seeded tokens; a regrouped gated-delta
recurrence changes most FP32 outputs but few after BF16 rounding; and the
transition norm is at most 1 exactly when 0 <= beta ||k||^2 <= 2, which
gives the state-error recursion.
@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:23:50.438149Z 69d2d1b 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

Reviewed at 69d2d1b, whole diff. The evidence was produced at 29c85d7, and the test code is unchanged since then.

What I checked

  • Tests. pytest tests/test_contracts.py: 6 passed. Rerunning the suite reproduces the committed witnesses exactly, including the GDN counts (1,481 of 1,600 FP32 outputs, 2 after BF16; 50 steps, width 32, seed 7). Hooks pass on the changed files, including mypy, and the branch merges into main without conflicts.
  • Format and rounding. Every floating-point witness states it. The module docstring and the README say IEEE binary32, round to nearest, ties to even, NumPy scalar and elementwise arithmetic, no FMA contraction, and explicit sequential reductions. The BF16 helper states ties-to-even.
  • Each witness by hand:
    • (1 + 2^-24) + 2^-24 ties to even at 1 twice, while 1 + (2^-24 + 2^-24) = 1 + 2^-23 is exact. The first-index argmax gives 0 and 1, and real arithmetic gives 1.
    • 2^-10 is below half the BF16 spacing at 1 (2^-8), so it rounds to 1.
    • The base-2 laws (2/3, 1/3) and (4/5, 1/5) are right.
    • The two inverse-CDF orders have the same law and map u = 1/4 to different tokens.
    • The split form S_t = S_0 P_t + W_t equals the sequential recurrence exactly, because the recurrence is linear with input-determined A_t and B_t. Both paths use the same rounded A_t and B_t, so the differences come only from regrouping.
    • I - β k k^T is symmetric with eigenvalues 1 - β‖k‖² (on k) and 1 (on k^⊥). Its spectral norm is at most 1 exactly when 0 ≤ β‖k‖² ≤ 2, for any key length.
  • GDN counts. They are described as this test's setup (steps, width, seed). The PR body says the sandbox figures (1,173 and 1) came from a different setup and that the test reproduces the phenomenon, not those numbers.
  • Scope. The scope statement says these are not engine measurements. No private paths appear, and P7 is cited from TASKS.md.

Suggestions (non-blocking)

  1. test_same_argmax_different_law hard-codes the two laws. Compute them from the logits (2^z / Σ 2^z), so the test checks the arithmetic it describes.
  2. test_same_law_different_seeded_tokens states the equal-law claim only in a comment. An exact check is short: the measure of u mapped to each token is 1/2 for both orders.
  3. The norm test uses only a unit key, although the claim covers any k. Add one non-unit case, for example k = (3, 4) with β = 2/25, β ‖k‖² = 2.
  4. Name the norm in ‖E_t‖ ≤ |α_t| ‖E_{t-1}‖ + ‖η_t‖: Frobenius or spectral, both valid via ‖E A‖ ≤ ‖E‖ ‖A‖_2.

@SamMausberg
SamMausberg merged commit 4fe7111 into main Sep 30, 2026
@SamMausberg
SamMausberg deleted the paper/contract-witnesses branch September 30, 2026 20:22

@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: 69d2d1bff7

ℹ️ 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 tests/test_contracts.py
seq_out, split_out = [], []
for _ in range(steps):
k = rng.standard_normal(d).astype(F32)
k = (k / F32(np.sqrt(np.sum(k.astype(np.float64) ** 2)))).astype(F32)

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 Make the GDN normalization reduction sequential

When this witness is rerun on another NumPy build or CPU architecture, np.sum may use a pairwise or otherwise implementation-dependent reduction, so the rounded normalized key—and consequently the reported recurrence-difference counts—is not governed by the fixed order promised in the module and evidence README. Accumulate the squared norm with an explicit loop before taking the square root, as is already done for the matrix reductions.

Useful? React with 👍 / 👎.

Comment thread tests/test_contracts.py
Comment on lines +3 to +5
Each test checks one small counterexample showing that two of the paper's contracts differ:
identical internal state, identical greedy outputs, identical seeded samples, and the exact
sampling distribution. Exact cases use Fractions; floating-point cases use NumPy scalar and

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 Cover empirical-quality equivalence in the witness suite

When this suite is used as the P7 counterexample evidence advertised by its header and README, it covers only four of the five stated contracts: this enumeration stops at sampling-distribution equality, and none of the six tests separates empirical-quality equivalence from a stronger contract. The resulting artifacts therefore cannot support the advertised five-contract separation; add a fixed metric/dataset witness or explicitly narrow the suite's claimed scope.

Useful? React with 👍 / 👎.

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