fix(codegen): handle bias formulas in numeric format SSOT (closes #1064) - #1065
Merged
Conversation
The bias field in formats_catalog.t27 can carry either a literal int or a rule-derived formula like 2^N-1. Two formats use the formula form: gf512: bias = 2^194-1 gf1024: bias = 2^390-1 Both were added by PR #1051 as limit-of-ladder phi-aligned formats. The parser did int(bias_str) unconditionally, which raised ValueError, so both rows were silently dropped with a "malformed CATALOG line" warning. This is why count drifted: committed gen/ JSON shipped 77 (pre-#1051), post-#1051 SSOT carries 83 raw lines, codegen yielded 81 even after a fresh re-run, paper #3 (arXiv:2606.09686) claims 84. Four sources of truth, none matching. See issue #1064 for the full audit. Fix: - parse_bias(s) helper: tries int(); falls back to evaluating simple 2^N+offset forms within int64 range; otherwise returns sentinel -2 with the raw string in a new bias_formula field - Format dataclass: adds bias_formula: str (preserves the raw SSOT string for every row, including the literal-int cases for symmetry) - All existing emitters (Rust struct, C header, TS interface, Python, Markdown table, etc.) continue to render the int bias field as before; bias_formula appears only in JSON and python emitter where asdict() picks it up automatically -- non-breaking for the typed emitters that hardcode their Format schema. Verification after fix: $ python3 tools/gen_formats_catalog.py specs/numeric/formats_catalog.t27 gen/numeric/ $ python3 -c "import json; print(json.load(open('gen/numeric/formats_catalog.json'))['count'])" 83 gf512 and gf1024 now appear in the JSON with bias=-2 and the formula preserved in bias_formula. Downstream tools that need the actual i64 value can carry the string forward and evaluate at use-site (mpmath or big-int arithmetic) without losing provenance. This does NOT yet reconcile SSOT 83 vs paper #3 claim of 84; that delta is the MXFP6 split + standalone E8M0 in Table 1 vs the SSOT's collapsed mxfp6 row + Microscaling cluster layout. See #1064 for the follow-up plan. The CI invariant (raw line count == JSON count) will land in a separate PR. Refs: #1051 (GF ladder expansion), #1063 (HF Discovery thread), #1064
Contributor
|
📓 NotebookLM Notebook linked to this PR
This notebook contains session context, decisions, and artifacts for this work. |
Contributor
PR #1065 originally committed regenerated gen/numeric/* outputs alongside the source fix in tools/gen_formats_catalog.py. Per L2 generation rules, gen/ artefacts must be auto-regenerated post-merge by ./scripts/tri gen, not committed in source PRs. This commit: - reverts gen/numeric/* back to master state - keeps the source fix (tools/gen_formats_catalog.py) intact - adds docs/NOW.md entry per NOW Sync Gate Closes #1064
Contributor
|
📓 NotebookLM Notebook linked to this PR
This notebook contains session context, decisions, and artifacts for this work. |
Contributor
PR DashboardGenerated at: 2026-06-13 14:18:32 UTC
Summary
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1064.
Summary
The bias field in
specs/numeric/formats_catalog.t27can carry either a literal int or a rule-derived formula like2^N-1. Two formats use the formula form:gf512(bias2^194-1),gf1024(bias2^390-1). Both were added by PR #1051 as limit-of-ladder phi-aligned formats. The codegen parser didint(bias_str)unconditionally, raisedValueError, and silently dropped both rows with aWARN: malformed CATALOG linelog.This is what caused the count drift documented in #1064: shipped
gen/JSON was 77, post-#1051 SSOT carries 83 raw lines, a fresh codegen re-run yielded only 81, paper #3 (arXiv:2606.09686) Table 1 claims 84.Change
parse_bias(s) -> (int, str)helper. Triesint(s); falls back to evaluating simple2^N+offsetforms when they fit in i64; otherwise returns sentinel-2with the raw string preserved in a newbias_formulafield.Formatdataclass getsbias_formula: str-- always populated with the raw SSOT string (even for literal-int rows, for symmetry).biasint field as before; the newbias_formulaappears only in JSON and Python emitters viaasdict(). Non-breaking for the typed emitters that hardcode theirFormatschema.Verification
$ python3 tools/gen_formats_catalog.py specs/numeric/formats_catalog.t27 gen/numeric/ [...] $ python3 -c "import json; print(json.load(open('gen/numeric/formats_catalog.json'))['count'])" 83gf512andgf1024now appear in the regenerated JSON withbias=-2and the formula preserved:{"id": "gf512", "bits": 512, ..., "bias": -2, "bias_formula": "2^194-1", ...} {"id": "gf1024", "bits": 1024, ..., "bias": -2, "bias_formula": "2^390-1", ...}What this does NOT fix
This patch reconciles codegen with SSOT: both are now 83.
It does not reconcile SSOT vs paper #3 (84). That delta is the MXFP6 split (paper has MXFP6 E2M3 + MXFP6 E3M2 as separate rows; SSOT collapses into one
mxfp6) and the standalone E8M0 block-scale row. Reconciliation options tracked in #1064:playra/numeric-format-catalogv3 on HuggingFaceThe CI invariant (
grep -c '// CATALOG:' specs/numeric/formats_catalog.t27 == json.load('gen/numeric/formats_catalog.json')['count']) will land in a follow-up PR.Refs
Filed by Trinity S3AI (gHashTag), 2026-06-10 +07