Repository navigation
Round underflowing leaves in the precision reference instead of raising - #43
Conversation
Accumulator.sum rejected any leaf that is not exact in the accumulator format. Products of two BF16 values have at most 16 significant bits, so in FP32 that only happens below the normal range, for example 2^-133 * 2^-133. Rescoring two such rows (an exact tie between duplicate rows with subnormal operands) therefore made certify_argmax raise instead of refining. A leaf below the normal range is now rounded into the format as the modelled accumulator would (gradual underflow, or flush to zero when ftz is set). Its error is at most `underflow`, which error_bound already charges once per leaf through nodes(n) = 2n + splits, so the bound is unchanged. A leaf that is inexact in the normal range is still an input error. tests/test_precision.py adds test_subnormal_products: subnormal weights and hidden states, with and without flush to zero, checks that every rescoring interval encloses the exact logit and that exact ties between identical rows resolve to the smallest index (71 ties in 160 cases). The test fails on the previous code. evidence/precision/precision_tests.json is regenerated by `python tests/test_precision.py` (all 21 test methods pass).
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c7046f2480
ℹ️ 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".
| raise ValueError('accumulated leaves must be exact in the accumulator format') | ||
| if abs(t) >= self.fmt.min_normal: | ||
| raise ValueError('accumulated leaves must be exact in the accumulator format') | ||
| t = self._r(t) |
There was a problem hiding this comment.
Preserve subnormal products until the FMA rounds
When order='sequential' models the documented FMA/add chain with ftz=False, rounding each leaf here inserts an extra rounding before the fused addition. For example, the valid exact BF16 products [2^-149, 2^-150] should produce 2^-148: after the first term, adding the half-ulp second term rounds the tie to the even 2^-148; this implementation first rounds 2^-150 to zero and instead returns 2^-149. Thus rescoring and stock_logits no longer emulate the selected accumulator for these inputs; retain the exact product until the accumulator operation rounds it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, and fixed in e690786. The source change is committed first (a5334a1), and the bundle was regenerated at that commit with python tests/test_precision.py 2>&1 | tee evidence/precision/precision_tests.log. The JSON records repo_commit a5334a1. The log and README now match: 21 test methods, 40,015 checks. Relative to main, the only changed count is crossover_implications (1536 to 1559), because the new test consumes the shared seeded stream; the README does not cite it.
| "test_methods": 21, | ||
| "seed": 20260930, | ||
| "repo_commit": "8296b585caa5352ad061fff1feb9ecdae920127d", | ||
| "repo_commit": "25278b6cb149799596118f6b818c0dc81b693a24", |
There was a problem hiding this comment.
Tie the regenerated evidence to the tested source
The recorded revision 25278b6 is this commit's parent, which contains neither test_subnormal_products nor the new underflow behavior, so checking out the claimed repo_commit cannot reproduce this 21-test report. The companion precision_tests.log and README also remain at the prior 20-test/8296b585 run, leaving the checked-in evidence bundle with contradictory provenance; regenerate the complete bundle after the source change is committed and record that source revision.
AGENTS.md reference: AGENTS.md:L23-L27
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, and fixed in e690786. The source change is committed first (a5334a1), and the bundle was regenerated at that commit with python tests/test_precision.py 2>&1 | tee evidence/precision/precision_tests.log. The JSON records repo_commit a5334a1. The log and README now match: 21 test methods, 40,015 checks. Relative to main, the only changed count is crossover_implications (1536 to 1559), because the new test consumes the shared seeded stream; the README does not cite it.
Review of the previous commit: rounding each underflowing product before the accumulation adds a rounding the modelled FMA chain does not perform. For the leaves [2^-149, 2^-150] the FP32 sequential sum is a tie that rounds to even (2^-148); rounding the second leaf first gave 2^-149. Leaves below the normal range are now kept exact and only the modelled accumulator operations round them; a chunk that is a single leaf is rounded once at the end, an error already charged by error_bound's nodes(n) term. The regression test includes the review's example.
|
Verdict: REQUEST CHANGES Reviewed head c7046f2 (6 behind main). The change removes the BlockingB1. Pre-rounding subnormal leaves adds a rounding that the modelled kernels do not have (
B2. The regenerated evidence records a commit that does not contain the tested code (
Checked
|
|
Verdict: APPROVE This re-review covers head 751d78a. Both blocking items, which were Codex's two P2s, are fixed.
|
…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.
Handles the Codex review comment on PR #7 (
src/precision_reference.py:250):Accumulator.sumraisedValueErrorwhen a product of two valid subnormal BF16 operands was not representable in FP32 (for example2^-133 * 2^-133), so an exact tie between two such rows madecertify_argmaxfail instead of refining. The comment's advice was sound and is taken as given.Change
A product of two BF16 values has at most 16 significant bits, so it is inexact in FP32 only below the normal range. Such a leaf is now rounded into the accumulator format the way the modelled accumulator would round it: gradual underflow, or flush to zero when
ftzis set. Its error is at mostAccumulator.underflow, anderror_boundalready charges oneunderflowper leaf throughnodes(n) = 2n + splits, so the bound itself is unchanged. A leaf that is inexact in the normal range is still rejected as an input error.Validation
test_subnormal_products: subnormal weights and hidden states, FP32 ladder with and without flush to zero. Every rescoring interval must enclose the exact logit, and the certified token must equal the exact argmax. Exact ties between duplicate rows (71 of 160 cases) must resolve to the smallest index.ValueError.python tests/test_precision.pypasses all 21 test methods and regeneratesevidence/precision/precision_tests.json.pre-commitpasses on the changed files.GPU counterpart
The certified head's GPU bound code, on branch
kernel/certified-head, was checked for the same case:2^-100term, which covers flush to zero of our int8 pass and of the stock kernel.2^-100, which covers flush to zero of up to2Kproducts at2^-126each. That change ships with the kernel PR.