Skip to content

lane: gain-folding constants hardcoded for width 5,120 and head 128: compute them by the documented rule for Qwen's head dimension 256 (CPU) #214

Open

Description

@wakesync

Question

On main the two constants that fold a norm's gain into the following weights are literals that are right only for width 5,120 and head dimension 128 (weight_sums/weight_sums.py lines 148 to 151; prover/weights_commitment/fold_weights.cuh lines 175 to 186; prover/weights_commitment/fold_source.cuh line 136 refuses any other shape). Qwen3.8-27B has width 5,120 but head dimension 256, so the query constant does not apply to it. Can both constants be computed from the rule scales/README.md already states (line 542: the conversion folds sqrt(d) / 64 into every matrix that reads a norm's output and 1 / sqrt(dh) into the query; lines 594 to 600: t the largest integer with 4^t <= d, c = sqrt(d / 4^t)) for any width and head size, with byte-identical output at 5,120 / 128? Since Qwen's width is also 5,120, only the query constant should change.

Why this is on the shortest path

Committing Qwen weights (M3 in docs/qwen-port.md) goes through weight_sums and the weight reader; with the literals, a Qwen commit is either refused by the shape gate or, if the gate is lifted, folds the query weights with the wrong constant. A public fork made the same change for TinyLlama (width 2,048, head 64) and reports unchanged values at 5,120 / 128 and new values at 2,048 / 64 (marcellobardus/FlashProve-TinyLlama1.1B, commit c0eb59e, "fold constants by the general rule for any width (T4.1)", test weight_sums/tests/fold_constants_test.py; from public source, not verified by us). We need our own derivation and test for dh = 256; this is not a copy of their code.

One milestone (about 2.5 hours)

  1. PREREG first, alone: the rule (t the largest integer with 4^t <= d, c = sqrt(d) / 2^t, c_0 = RN32(c), c_q = RN32(c / sqrt(dh))) quoted from scales/README.md lines 542 and 594 to 600 on main, a check of whether sqrt(d) / 64 there is only the t = 6 case of c, the expected words at (5,120, 128) equal to the current literals, and the pass rule.
  2. A fold_constants(width, head) in weight_sums/weight_sums.py and the C++ twin, the CUDA reader taking d and dh, the shape gate relaxed only to "positive whole shape that matches the policy".
  3. Tests: the current literals reproduced exactly at 5,120 / 128; byte-identical weight_sums output against weight_sums/tests/oracle.py for every seed the suite already uses; the values at 5,120 / 256 recorded with an independent float64 / mpmath computation.

Out of scope

Partial rotary, the dh = 256 no-wrap barrier and every other Qwen admission gate (they stay closed), any GPU build or run, any weights.

What a negative result looks like

The rule in scales/README.md does not reproduce the current literals, or the suite rows change at 5,120 / 128: stop and report the difference.

Cost

CPU only, minutes, under 2 GB.

Activity

  1. added
    loop:ready
    P2
    gate:0
    on Nov 17, 2026
  2. added
    loop:active
    and removed
    loop:ready
    on Nov 29, 2026
  3. added 5 commits that reference this issue on Nov 29, 2026
  4. wakesync commented on Nov 29, 2026

    @wakesync
    OwnerAuthor

    Draft PR #234 (#234), CPU part of this issue. Head 472b409ad0f20fc3d995cf0d2d47efa681c918e4.

    • The rule reproduces main's literals: fold_constants(5120, 128) = (0x3F8F1BBD, 0x3DCA62C2) in both weight_sums.py and bin/weight_sums. sqrt(d) / 64 in scales/README.md is the t = 6 case of c = sqrt(d) / 2^t.
    • 19 of 19 sums files of the existing suite are byte-identical between base and head. run_tests.sh passes every step (26 at base, 27 at head).
    • At (5,120, 256): c_0 0x3F8F1BBD, c_q 0x3D8F1BBD (mpmath at 256 bits and exact integer roots agree).
    • NOT changed: the CUDA reader and its shape gate (no GPU here). The exact change they need is an open item in the PR's RESULTS.md. The shape gates of weight_sums also stay at 5,120 / 128, so no admission gate is opened. No Qwen commit, no weights.
    • The branch conflicts with main on the generated results files (another row landed). Must merge with a merge commit.
  5. added 3 commits that reference this issue on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2gate:0loop:active

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions