Skip to content

research: fold constants by the rule for any width and head size (#214, CPU part) - #234

Draft
wakesync wants to merge 13 commits into
mainfrom
research/1129-fold-constants-214
Draft

wakesync wants to merge 13 commits into
mainfrom
research/1129-fold-constants-214

Conversation

@wakesync

@wakesync wakesync commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Part of #214

The CUDA side is NOT changed by this PR: prover/weights_commitment/fold_weights.cuh (reads()) and prover/weights_commitment/fold_source.cuh (the shape gate) keep their literals and their (5,120, 128) gate. This host has no GPU and could not compile them. The change they need is written in experiments/20261129-214-fold-constants/RESULTS.md, "Open item: the CUDA side", as NOT made and NOT compiled.

What changed

  • weight_sums/weight_sums.py: fold_constants(width, head) and rn32_sqrt_word() compute the two constants (t the largest integer with 4^t <= d, c = sqrt(d) / 2^t, c_0 = RN32(c), c_q = RN32(c / sqrt(dh)), each one rounding of the exact real, integer arithmetic only). NORM_CONSTANT and QUERY_CONSTANT now come from fold_constants(5120, 128).
  • weight_sums/weight_sums.cpp: the C++ twin as constexpr (unsigned __int128), with a static_assert that it gives 0x3F8F1BBD and 0x3DCA62C2 at (5,120, 128).
  • Tests: weight_sums/tests/fold_constants_test.py (new step fold-constants.py in run_tests.sh) checks the literals, the (5,120, 256) words and 23 shapes against an independent exact bisection. unit_test.cpp adds test_fold_constants.
  • The shape gates of both programs are unchanged (still only 5,120 / 128). No admission gate is opened.

What the documents state, and what this PR chose

  • docs/model.md, section 11.3, states the two constants as RN32(sqrt(d)/64) and, for the query matrix, RN32(sqrt(d)/64/sqrt(dh)), and says they are right for d = 5,120 and dh = 128 only. scales/README.md states the conversion's constant as sqrt(d) / 64 too. Neither states sqrt(d) / 2^t as the conversion's constant.
  • sqrt(d) / 64 equals c where t = 6, that is for widths from 4,096 to 16,383, Qwen's 5,120 included. There fold_constants returns what the documents state.
  • For every other width (t != 6) the function uses c = sqrt(d) / 2^t. That is a choice made in this PR (argued in PREREG, "The rule, quoted from main"). No document on main states it, and it is not tested against the scales of scales/. Example: at d = 2,048 and dh = 64 the function gives 0x3FB504F3 for the norm constant, while sqrt(d) / 64 rounds to 0x3F3504F3. Which is right for such a width is open. No gate admits such a width.
  • The tests check the arithmetic of the formula (Python, C++ and a second exact computation of the same formula agree). They do not test the choice of c.

Verdicts (PREREG thresholds), all measured, unreplicated

  • P1 PASS: Python and C++ give (0x3F8F1BBD, 0x3DCA62C2) at (5,120, 128), main's literals.
  • P2 PASS: mpmath at 256 bits and exact integer roots (values.json) agree. At (5,120, 256): c_0 0x3F8F1BBD, c_q 0x3D8F1BBD.
  • P3 PASS: 19 of 19 sums files over the suite's inputs are byte-identical between base and head and equal the expected files (runs/compare.json). run_tests.sh: base 26/26, head 27/27, 0 skipped.
  • P4 PASS: fold_constants_test.py 0 failed checks; unit_test 0 of 20,066,032 failed.

The runs are those of commit b1939005. Nothing was run again or built after the review; see the next section.

Changed after the round-1 review (text only)

The review (PR comment 7249850873, REQUEST CHANGES at 111b104d) found that the code comments and the write-up presented c = sqrt(d) / 2^t as a rule stated by scales/README.md and docs/model.md section 11.3. Commits on top of 111b104d, no rebase and no force-push:

  • b831cfac: PREREG amendment A2, alone, before any other change.
  • 774225a1: the fold_constants docstring in weight_sums.py, the matching comment in weight_sums.cpp, one passage of weight_sums/README.md, and two passages of RESULTS.md plus a new RESULTS section "Changed after review". In weight_sums.py only lines inside that docstring change; in weight_sums.cpp only whole-line // comments change.
  • cd2e361c: RESULTS open item 3, the gguf_source.cuh gate is at line 29, not 28.
  • 64a0b87f: the summary of the fold-constants-214 row in research/results.yaml, with the regenerated README block and CLAIMS.md. This commit holds the hand-edited row and the regenerated files together, and its message names only the regeneration; they were meant to be two commits. The tree is as intended.

No code line, test, run file, verdict, count or threshold changed. bin/weight_sums was NOT rebuilt after the comment change in weight_sums.cpp: a comment is replaced by a space before compilation and the file uses no __LINE__, assert() or #line, so the program should not change, but that is an argument and not a measurement. A reviewer who wants it measured can rebuild at 111b104d and at this head and compare the two programs.

NOT established

No Qwen commit and no weights. No admission gate opened. No GPU build or CUDA change. Partial rotary and the dh = 256 no-wrap barrier untouched. Whether c = sqrt(d) / 2^t or the documented sqrt(d) / 64 is the right conversion constant for widths outside 4,096 to 16,383. Values at shapes other than the two registered ones are checked only between computations written in this PR. The public fork the issue mentions was not read.

Proposed claim

fold-constants-214 (the results.yaml row): the words above and the 19/19 byte identity. Not a headline.

Merge notes

  • Adds a research/results.yaml row: must merge with a merge commit (metric commit b1939005).
  • Main is merged into the branch, twice, each time by the union rule (results.yaml is main's file plus this PR's own row appended; README block and CLAIMS.md regenerated; README stamp line is main's): main 1599e1b9 in merge commit 28308f55 with regeneration commit 111b104d, and main fef9d2b8 in merge commit ff08ab3c with regeneration commit 419b12c3. Head 419b12c3 contains main fef9d2b8. If main moves again, the three generated files will conflict again in the same way.

Draft, not for merging by the lane.

Conflicts: research/results.yaml, README.md, CLAIMS.md. results.yaml is main's file plus this PR's own entry (fold-constants-214), unchanged and appended at the end. README/CLAIMS take main's side here and are regenerated in the following commit after the merge makes the metric commits available in branch history; README stamp is main's verbatim.
…9e1b

scripts/update-results.py after the merge commit (76 results); stamp line kept as main's verbatim. Adds this PR's row for fold-constants-214 to the README block and CLAIMS.md on top of main's; no other change.
@wakesync

Copy link
Copy Markdown
Owner Author

Main sync: merged main 1599e1b94abcd3295dd3410ec6bd8dc8c9995986 (adds #224 and its results sync) into this branch with a merge commit. Old head 472b409ad0f20fc3d995cf0d2d47efa681c918e4, new head 111b104dfabc24b204bdd121edb9d8f6d7c05cd4 (fast-forward, merge commit 28308f55 plus a separate README/CLAIMS regeneration commit 111b104d).

Conflicted files: research/results.yaml, README.md, CLAIMS.md, nothing else. research/results.yaml is main's file byte for byte plus this PR's own entry fold-constants-214, appended unchanged: removing that entry gives main's file (sha256 1470a4de...1c42b both), the entry is byte-identical to the old head, and the 76 ids are unique. README and CLAIMS are regenerated (stamp line is main's); each differs from main only by this PR's one row.

All 9 files under experiments/20261129-214-fold-constants/ and the 6 changed weight_sums/ files are byte-identical to the old head, and the other 3806 experiments/ paths are byte-identical to main. update-results.py --check, check-claims.py, check_inventory.py and the host-path guard all pass on the merged tree. The PR is still a draft.

@wakesync

Copy link
Copy Markdown
Owner Author

REQUEST CHANGES at 111b104

class A, Opus review, same model family as the author, second family not available. The build lane and the sync lane both ran on claude-opus-5-5, the same model as this review. This verdict does not allow a merge by itself.

Summary: the code is correct and inert. At (5,120, 128) nothing the prover consumes changes: the bin/weight_sums binaries built at base and at head are byte-identical, and so are all 19 sums files. Python and C++ agree everywhere I checked. No gate is opened. The changes I ask for are text only. The code comments say the general formula c = sqrt(d) / 2^t comes from docs/model.md section 11.3, but that section states sqrt(d) / 64 and says it is right for (5,120, 128) only. The PR body also still says the branch conflicts with main.

What I checked myself (fresh clone, base = merge base cdf7844, head = 111b104, CPU only)

  • History: PREREG.md alone in the first commit (3ee789b). A1 (3841393, 02:09Z) comes before the code commit 92e1dc1 and the run commit b193900. A1 changes only PREREG.md, under "Amendments", and moves no threshold. The PR timeline has no force-push. Run files are unchanged from b193900 to head.
  • Rule and rounding (worry a): neither language uses floating point. Both compute RN32(sqrt(n / d)) with integers only: scale into [2^23, 2^24), take an integer square root, then decide by comparing 4N with (2m+1)^2 D. That is a single rounding of the exact real, ties to even. Python uses math.isqrt. C++ uses unsigned __int128 with constexpr, so compiler flags cannot change the result. Every product stays below 2^128 for the admitted inputs. The tie branch cannot be reached for the operands these callers produce, because an exact tie needs a rational square that is not representable here.
  • The two binaries: bin/weight_sums built at base and at head with the repository's flags (by the build step of run_tests.sh) are byte-identical (cmp). The static_assert replaces two literals with the same compile-time values, so the program's bytes do not change.
  • run_tests.sh at base and at head, system python3: every step that ran passed (base 13 passed, 13 skipped; head 13 passed, 14 skipped). The skipped steps are the Python ones. Python was covered separately; see the next three items.
  • Byte comparison with my own script (filecmp, not the PR's script). Inputs came from the BASE oracle.py and a make_model built from base. Result: 19 of 19 sums files are equal across base, head and the expected file, for C++ and Python, under a venv with numpy 2.3.5 and gguf 0.19.0.
  • The PR's compare_base_head.py, run by me: 19 of 19. My JSON output equals the committed runs/compare.json in every one of the 19 rows, SHA-256 values included.
  • Shapes behind the 19 files (worry b): all are width 5,120. The head size is 128, or absent and so 128 by default (oracle seeds 1, 3 and 101). Main's gates admit only (5,120, 128), in weight_sums.py, weight_sums.cpp, block_weights.py, gguf_source.cuh and fold_source.cuh. So no other shape exists that main admits and these files fail to cover.
  • Independent recomputation (worry e and check 4): my own script, which does not import the PR's code, uses mpmath at 300 bits plus Python's decimal module at 120 digits. I computed 15 pairs: (5,120, 128), (5,120, 256), (2,048, 64), (4,096, 128), (2^32-1, 1), (1, 2^32-1), (2^32-1, 2^32-1), (3, 7), (4,095, 5), (6,144, 96), and the five pairs in [1, 16,384] x [1, 512] whose root lies closest to a rounding midpoint: (13,211, 102) at 1.35e-7 of a binary32 step, (14,249, 362), (12,355, 291), (1,919, 435), and the norm constant at d = 6,577 (1.8e-6). All 15 equal the PR's C++ output and values.json. At (5,120, 256), c_q = 0x3D8F1BBD.
  • Cross-language agreement (check 5): the PR's C++ (compiled with the repository's flags) against the PR's Python on every (width, head) in [1, 16,384] x [1, 512]: 0 of 8,388,608 pairs differ. My independent computation against the C++ on [1, 8,192] x [1, 64]: 0 of 524,288 differ.
  • Tests: fold_constants_test.py gives 0 failed checks and independent_values.py --check matches. unit_test gives 0 of 20,066,032 at head and 0 of 20,066,025 at base.
  • Sync commits (check 8): git diff 472b409a 111b104d, excluding the three generated files, is identical to git diff cdf78449 1599e1b9 with the same exclusion (cmp on the two patches). The six weight_sums/ paths and the experiment directory are byte-identical between 472b409 and head. Head research/results.yaml is main's file plus one appended row. README.md and CLAIMS.md each differ from main by one added line. Metric commit b193900 is an ancestor of head (worry g).
  • Hygiene: update-results.py --check ok (76 results, 1,214 metrics), check-claims.py ok, check_inventory.py ok, check-no-host-paths.sh ok. The scrub gives total_matches=0 on the 19 changed text files, the commit messages, the PR body and the issue comment. The row has pr: 234.

Must-fix

  1. weight_sums/weight_sums.py lines 183 to 187 and weight_sums/weight_sums.cpp lines 724 to 727 attribute the general rule to docs that do not state it. They say "The rule is stated in scales/README.md (...step 2) and docs/model.md, section 11.3: ... c = sqrt(width) / 2^t". On main, docs/model.md section 11.3 gives the constants as RN32(sqrt(d)/64) and RN32(sqrt(d)/64/sqrt(dh)), "right for d = 5,120 and dh = 128 only". In scales/README.md, line 542 says the conversion folds sqrt(d) / 64. Lines 594 to 600 define c for the fit's norm-site exponent, not as the conversion constant. For t != 6 (widths outside 4,096 to 16,383) the PR's function returns RN32(sqrt(d)/2^t), not the RN32(sqrt(d)/64) that the reference text states. Example: at d = 2,048, dh = 64 the PR gives 0x3FB504F3 (sqrt 2), while sqrt(d)/64 rounds to 0x3F3504F3. The PREREG argues for c, and the argument may well be right, but no doc on main makes that choice. To settle: reword both docstrings, the weight_sums/README.md sentence (lines 229 to 232), the row summary and RESULTS "The answer to the issue's first question". They should say that sqrt(d)/64 is what the docs state; that it equals c at t = 6, so at every width the gates could admit next, Qwen's 5,120 included; and that for t != 6 the function uses c = sqrt(d)/2^t, a choice made in this PR that docs/model.md section 11.3 does not yet state and that is untested against the scales of scales/. Alternatively, update docs/model.md section 11.3 in this PR and say so. Text only; no byte the prover consumes changes either way.
  2. The PR body is stale. "Merge notes" still says "The branch currently CONFLICTS with main ... fp_merge_main.py aborted ... the lane did not resolve it by hand". The sync lane resolved it at 28308f5/111b104d, and GitHub reports MERGEABLE/CLEAN. To settle: replace that bullet with a line naming the sync merge commit and the regeneration commit.

Nonblocking

  • Worry d: nothing in the repository compares the CPU rule with the CUDA literals. Those literals are in fold_weights.cuh lines 181 to 186, make_model.cpp line 504, block_weights.py lines 306 to 307 and oracle.py lines 395 to 396. The C++ static_assert pins only the CPU side to the old literals. The vLLM test at test_block_decoding.py lines 585 to 590 checks against numpy.float32(math.sqrt(...)). A small test that reads those four files and asserts each literal equals fold_constants(5120, 128) would make "equal at the existing shape" tested rather than asserted. The only guard against opening the CPU gate alone is comment text (PREREG "Scope cut"; RESULTS open item 5). I suggest a comment at weight_sums.py line 345 and weight_sums.cpp line 1338 saying the CUDA reader, block_weights.py and oracle.py must open together.
  • Worry c: the new function is reachable only at module or compile-time initialisation, with (5,120, 128), and from tests. No metadata key, flag or environment variable reaches it with another shape (--any-gguf-version is unrelated). The change is inert today. The trap for the next person is the one above: the CPU side would follow the rule while CUDA, vLLM and the oracle keep the old literals.
  • C++ fold_constants(0, h) and fold_constants(w, 0) loop forever in rn32_sqrt_word (zero numerator, or zero denominator). Python raises ValueError instead. This is unreachable today; a width >= 1 && head >= 1 precondition would make the twins match.
  • RESULTS "Open item", item 3: the gate in gguf_source.cuh is at line 29, not 28. Item 4 should also list the gate at block_weights.py line 600, plus weight_sums/tests/oracle.py lines 394 to 396 and 459, refusals.py and test_block_decoding.py lines 585 to 590. The section nowhere claims that anything was compiled or tested.
  • Worry e: of the two methods in independent_values.py, the "exact" one is the same algorithm as rn32_sqrt_word (integer square root plus squaring), retyped. Only the mpmath one is a second method. My mpmath and decimal computations agree with both.
  • Worry f: of the 20,066,032 unit_test checks, 7 are new (base has 20,066,025). The rest are the earlier SHA, widening and rounding checks. The static_assert covers (5,120, 128) only. Wording such as "0 of 20,066,032" reads as though all of those checks test this change.

Main sync needed: no (main is 1599e1b, already merged).
CI (check-runs API at 111b104): claims completed/success 02:31:32Z, guard completed/success 02:31:38Z.

Skipped checks

  • I ran run_tests.sh without the venv on PATH, because the exec gate refused a custom PATH. I did not rerun it in another form. Its Python steps were covered by running fold_constants_test.py, the PR's comparison script and my own comparison under the venv directly. I did not run oracle.py's other Python steps (edge, refusals, fork-failure) under the venv at either arm.
  • No CUDA build (not possible here, as the brief says). No trial merge was needed, because main has not moved.

Second reviewer, look first at: whether c = sqrt(d)/2^t, rather than the documented sqrt(d)/64, is the right conversion constant for widths outside 4,096 to 16,383 (must-fix 1). Everything else at the existing shape is byte-identical.

…ys more than the cited documents; text-only step)

A review found that the fold_constants docstring and related text present
the general rule c = sqrt(d) / 2^t as stated by scales/README.md and
docs/model.md section 11.3. Those documents state sqrt(d) / 64, right for
d = 5,120 and dh = 128 only. The amendment records that, and that the step
that follows corrects comments and text only: no code line, test, run file,
threshold, count or verdict changes. Appended under "Amendments"; no earlier
PREREG text is edited.
…ule as this PR's (review must-fix 1, text only)

docs/model.md section 11.3 states the two constants as RN32(sqrt(d)/64) and
RN32(sqrt(d)/64/sqrt(dh)), right for d = 5,120 and dh = 128 only, and
scales/README.md states the conversion's constant as sqrt(d) / 64. The
fold_constants docstring (weight_sums.py), the matching comment
(weight_sums.cpp), one passage of weight_sums/README.md and two passages of
RESULTS.md said that those documents state c = sqrt(d) / 2^t. They now say:
sqrt(d) / 64 is what the documents state; it equals c where t = 6 (widths
4,096 to 16,383, 5,120 included); for other widths c is a choice made in
this PR that no document on main states and that is not tested against the
scales of scales/; the tests check the arithmetic of the formula only.

weight_sums.py: only lines inside the fold_constants docstring change.
weight_sums.cpp: only whole-line // comments change. No code line, test or
run file changes. Nothing was built for this commit.
…ine 29, not 28 (review, nonblocking)

Checked against prover/weights_blocks/gguf_source.cuh at this head: the test
of embedding_length and key_length is on line 29. One number changes.
…ts-214 summary change

Output of scripts/update-results.py, with the README stamp line set to
main's. One row changes in each file, and the stamp line in README.md.
Conflicts: research/results.yaml, README.md, CLAIMS.md. results.yaml is main's file plus this PR's own entry (fold-constants-214), byte-identical to the entry at the branch head before the merge and appended at the end. README/CLAIMS take main's side here and are regenerated in the following commit, after the merge makes the metric commits available in branch history; the README stamp line is main's, verbatim.
…9d2b

Output of scripts/update-results.py on the merged tree, with the README stamp line set to main's. Each file differs from main by this PR's own row only.
@wakesync

Copy link
Copy Markdown
Owner Author

Fix for the round-1 review (comment 7249850873, REQUEST CHANGES at 111b104d). Text only, then main brought in.

New head: 419b12c327067547a90c97b4b99da18d5465fc47. Main merged: fef9d2b800b49a2d3eefb45dda82c58474cc25d4. Six commits on top of 111b104d, no rebase, no amend, no force-push. Still draft.

Review items

Must-fix 1 (the citation). Reworded; whether it is settled is the reviewer's call.
I read docs/model.md section 11.3 myself at the head (lines 411 to 437). The table gives RN32(sqrt(d)/64) and, for attn_q, RN32(sqrt(d)/64/sqrt(dh)); lines 435 to 436 say the constants are "right for d = 5,120 and dh = 128 only". The section has no t and no sqrt(d)/2^t. The review's reading is right. I also recomputed the review's example with my own exact script: at d = 2,048 the PR's rule gives 0x3FB504F3 and sqrt(d)/64 gives 0x3F3504F3.

  • b831cfac: PREREG amendment A2, alone and pushed before any other change (PREREG.md lines 74 to 81). It also names the same overstatement in the PREREG's own "Prior art" sentence, which is left as registered.
  • 774225a1: weight_sums/weight_sums.py lines 181 to 203 (the fold_constants docstring), weight_sums/weight_sums.cpp lines 724 to 741 (the comment above struct FoldConstants), weight_sums/README.md lines 229 to 237, RESULTS.md line 7 ("In plain words"), lines 22 to 26 ("The answer to the issue's first question") and lines 68 to 70 (new section "Changed after review").
  • 64a0b87f: the row summary, research/results.yaml line 2099 at this head, and the regenerated row in README.md (line 88) and CLAIMS.md (line 90).

Each place now says: sqrt(d)/64 is what the documents state; it equals c where t = 6, widths 4,096 to 16,383, 5,120 included; for other widths c = sqrt(d)/2^t is a choice made in this PR that no document on main states and that is not tested against the scales of scales/; the tests check the arithmetic of the formula, not the choice. I took the review's first option. docs/model.md is not edited.

No code line changed. weight_sums.cpp: 23 changed lines, all whole-line // comments; the file with whole-line comments and blank lines removed has the same sha256 before and after (c4686460...2e70a). weight_sums.py: 28 changed lines, all inside the fold_constants docstring; the syntax tree without docstrings and the token stream without comments and that docstring are equal before and after.

NOT done: no build and no run. I did not rebuild bin/weight_sums or rerun any test after the comment change. A comment becomes a space before compilation and the file has no __LINE__, assert() or #line, so the program should be unchanged, but I did not measure that. The byte comparison of the two programs that the review made at 111b104d does not cover this head.

Must-fix 2 (PR body). Done. The stale "currently CONFLICTS with main" bullet is replaced by a line naming both syncs: main 1599e1b9 in 28308f55 + 111b104d, and main fef9d2b8 in ff08ab3c + 419b12c3. The body's "What changed" no longer says the constants come "from the rule in scales/README.md", and it has two new sections ("What the documents state, and what this PR chose", "Changed after the round-1 review"). The old body is kept outside the repository.

Nonblocking, RESULTS open item 3 line reference. Done in cd2e361c: gguf_source.cuh line 28 changed to 29 (RESULTS.md line 50), checked against the file at the head.

Left open (not done here, by the lane's scope)

  • A test that ties the CUDA-side literals (fold_weights.cuh, make_model.cpp, block_weights.py, oracle.py) to fold_constants(5120, 128), and the suggested comments that the gates must open together. The two places the review names for those comments have moved: weight_sums.py line 345 is now line 359, weight_sums.cpp line 1338 is now line 1351.
  • C++ fold_constants(0, h) and fold_constants(w, 0) loop forever; Python raises. Unreachable today. Not changed (a code line).
  • RESULTS open item 4: the further gates and literals the review lists are not added.
  • independent_values.py: its "exact" method is the same algorithm as rn32_sqrt_word; only the mpmath method is a second method. Wording not changed.
  • "0 of 20,066,032" in RESULTS and the PR body: only 7 of those checks are new. Wording not changed.

Found while doing this, not changed

  • weight_sums/tests/fold_constants_test.py lines 7 to 8 call the function's rule "the conversion rule (scales/README.md, ...)". Same overstatement as must-fix 1, in a test file, which this lane may not edit.
  • RESULTS.md open item 3 also says gguf_source.cuh "lines 30 to 32" compare with shape.d, shape.dh; at the head that comparison is on lines 31 to 32.
  • research/weight-binding/DESIGN.md line 154 cites weight_sums.py:412-414. This PR's code already moved that target by 54 lines, and the longer docstring moves it 14 more. That file is not part of this PR.

One thing done wrong

64a0b87f holds the hand-edited results.yaml row and the regenerated README block and CLAIMS.md in ONE commit, and its message names only the regeneration. They were meant to be two commits. I ran the add and the commit of the row in one step, the commit ran first and failed, and the row went into the next commit. The tree is as intended. I did not repair it, because that needs an amend or a force-push.

Main sync

fp_merge_main.py stopped with conflicts in research/results.yaml, README.md, CLAIMS.md only, so the union rule was followed. Merge commit ff08ab3c (parents 64a0b87f and fef9d2b8), regeneration commit 419b12c3.

  • results.yaml minus this PR's row equals main's file byte for byte (sha256 05338b46...1fa0 both).
  • This PR's row is byte-identical to the row at 64a0b87f. 77 ids, 77 unique, own row last.
  • This PR's experiment directory: 9 files, byte-identical to 64a0b87f. Every other experiments/ path: 3,824, byte-identical to main.
  • The 6 weight_sums/ paths are byte-identical to 64a0b87f. 18 files differ from main, all of them this PR's.
  • At 419b12c3: update-results.py --check ok (77 results, 1,220 metrics), check-claims.py ok, check_inventory.py ok, check-no-host-paths.sh ok (working tree).

@wakesync

Copy link
Copy Markdown
Owner Author

REQUEST CHANGES at 419b12c

class A, Opus review, round 2, delta review, same vendor family as the authors; this verdict does not by itself allow a merge

Summary: the delta is text only, and I measured that. bin/weight_sums built at 111b104d and at this head is byte-identical. The five places round 1 named now say what docs/model.md 11.3 and scales/README.md state, and every new factual sentence I checked is true. One place with the same overstatement is left: the docstring of the test file this PR adds, weight_sums/tests/fold_constants_test.py lines 7 to 8. It still calls the function's rule "the conversion rule (scales/README.md ... step 2)". It is two lines of text and needs no code change. Everything else is settled or nonblocking.

What I checked myself (the fix lane's clone, read only; exports by git archive to a private tmp directory; CPU cores 2 to 3)

  • Clone clean, HEAD = remote branch = 419b12c3; main fef9d2b8.
  • Delta (check 1). 111b104d..64a0b87f touches 8 paths: CLAIMS.md, README.md, the PR's PREREG.md and RESULTS.md, research/results.yaml, weight_sums/README.md, weight_sums.cpp, weight_sums.py. No runs/ path, no test file. From 64a0b87f to the head, nothing under weight_sums/ or the PR's experiment directory changes. Every other experiments/ path at the head is identical to main (git diff --stat fef9d2b8 419b12c3 -- experiments minus the PR's directory is empty). Against main, research/results.yaml differs only by the appended fold-constants-214 row (pr: 234). README.md and CLAIMS.md differ by one added line each, and main's stamp line is unchanged. ff08ab3c has parents 64a0b87f and fef9d2b8. The repository activity API shows every push since cdf78449 as a fast-forward (each before equals the previous after), so there was no force-push. All six commits are authored and committed by the wakesync noreply identity, with no trailer.
  • Code text unchanged (worry b, part 1). My script review234r2_strip_compare.py worked on the two exports. weight_sums.cpp with comments removed (my own lexer, and separately g++ -fpreprocessed -E -P) has the same text at both commits. weight_sums.py has the same token stream without comments and docstrings, and the same AST without docstrings. Only one docstring differs, the one of fold_constants. The file has no __LINE__, assert( or #line. Where the changes are at the head: the C++ comment block is lines 724 to 741 and the Python docstring is lines 181 to 203.
  • Binary unchanged (worry b, part 2, measured). I ran the PR's own weight_sums/build.sh - <dir> from each export, through fp-heavy.sh with taskset -c 2-3 (g++ 13.3.0, -O2 -fno-ipa-modref -std=c++17 -ffp-contract=off -pthread). Both weight_sums programs have SHA-256 3e3a92624b6b8e2bc991aebf01dc636291e1662102025b5eed10a224bc9405f0, and cmp finds them equal.
  • New factual claims (worry a). I checked each one at the head:
    • docs/model.md 11.3 (lines 411 to 437). The table gives RN32(sqrt(d)/64/sqrt(dh)) for attn_q and RN32(sqrt(d)/64) for the other rows. Lines 435 to 436: "The constants are the float32 bit patterns 0x3F8F1BBD and, for Wq, 0x3DCA62C2. They are right for d = 5,120 and dh = 128 only, and files with other values are rejected." It has no t and no sqrt(d)/2^t. The new text says exactly this. True.
    • scales/README.md. Line 542 says "the constant sqrt(d) / 64 into every matrix that reads the norm's output". Lines 594 to 601 define t and c for the norm sites' exponents and say "the conversion's constant sqrt(d) / 64 cancels c only where t = 6". So "gives the conversion's constant as sqrt(d) / 64 too", "c is what scales/README.md (step 2) defines for the exponents of the fit's norm sites" and "neither states sqrt(d)/2^t as the conversion's constant" are all true.
    • "For t != 6, using c is a choice made with this function": true, because no document I read states it.
    • The two example words, recomputed by my script (Decimal at 80 digits plus a neighbour check, without importing the PR's code). At (2048, 64) the PR's rule gives c_0 0x3FB504F3 and c_q 0x3E3504F3, while sqrt(d)/64 gives 0x3F3504F3 and sqrt(d)/64/sqrt(dh) gives 0x3DB504F3. At (5120, 128) both forms give 0x3F8F1BBD and 0x3DCA62C2, and at (5120, 256) both give 0x3F8F1BBD and 0x3D8F1BBD. True.
    • The tests. unit_test.cpp test_fold_constants (lines 332 to 353) pins 7 shapes: (5120,128), (5120,256), (2048,64), (4096,128), (1,1), (4,1), (2,1). That matches "seven shapes, (2048, 64) among them". fold_constants_test.py compares weight_sums.fold_constants with independent(), which uses the same t and c formula with an exact Fraction bisection, over 23 shapes including (2048, 64). That matches "a second exact computation of the same formula". True. One loose phrase: the Python docstring says unit_test.cpp "pins words of bin/weight_sums", but unit_test includes weight_sums.cpp and tests the function in its own program, not the bin/weight_sums binary. Nonblocking.
    • The gates. C++ plan() lines 1351 to 1354 refuse width != 5120 and key_length != 128 (an absent key, or one that is not unsigned, counts as 128) with outside_the_rule, which throws. In run(), plan() runs before convert_all and output.complete, and the .part file is removed by ~OutputFile. Python model_layers (lines 359 to 365) raises Fault while it reads the first shard, before select and write_sums_file. So "no other shape reaches a sums file" is true for both programs. refusals.py already has cases metadata.width-4096 and metadata.head-dimension-64.
  • Repository checks at the head (check 7), all exit 0. update-results.py --check ok (77 results, 1220 metrics). check-claims.py ok (77 claims, 69 unreplicated). check_inventory.py ok. check-no-host-paths.sh ok (working tree). The scrub gives total_matches=0 on the 8 changed files at the head, the six commit messages, the PR body and the mapping comment.
  • Main (check 9). git ls-remote main is fef9d2b8, an ancestor of the head. git merge-tree --write-tree fef9d2b8 419b12c3 gives ef942ab3, which is the head's own tree. GitHub reports draft, MERGEABLE, CLEAN.

Round-1 items

  • Must-fix 1, settled for the five places it named. weight_sums/weight_sums.py lines 181 to 203 and weight_sums/weight_sums.cpp lines 724 to 741 now cite 11.3 and scales/README.md only for sqrt(d)/64. So does weight_sums/README.md lines 229 to 237. The row summary is at research/results.yaml line 2099, with the same text at README.md line 88 and CLAIMS.md line 90. In RESULTS.md, "The answer to the issue's first question" (lines 22 to 26) and "In plain words" (line 7) are also corrected. Each says the documented constant equals c only where t = 6 and calls c for other widths this PR's choice, untested against scales/. Not settled PR-wide: see must-fix below.
  • Must-fix 2, settled. The PR body no longer says the branch conflicts with main. "Merge notes" names both syncs (28308f55 + 111b104d for main 1599e1b9, ff08ab3c + 419b12c3 for main fef9d2b8). "Changed after the round-1 review" says that 64a0b87f holds the hand-edited row together with the regenerated files under a regeneration-only message, and that nothing was rebuilt. I found nothing in the body that is wrong for this head. Its sentence about the rebuild ("an argument and not a measurement") is now answered by my build above.
  • Nonblocking line reference, settled. prover/weights_blocks/gguf_source.cuh line 29 holds if (file_.embedding_length != 5120 || file_.key_length != 128), and RESULTS.md line 50 now says 29.
  • Round-1 nonblocking items left open (check 6). The mapping comment lists: the CUDA-literal test and the gate comments (now at weight_sums.py 359 and weight_sums.cpp 1351), the C++ hang on 0, RESULTS item 4, independent_values.py's "exact" method, and the "0 of 20,066,032" wording. Round 1's worry c paragraph made no request beyond worry d's. None was dropped silently.

Worries

  • c (commit 64a0b87f). Accepted as it stands. In research/results.yaml only the summary string of fold-constants-214 changes (1 line in, 1 line out). No metric value, source, commit, id, status or pr: changes. The generated README and CLAIMS rows carry the same text, and update-results.py --check agrees. The PR body and the mapping comment both say plainly what the commit holds. Repairing it would need a history rewrite, which costs more than the wrong message does.
  • e (PREREG A2). Fine. It is appended under "Amendments" (lines 74 to 81), dated 2026-11-29 04:10 UTC, and alone in b831cfac, which was pushed at 04:10:52Z, before 774225a1 was pushed at 04:18:13Z. No later commit touches PREREG.md. It changes no threshold, class, case, run or count. It names the "Prior art" sentence (line 61) as overstated and leaves the registered text alone, which is the right handling.
  • d (the same overstatement elsewhere). I searched the PR's changed and added files for 11.3, scales/README, "the rule" and "conversion rule". Results:
    • weight_sums/tests/fold_constants_test.py lines 7 to 8: must-fix (below).
    • PREREG line 61: corrected by A2. Acceptable.
    • RESULTS line 50, "lines 30 to 32": the comparison is on lines 31 to 32. Nonblocking.
    • research/weight-binding/DESIGN.md line 154 (weight_sums.py:412-414) is not in this PR. Nonblocking, for a later docs pass.
    • The row and PR title "computed by the rule for any width and head size" reads as if a repository rule existed for every width. The summary right next to it now says otherwise, so this is nonblocking, but a title like "computed by one formula for any width and head size" would be more exact.

Must-fix

  1. weight_sums/tests/fold_constants_test.py lines 7 to 8: "returns the binary32 bit patterns of the two constants of the conversion rule (scales/README.md, "The exponent of each cell", step 2)". This is the round-1 overstatement again, in a file this PR adds, and it now contradicts the corrected docstring of the function it tests. To settle: reword the docstring only, for example "of the two fold constants as fold_constants defines them (c = sqrt(d) / 2^t; equal to the documented sqrt(d) / 64 of docs/model.md 11.3 only where t = 6; for other widths a choice made in PR research: fold constants by the rule for any width and head size (#214, CPU part) #234)". Show that the file's AST without docstrings and its token stream without comments and docstrings are unchanged. The fix lane could not do this, because its brief forbade test files.

Nonblocking

  • RESULTS.md line 50: "lines 30 to 32" should be "lines 31 to 32".
  • weight_sums.py line 200: "unit_test.cpp pins words of bin/weight_sums" should say "of the C++ fold_constants (unit_test includes weight_sums.cpp)".
  • Row and PR title: "by the rule" (see worry d).
  • research/weight-binding/DESIGN.md line 154: stale line reference, not in this PR.
  • Round 1's open nonblocking items, as the mapping comment lists them.

Main sync needed: no (main fef9d2b800b49a2d3eefb45dda82c58474cc25d4, already merged; a trial merge gives the head's own tree).
CI (check-runs API at 419b12c3): guard completed/success 04:26:59Z, claims completed/success 04:27:01Z.

Skipped checks

  • I did not rerun run_tests.sh, unit_test, fold_constants_test.py or the 19-file comparison. The brief does not ask for them, and the code text and the binary are unchanged. The Python side rests on the AST and token comparison only, because there is no Python binary to compare. The one runtime difference is fold_constants.__doc__, which nothing in weight_sums/ reads (the only __doc__ reader is the module docstring at line 713).
  • I did not build unit_test at either commit.

For the person deciding on a waiver

A merge would put new code into two upstream prover source files. That code is round 1's, unchanged in this round. In weight_sums/weight_sums.cpp, rn32_sqrt_word (lines 690 to 722), fold_constants and struct FoldConstants (lines 742 to 751), and kNormConstant, kQueryConstant and the static_assert (lines 757 to 763). In weight_sums/weight_sums.py, rn32_sqrt_word (lines 147 to 178), the body of fold_constants (lines 204 to 208) and NORM_CONSTANT and QUERY_CONSTANT (lines 215 to 219). The changes this round are comments only: C++ lines 724 to 741 and Python docstring lines 181 to 203. It would also add one new test file and a new step in the existing unit test. I built bin/weight_sums from both commits and the two programs are byte-identical. At the one admitted shape (5,120, 128) the program the prover uses does not change. Round 1 showed the 19 sums files equal. A merge would NOT establish:

  • that c = sqrt(d) / 2^t is the right fold constant for any width outside 4,096 to 16,383 (the PR now says so itself);
  • anything about the CUDA reader, block_weights.py or oracle.py, which keep their literals;
  • any opened shape gate;
  • anything about Qwen weights.

If you waive, the one thing left is a two-line docstring in the new test file. It repeats the citation round 1 asked to correct. The thing I am least sure of is the Python side. For C++ I compared built binaries, but for Python I compared source text only, and I did not run the Python tests at the new head.

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