Skip to content

Let the core lane projection run on Macs without tensor units - #679

Merged
ashhart merged 2 commits into
ashhart:mainfrom
cwschroeder:lane-projection-simd
Oct 12, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
cwschroeder:lane-projection-simd

Conversation

@cwschroeder

Copy link
Copy Markdown
Contributor

What this changes

FZ_LANE=1 selects the core lane projection for Flash Next's target layers, and the speed-up guide sets it. On Macs without tensor units (M1 to M4) it stops at load with TensorUnitsRequired. With a Metal 4 runtime, this lets the existing 6-bit/group-32 projection run there through the shared simdgroup fragment selection (TF_SIMD_FRAGS, as affine_mm.metal does). The default route and each row's arithmetic are unchanged, and other layouts stay refused. It is a compatibility fix, not a speed-up: on the tested M3 Ultra, token hashes matched the legacy route for the recorded prompts, and measured decode rates were 0.46-0.55% lower in this session; these measurements do not establish a sustained performance difference.

Receipt

  • Environment: base e7c523e, candidate 82128cc; Zig 0.17.0/native 1.0.7, native Metal (no MLX/PyTorch). M3 Ultra/256 GiB/macOS 27.0.1; M5 Max/128 GiB/macOS 26.6.2.
    Checkpoint TensorFold/Qwen3.8-Flash-Next-MLX-6bit-MTP at 45032a193a5d4126ba8534822cbaf8fb30b3e368; greedy, context 131072, one lane, cache off for timing; sampled peak process footprint 171.815 GiB during the legacy/core-lane comparison and 172.513 GiB during the earlier model gate.
  • Exactness: 3/3 drafted/draft:false pairs match across routes, including a 256-token thinking prefix; the candidate default-route spot check matches base.
    Prior gate: 2/2 resumed replies equal fresh; 30/30 queued replies equal solo. Hashes available on request.
  • Decode, tools/bench_openai.py: M3 Ultra, base legacy → candidate FZ_LANE=1, ABBA, 256 tokens/3 reps per block: code 107.69 → 107.20 tok/s (-0.46%); chat 103.30 → 102.73 (-0.55%).
  • Cold prompt/TTFT rates, using an existing prefill_cold.py run helper copied separately because it is absent from both pinned commits; 3 reps per length, legacy → core lane: 2k 1202.4 → 1199.5 tok/s (-0.24%); 8k 1381.5 → 1382.5 tok/s (+0.07%); 16k 1438.1 → 1442.9 tok/s (+0.33%); 32k 1431.3 → 1437.3 tok/s (+0.42%); 64k 1424.0 → 1427.8 tok/s (+0.27%). All requests had cached_tokens 0. Request bodies, native token arrays, timings and cached-token counts for both routes: https://gist.github.com/cwschroeder/b3b6d04e0e0018a20f5b058c42306377 (one 64k body is withheld because the prompt builder picked up a local build-configuration file; its timings and counts are there). Rates include request/render and first-token overhead. Lengths are nominal; some 8k/16k requests differed by one token. Prefill ran legacy then candidate once; ABBA applies only to decode.
  • M3 kernel bits: 13 layouts, 1768 solo-row/window pairs, 208 frozen byte-equal windows, 6656 independent FP64 values.
  • M5 kernel bits: the same counts and fixture bytes; both chips' worst fp32 error is 0.000180602. Explicit sum order and precision stay unchanged.
  • Tests (prior receipt): each Mac host 1290 passed/0 failed/2 skipped; fmt passed; native build 44/44. M3 fallback and M5 slice each 13 passed/0 failed/0 skipped; M3 7 expected refusals, M5 --simd 1 skip.
    8 capability outcomes passed (7 skips, 1 expected shader failure); lean checker 534 inherited/0 added. M3 regression and core-lane load fail before/pass after.
    Full M5 suite: 68 passed/1 inherited cooperative FP64 failure/46 not reached; two new unchanged-base runs agree. Logs available on request.
  • Not run: M1/M2/M4/CUDA and physical macOS 15 (unavailable); TP/dump replay, sampled decode, separate-runtime teacher forcing, seam-state/cancellation stress and 128k/full-window timing (outside this gate).
    test-golden, previous-release/standard-server comparisons and GitHub CI have not run. The inherited M5 failure remains open.

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, for the tested greedy requests (Flash Next queues).
  • 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. Last-release comparison not run.
  • 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 (unsupported-runtime checks use injection).
  • 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.

I have two M3 Ultras on Thunderbolt 5 and several GB10s for receipts; I'm @supermeister on X if that's quicker for scheduling a gate.

@mrv777

mrv777 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Tested 82128cc3 against base e7c523eb on an M1 Max (32-core GPU, 32 GB), macOS 26.7, Xcode 26.6, Metal compiler 32023.883 / SDK 26.5, Zig 0.17.0; native binary reports 1.0.7.

The base checker exits with TensorUnitsRequired. On the candidate, test-core-lane and tf-core-lane-check --simd both pass on the actual GPU, with zero skips. Each run reports:

  • 13 layouts, 1,768 byte-equal row/window pairs, 208 frozen windows, 6,656 FP64-reference values, and seven expected unsupported-layout refusals.
  • Worst FP32 error 0.000180602; worst roundoff-bound fraction 0.014385. Frozen fixtures are unchanged from the base.

Native build passes. The fresh full suite reports 1,289 passed, one failed, two Linux-only skips. Goldens: 309/319 equal, 10 declared differences, zero unexpected differences. Lean checker: 534 inherited findings, zero added; its exit remains 1.

The full-suite failure is the existing GLM sparse-attention test in zig/src/families/glm/attn_check.zig (“sparse attention on the tensor units: the row kernel's values within bf16 rounding”). Both base and candidate report 20.00% equal outputs, worst difference 128.00 bf16 steps. The test, GLM kernel, and shared fragment helper are unchanged. This failure was not fixed or counted as a clean gate.

Both commits used the same local launcher selecting the installed Metal compiler/linker because SDK-specific xcrun selected a nonworking stub. No project-source changes.

This supports the synthetic 6-bit/group-32 fallback on this M1/runtime. No checkpoint, model token/resume/concurrency checks, performance measurements, or CUDA device tests were run.

@cwschroeder

Copy link
Copy Markdown
Contributor Author

Thanks, @mrv777. That covers M1, which I couldn't test, with the same 13 layouts, 1,768 pairs and worst error (0.000180602) as on M3 and M5. The GLM sparse-attention failure is the same on base and candidate, so I'm leaving it out of this PR.

@ashhart
ashhart merged commit 168f103 into ashhart:main Oct 12, 2026
@ashhart

ashhart commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Thank you, @cwschroeder. FZ_LANE=1 stopping at load on M1 to M4 was a real gap, since the speed-up guide set it until now, and your fragment mapping follows the simdgroup layout our prompt kernels already use on those Macs. Your two commits (0a238c2e6, 82128cc3e) landed in 1.0.8 under your name, on top of #698, so GitHub shows this PR as merged.

What we checked:

  • M3 Ultra. Before your change tf-core-lane-check stopped at TensorUnitsRequired. With it, the check passes Flash Next's 13 layouts (1,768 row/window pairs, 208 frozen windows, 6,656 CPU values, worst fp32 error 0.000180602) and gives the 7 refusals, the same with --flashnext and --simd. The frozen windows were captured on an M5 Max, so every window is byte-equal to the M5's, and per-layout hashes of all 13 layouts' outputs equal an M5 Ultra's.
  • Macs with tensor units keep their bits. We hashed every layout's single-row and window outputs with and without your change on an M5 Max: all 115 are byte-identical, so the new index expression and the per-column guard change nothing there. An M5 Ultra gives the same 115 hashes.
  • Flash Next on an M5 Ultra (6-bit, greedy, thinking off), with FZ_LANE=1 FZ_GDN=2: drafted equals "draft": false on 8 of 8 release prompts, and the replies are the same tokens as before your change, 8 of 8. The default route is the same, 8 of 8, and both routes give the same tokens. Decode on the FZ_LANE route is level: over 16 requests a build in a B A A B run, the server's rates were 138.7 against 138.8 tok/s on prose and 201.2 against 201.7 on code. An earlier A B B A run read prose 1.3% lower because the first request on both servers with your change ran slow, and that did not happen again.
  • Not run by us. Flash Next served on an M3 with FZ_LANE=1. Your M3 Ultra receipts carry that part, and they line up with the kernel checks above.

One change in 1.0.8 that touches this: the speed-up guide no longer sets FZ_LANE=1 FZ_GDN=2, because on our M5 Ultras they decode 2 to 5% slower than the default kernels, on one Mac and on the pair, with the same replies. Your fix keeps them working on M1 to M4 for anyone who sets them. If you run speed-up mode on your two M3 Ultras, we'd like to see the default route's numbers beside FZ_LANE=1 FZ_GDN=2's.

@cwschroeder

Copy link
Copy Markdown
Contributor Author

Thanks, @ashhart, and thanks again to @mrv777 for the independent M1 check. Both #679 and #698 have now landed in 1.0.8, and your before/after layout hashes and model-token checks add the complementary M5 evidence.

The proposed M3 comparison will keep the default route and FZ_LANE=1 FZ_GDN=2 as separate arms, with the same checkpoint, requests and token-equivalence checks. M3 performance needs its own measurements.

The two-Mac Thunderbolt/RDMA arm is paused after a teardown hang, until that fault is understood. A single-Mac route comparison can precede it.

For anyone seeing today's failure notifications: the upstream Actions summaries for these PRs report that approval expired; the jobs never ran. That CI state is separate from the hardware checks you reported here.

BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
@grantoverton grantoverton mentioned this pull request Oct 13, 2026
8 tasks done
grantoverton added a commit to grantoverton/TensorFold-pr that referenced this pull request Oct 13, 2026
…d 16-row members

Format accepts 2-, 3- and 5-bit codes beside 4, 6 and 8, in groups of 32, 64 or 128. The non-4-bit path widens 2- and
3-bit codes to nibbles for the bf16 x uint4 op and 5-, 6- and 8-bit codes to bytes for the uint8 op, the staging the
Python lane matmul uses, so each width keeps that arithmetic. 3- and 5-bit groups of 32 are an odd number of words a
lane; they are fetched a word at a time instead of in pairs, which would drop the last word.

Layout.y_stride (default N) sets the elements between output rows in every kernel (tf_lane, tf_lane_pair, tf_lane_reg),
so a member of a fused stack writes its columns of the fused rows; the output bound checks follow it. The store of
the simdgroup-matrix layout (Macs without tensor units, ashhart#679) takes the same stride and keeps its column guard.

N may be a multiple of 16 on the plain kernel: the last 32-column tile is packed with zero codes past N, its metadata
reads and stores are already guarded by N, and weightWords counts the padded tiles (sourceWords is MLX's W).
Cooperative and reg layouts still need N % 32 == 0. encodeSums checks its sums buffer by the group count, as ashhart#698
sizes the dispatch.

Without tensor units the admitted layout is unchanged: 6-bit group 32 on the plain kernel (ashhart#679); every other width
still answers TensorUnitsRequired there, now checked at 2, 3 and 5 bits too.

With the defaults the 4-, 6- and 8-bit kernels preprocess (metal -E) to the same text as main's for every group,
schedule, output, prepared-sums/reg layout and both fragment layouts tried (148 variants), so the uniform paths
keep their kernels. Host tests that fail before: 2, 3 and 5 bits validate; y_stride reaches the source and below N
is refused; a 48-row member validates (cooperative and reg refuse it); every width x group x {64, 48} rows packs
MLX codes bit for bit with zero padding. The device program covers every width, 48-row members and strided output
on tensor units; without them (M3 Ultra): PASS 14 layouts, 1904 bit-equal row/window pairs, 208 windows equal to
fn_lane's recorded bytes, 7424 CPU values (max roundoff-bound fraction 0.0144), 10 refusals, and a 48-row member
and two strided layouts at 6/32 equal the unstrided rows with the gaps untouched. fn_lane's recorded windows are
compared only on the layouts they were recorded at.

Gate on main 0efbd44 (M3 Ultra, Zig 0.17.0): `zig build test test-golden -Dcpu=apple_m1` has 309/319 goldens
equal and 0 unexpected; every step passes but one that fails on main too (core.checkpoint_metal's split-checkpoint
test: `get` logs an error on the DeferredTensor path the test expects). lean_check: 536 problems (main 539), no
new findings.
grantoverton added a commit to grantoverton/TensorFold-pr that referenced this pull request Oct 13, 2026
…d 16-row members

Format accepts 2-, 3- and 5-bit codes beside 4, 6 and 8, in groups of 32, 64 or 128. The non-4-bit path widens 2- and
3-bit codes to nibbles for the bf16 x uint4 op and 5-, 6- and 8-bit codes to bytes for the uint8 op, the staging the
Python lane matmul uses, so each width keeps that arithmetic. 3- and 5-bit groups of 32 are an odd number of words a
lane; they are fetched a word at a time instead of in pairs, which would drop the last word.

Layout.y_stride (default N) sets the elements between output rows in every kernel (tf_lane, tf_lane_pair, tf_lane_reg),
so a member of a fused stack writes its columns of the fused rows; the output bound checks follow it. The store of
the simdgroup-matrix layout (Macs without tensor units, ashhart#679) takes the same stride and keeps its column guard.

N may be a multiple of 16 on the plain kernel: the last 32-column tile is packed with zero codes past N, its metadata
reads and stores are already guarded by N, and weightWords counts the padded tiles (sourceWords is MLX's W).
Cooperative and reg layouts still need N % 32 == 0. encodeSums checks its sums buffer by the group count, as ashhart#698
sizes the dispatch.

Without tensor units the admitted layout is unchanged: 6-bit group 32 on the plain kernel (ashhart#679); every other width
still answers TensorUnitsRequired there, now checked at 2, 3 and 5 bits too.

With the defaults the 4-, 6- and 8-bit kernels preprocess (metal -E) to the same text as main's for every group,
schedule, output, prepared-sums/reg layout and both fragment layouts tried (148 variants), so the uniform paths
keep their kernels. Host tests that fail before: 2, 3 and 5 bits validate; y_stride reaches the source and below N
is refused; a 48-row member validates (cooperative and reg refuse it); every width x group x {64, 48} rows packs
MLX codes bit for bit with zero padding. The device program covers every width, 48-row members and strided output
on tensor units; without them (M3 Ultra): PASS 14 layouts, 1904 bit-equal row/window pairs, 208 windows equal to
fn_lane's recorded bytes, 7424 CPU values (max roundoff-bound fraction 0.0144), 10 refusals, and a 48-row member
and two strided layouts at 6/32 equal the unstrided rows with the gaps untouched. fn_lane's recorded windows are
compared only on the layouts they were recorded at.

Gate on main 0efbd44 (M3 Ultra, Zig 0.17.0): `zig build test test-golden -Dcpu=apple_m1` has 309/319 goldens
equal and 0 unexpected; every step passes but one that fails on main too (core.checkpoint_metal's split-checkpoint
test: `get` logs an error on the DeferredTensor path the test expects). lean_check: 536 problems (main 539), no
new findings.
ThinkOffApp pushed a commit to ThinkOffApp/TensorFold that referenced this pull request Oct 14, 2026
…d 16-row members

Format accepts 2-, 3- and 5-bit codes beside 4, 6 and 8, in groups of 32, 64 or 128. The non-4-bit path widens 2- and
3-bit codes to nibbles for the bf16 x uint4 op and 5-, 6- and 8-bit codes to bytes for the uint8 op, the staging the
Python lane matmul uses, so each width keeps that arithmetic. 3- and 5-bit groups of 32 are an odd number of words a
lane; they are fetched a word at a time instead of in pairs, which would drop the last word.

Layout.y_stride (default N) sets the elements between output rows in every kernel (tf_lane, tf_lane_pair, tf_lane_reg),
so a member of a fused stack writes its columns of the fused rows; the output bound checks follow it. The store of
the simdgroup-matrix layout (Macs without tensor units, ashhart#679) takes the same stride and keeps its column guard.

N may be a multiple of 16 on the plain kernel: the last 32-column tile is packed with zero codes past N, its metadata
reads and stores are already guarded by N, and weightWords counts the padded tiles (sourceWords is MLX's W).
Cooperative and reg layouts still need N % 32 == 0. encodeSums checks its sums buffer by the group count, as ashhart#698
sizes the dispatch.

Without tensor units the admitted layout is unchanged: 6-bit group 32 on the plain kernel (ashhart#679); every other width
still answers TensorUnitsRequired there, now checked at 2, 3 and 5 bits too.

With the defaults the 4-, 6- and 8-bit kernels preprocess (metal -E) to the same text as main's for every group,
schedule, output, prepared-sums/reg layout and both fragment layouts tried (148 variants), so the uniform paths
keep their kernels. Host tests that fail before: 2, 3 and 5 bits validate; y_stride reaches the source and below N
is refused; a 48-row member validates (cooperative and reg refuse it); every width x group x {64, 48} rows packs
MLX codes bit for bit with zero padding. The device program covers every width, 48-row members and strided output
on tensor units; without them (M3 Ultra): PASS 14 layouts, 1904 bit-equal row/window pairs, 208 windows equal to
fn_lane's recorded bytes, 7424 CPU values (max roundoff-bound fraction 0.0144), 10 refusals, and a 48-row member
and two strided layouts at 6/32 equal the unstrided rows with the gaps untouched. fn_lane's recorded windows are
compared only on the layouts they were recorded at.

Gate on main 0efbd44 (M3 Ultra, Zig 0.17.0): `zig build test test-golden -Dcpu=apple_m1` has 309/319 goldens
equal and 0 unexpected; every step passes but one that fails on main too (core.checkpoint_metal's split-checkpoint
test: `get` logs an error on the DeferredTensor path the test expects). lean_check: 536 problems (main 539), no
new findings.
@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
ashhart#679 landed above as f909684d4 and 649b069b4 (the author's commits, rebased onto this candidate). This keeps the PR's own head commit in the history, with no change to the tree.
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
…d 16-row members

Format accepts 2-, 3- and 5-bit codes beside 4, 6 and 8, in groups of 32, 64 or 128. The non-4-bit path widens 2- and
3-bit codes to nibbles for the bf16 x uint4 op and 5-, 6- and 8-bit codes to bytes for the uint8 op, the staging the
Python lane matmul uses, so each width keeps that arithmetic. 3- and 5-bit groups of 32 are an odd number of words a
lane; they are fetched a word at a time instead of in pairs, which would drop the last word.

Layout.y_stride (default N) sets the elements between output rows in every kernel (tf_lane, tf_lane_pair, tf_lane_reg),
so a member of a fused stack writes its columns of the fused rows; the output bound checks follow it. The store of
the simdgroup-matrix layout (Macs without tensor units, ashhart#679) takes the same stride and keeps its column guard.

N may be a multiple of 16 on the plain kernel: the last 32-column tile is packed with zero codes past N, its metadata
reads and stores are already guarded by N, and weightWords counts the padded tiles (sourceWords is MLX's W).
Cooperative and reg layouts still need N % 32 == 0. encodeSums checks its sums buffer by the group count, as ashhart#698
sizes the dispatch.

Without tensor units the admitted layout is unchanged: 6-bit group 32 on the plain kernel (ashhart#679); every other width
still answers TensorUnitsRequired there, now checked at 2, 3 and 5 bits too.

With the defaults the 4-, 6- and 8-bit kernels preprocess (metal -E) to the same text as main's for every group,
schedule, output, prepared-sums/reg layout and both fragment layouts tried (148 variants), so the uniform paths
keep their kernels. Host tests that fail before: 2, 3 and 5 bits validate; y_stride reaches the source and below N
is refused; a 48-row member validates (cooperative and reg refuse it); every width x group x {64, 48} rows packs
MLX codes bit for bit with zero padding. The device program covers every width, 48-row members and strided output
on tensor units; without them (M3 Ultra): PASS 14 layouts, 1904 bit-equal row/window pairs, 208 windows equal to
fn_lane's recorded bytes, 7424 CPU values (max roundoff-bound fraction 0.0144), 10 refusals, and a 48-row member
and two strided layouts at 6/32 equal the unstrided rows with the gaps untouched. fn_lane's recorded windows are
compared only on the layouts they were recorded at.

Gate on main 8d006a3 (M3 Ultra, Zig 0.17.0): `zig build test test-golden -Dcpu=apple_m1` has 309/319 goldens
equal and 0 unexpected; every step passes but one that fails on main too (core.checkpoint_metal's split-checkpoint
test: `get` logs an error on the DeferredTensor path the test expects). lean_check: 536 problems (main 539), no
new findings.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…d 16-row members

Format accepts 2-, 3- and 5-bit codes beside 4, 6 and 8, in groups of 32, 64 or 128. The non-4-bit path widens 2- and
3-bit codes to nibbles for the bf16 x uint4 op and 5-, 6- and 8-bit codes to bytes for the uint8 op, the staging the
Python lane matmul uses, so each width keeps that arithmetic. 3- and 5-bit groups of 32 are an odd number of words a
lane; they are fetched a word at a time instead of in pairs, which would drop the last word.

Layout.y_stride (default N) sets the elements between output rows in every kernel (tf_lane, tf_lane_pair, tf_lane_reg),
so a member of a fused stack writes its columns of the fused rows; the output bound checks follow it. The store of
the simdgroup-matrix layout (Macs without tensor units, ashhart#679) takes the same stride and keeps its column guard.

N may be a multiple of 16 on the plain kernel: the last 32-column tile is packed with zero codes past N, its metadata
reads and stores are already guarded by N, and weightWords counts the padded tiles (sourceWords is MLX's W).
Cooperative and reg layouts still need N % 32 == 0. encodeSums checks its sums buffer by the group count, as ashhart#698
sizes the dispatch.

Without tensor units the admitted layout is unchanged: 6-bit group 32 on the plain kernel (ashhart#679); every other width
still answers TensorUnitsRequired there, now checked at 2, 3 and 5 bits too.

With the defaults the 4-, 6- and 8-bit kernels preprocess (metal -E) to the same text as main's for every group,
schedule, output, prepared-sums/reg layout and both fragment layouts tried (148 variants), so the uniform paths
keep their kernels. Host tests that fail before: 2, 3 and 5 bits validate; y_stride reaches the source and below N
is refused; a 48-row member validates (cooperative and reg refuse it); every width x group x {64, 48} rows packs
MLX codes bit for bit with zero padding. The device program covers every width, 48-row members and strided output
on tensor units; without them (M3 Ultra): PASS 14 layouts, 1904 bit-equal row/window pairs, 208 windows equal to
fn_lane's recorded bytes, 7424 CPU values (max roundoff-bound fraction 0.0144), 10 refusals, and a 48-row member
and two strided layouts at 6/32 equal the unstrided rows with the gaps untouched. fn_lane's recorded windows are
compared only on the layouts they were recorded at.

Gate on main 8d006a3 (M3 Ultra, Zig 0.17.0): `zig build test test-golden -Dcpu=apple_m1` has 309/319 goldens
equal and 0 unexpected; every step passes but one that fails on main too (core.checkpoint_metal's split-checkpoint
test: `get` logs an error on the DeferredTensor path the test expects). lean_check: 536 problems (main 539), no
new findings.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…d 16-row members

Format accepts 2-, 3- and 5-bit codes beside 4, 6 and 8, in groups of 32, 64 or 128. The non-4-bit path widens 2- and
3-bit codes to nibbles for the bf16 x uint4 op and 5-, 6- and 8-bit codes to bytes for the uint8 op, the staging the
Python lane matmul uses, so each width keeps that arithmetic. 3- and 5-bit groups of 32 are an odd number of words a
lane; they are fetched a word at a time instead of in pairs, which would drop the last word.

Layout.y_stride (default N) sets the elements between output rows in every kernel (tf_lane, tf_lane_pair, tf_lane_reg),
so a member of a fused stack writes its columns of the fused rows; the output bound checks follow it. The store of
the simdgroup-matrix layout (Macs without tensor units, ashhart#679) takes the same stride and keeps its column guard.

N may be a multiple of 16 on the plain kernel: the last 32-column tile is packed with zero codes past N, its metadata
reads and stores are already guarded by N, and weightWords counts the padded tiles (sourceWords is MLX's W).
Cooperative and reg layouts still need N % 32 == 0. encodeSums checks its sums buffer by the group count, as ashhart#698
sizes the dispatch.

Without tensor units the admitted layout is unchanged: 6-bit group 32 on the plain kernel (ashhart#679); every other width
still answers TensorUnitsRequired there, now checked at 2, 3 and 5 bits too.

With the defaults the 4-, 6- and 8-bit kernels preprocess (metal -E) to the same text as main's for every group,
schedule, output, prepared-sums/reg layout and both fragment layouts tried (148 variants), so the uniform paths
keep their kernels. Host tests that fail before: 2, 3 and 5 bits validate; y_stride reaches the source and below N
is refused; a 48-row member validates (cooperative and reg refuse it); every width x group x {64, 48} rows packs
MLX codes bit for bit with zero padding. The device program covers every width, 48-row members and strided output
on tensor units; without them (M3 Ultra): PASS 14 layouts, 1904 bit-equal row/window pairs, 208 windows equal to
fn_lane's recorded bytes, 7424 CPU values (max roundoff-bound fraction 0.0144), 10 refusals, and a 48-row member
and two strided layouts at 6/32 equal the unstrided rows with the gaps untouched. fn_lane's recorded windows are
compared only on the layouts they were recorded at.

Gate on main 8d006a3 (M3 Ultra, Zig 0.17.0): `zig build test test-golden -Dcpu=apple_m1` has 309/319 goldens
equal and 0 unexpected; every step passes but one that fails on main too (core.checkpoint_metal's split-checkpoint
test: `get` logs an error on the DeferredTensor path the test expects). lean_check: 536 problems (main 539), no
new findings.
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.

3 participants