Skip to content

core: make the fragment check catch a transposed operand - #744

Merged
ashhart merged 1 commit into
ashhart:mainfrom
harrisonfriia:pr/frag-check-transposes
Oct 13, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
harrisonfriia:pr/frag-check-transposes

Conversation

@harrisonfriia

Copy link
Copy Markdown
Contributor

What this changes

frags.check can't detect a transposed operand. Nemotron and Flash Next run it at load to verify nax.h's fragment layout, but its mod 5 test values make every block of the transposed operand symmetric: its row pitch is 16, which is 1 mod 5. Loading that operand as a plain one still produces the expected sums.

This switches the values to mod 13, which breaks the symmetry and keeps every sum an exact small integer. It also adds a GPU test that runs the check against a plain-loaded variant. Every GPU I tested reads the layout correctly, so nothing changes on them. The check now stops a load if a GPU, a Metal compiler, or an edit to nax.h introduces that mistake.

Part of #743.

Receipt

  • Environment, with the TensorFold commit, MLX or PyTorch version, machine and GPU, checkpoint and revision: base 0efbd44, candidate 0e49fec. Zig 0.17.0, native Metal, no MLX or PyTorch, Xcode 27.0 (Metal 32023.921). Full suite on an M3 Ultra (80-core GPU, 256 GB, macOS 27.0.1). The new test also ran on an M2 Max (38-core GPU, 64 GB, macOS 27.0.1) and an M4 (10-core GPU, 24 GB, macOS 26.6.2). No checkpoint: the check and its test use synthetic values.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: not applicable. No kernel, token path or model arithmetic changes.
  • Decode speed before and after, from tools/bench_openai.py: not applicable. The check runs once at load.
  • Prompt speed before and after, from tools/prefill_cold.py: not applicable, for the same reason.
  • Tests run, with pass, fail and skip counts:
    • M3 Ultra, zig build test test-golden -Dcpu=apple_m1: 1,506 passed, 0 failed, 8 skipped, one more than the base's 1,505. 158 of 160 steps succeed. The failing step fails on the base too: core.checkpoint_metal's split-checkpoint test passes but logs checkpoint tensor text.weight stays in its file: read it through a Stage. Goldens: 309/319 equal to the frozen answers, 10 declared differences, 0 unexpected. zig build native -Dcpu=apple_m1 -Dversion=1.0.0 builds.
    • The new core.frags test, "the check passes this GPU's layout and, before M5, fails a transposed operand loaded as a plain one", passes on the M3 Ultra, M2 Max and M4. With the old mod 5 values it fails on the M3 Ultra and M2 Max with TestUnexpectedResult, because the plain-loaded variant matches the host's sums. The M2 Max and M4 ran an earlier build of this test that differs only in comments and in skipping the plain-loaded half on M5.
    • On M5, frag_get_t is frag_get and mma_16x32 does the transpose, so swapping them changes nothing there; the test checks only the first half on M5.
    • zig fmt --check build.zig zig is clean. python3 tools/zig/lean_check.py reports 539 problems, the same as the base, all inherited.
  • Not run, and why: M1 and M5, because neither was available. Nemotron and Flash Next run the check on M5 too. Its sums stay exact on every GPU, though mma_16x32 asks for relaxed precision: the inputs are bf16 integers from -6 to 6, and each output's terms sum to at most 254 in magnitude, so every partial sum in any order is exact even in a bf16 accumulator. CUDA has no changed code. No model loads: the test runs the kernel those families run at load, on each GPU listed.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. No token path changes.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Prompt processing is no slower than the last release. No prompt path changes.
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. Before M5; on M5 the test checks only the correct layout, which the old values also pass.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

frags.check fills its operands with (i * 7 + salt * 3) mod 5. The
transposed operand has a row pitch of 16, and 16 is 1 mod 5, so each of
its values depends only on row plus column. Every block of it is then
symmetric, and loading it as a plain one gives the same sums. Before M5
the check is the load-time guard on nax.h's simdgroup-matrix fragment
layout, and it couldn't detect a transposed operand.

Values mod 13 break that symmetry and stay small integers, so products
and sums are exact in any order. A GPU test runs tf_frag_check as is
and, before M5, with frag_get_t swapped for frag_get: the first must
match the host's sums and the second must not. With the old values both
match, so the test fails. On M5, frag_get_t is frag_get and mma_16x32
does the transpose, so the swap changes nothing there and the test
checks only the first part.
@ashhart
ashhart merged commit b3db79c into ashhart:main Oct 13, 2026
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 13, 2026
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 13, 2026
@ashhart

ashhart commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Thank you, @harrisonfriia. A load-time check that can't see a transposed operand reads as cover it doesn't give, and values mod 13 close that hole while keeping every sum exact. Your commit landed in 1.0.9 under your name (877f6d454), and the PR's head is merged into the history with no change to the tree (b3db79c03), so GitHub shows this PR as merged.

What we ran:

  • Your test on an M3 Ultra. It passes, and with the old mod-5 values put back it fails with TestUnexpectedResult, as your receipt says, because the plain-loaded transposed operand matches the host's sums.
  • On an M5 Ultra. Your test passes. There the multiply does the transpose, so it checks the layout alone, as you wrote. Flash Next 6-bit loaded through the check with the new values and gave 1.0.8's tokens in 9 of 9 cases, and GLM-5.3-Flash on two M5 Ultras loaded through it on both Macs with every reply equal to 1.0.8's.
  • In the 1.0.9 release gate. Nemotron loads through the check on an M5 Max and an M3 Ultra with 1.0.8's tokens in every release cell.
  • A broken layout stops the load. GLM-5.3-Flash, with GLM: run the fragment check at load #745, stops at load when the check kernel loads the transposed operand as a plain one; details on GLM: run the fragment check at load #745.
  • Host suite. On macOS your test is one more, and it skips cleanly without a GPU.

Every partial sum stays within 254 in magnitude, so it's exact even in a bf16 accumulator. M1 is unrun here.

@ashhart ashhart mentioned this pull request Oct 14, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
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.

2 participants