Repository navigation
core: make the fragment check catch a transposed operand - #744
Merged
Merged
Conversation
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.
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
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 ( What we ran:
Every partial sum stays within 254 in magnitude, so it's exact even in a bf16 accumulator. M1 is unrun here. |
Closed
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
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.
What this changes
frags.checkcan't detect a transposed operand. Nemotron and Flash Next run it at load to verifynax.h's fragment layout, but itsmod 5test 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 tonax.hintroduces that mistake.Part of #743.
Receipt
0efbd44, candidate0e49fec. 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.tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: not applicable. No kernel, token path or model arithmetic changes.tools/bench_openai.py: not applicable. The check runs once at load.tools/prefill_cold.py: not applicable, for the same reason.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 logscheckpoint 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.0builds.core.fragstest, "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 oldmod 5values it fails on the M3 Ultra and M2 Max withTestUnexpectedResult, 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.frag_get_tisfrag_getandmma_16x32does the transpose, so swapping them changes nothing there; the test checks only the first half on M5.zig fmt --check build.zig zigis clean.python3 tools/zig/lean_check.pyreports 539 problems, the same as the base, all inherited.mma_16x32asks 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
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. No token path changes.