Skip to content

fix(metal): the 27B's prompt attention and tf_lane_reg compile on macOS 27 - #573

Merged
ashhart merged 1 commit into
ashhart:mainfrom
jkuepker:qwen27-macos27-compile
Oct 10, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
jkuepker:qwen27-macos27-compile

Conversation

@jkuepker

Copy link
Copy Markdown
Contributor

On macOS 27 the 27B engine (qwen27) cannot load. Two of its Metal kernels fail to compile at startup, and the load stops with LibraryLoad:

program_source:535:25: error: no matching member function for call to 'get_destination_cooperative_tensor'
program_source:549:25: error: no matching member function for call to 'get_destination_cooperative_tensor'
error: LibraryLoad

Under Metal 4.1, decltype of a cooperative-tensor local keeps its thread address space, and matmul2d::get_destination_cooperative_tensor rejects that type. Three call sites pass such a type:

  • q27_mma_s and q27_mma_o in zig/kernels/metal/qwen27/attention_prompt.metal. These fail first.
  • tf_lane_reg in zig/kernels/metal/core/lane_projection.metal. This fails next, at the first projection, once attention compiles.

The fix wraps those template arguments in metal::remove_addrspace_t, as nax.h already does. It changes template arguments only. There is no arithmetic, layout or dispatch change.

Receipt

Setup: M5 Max, macOS 27.0 (26A428), Xcode 27.0 (27A266a), Metal 32023.921, Zig 0.17.0, Qwen3.8-27B MLX 4-bit, 2,048-token prompt. Both columns were built the same way (-Dcpu=apple_m1); "before" is this branch with main's two kernel files restored.

check main 0d83398b this branch bc93801d
tf-core-lane-reg-check LibraryLoad (tf_lane_reg, line 243) REG CHECK PASS cases=352
tf-qwen27-synthetic LibraryLoad 19 prompt chunk widths byte-equal to chunk 1, 7 decoded-row widths equal to the CLI tree
tf-qwen27-run --max-tokens 32 --compare-chunk 16 LibraryLoad (attention, lines 535/549) prompt_state_byte_equal: true, prompt_sha256 c89730be…
same, TF_ANE_COLUMNS=0 not run (load fails) prompt_state_byte_equal: true, prompt_sha256 1ae7ce8f…

Host gates on the branch:

  • zig build native -Dcpu=apple_m1 -Dversion=1.0.0: builds.
  • zig build test test-golden -Dcpu=apple_m1: exit 0. The golden corpus reports 309/319 equal and 0 unexpected differences; the other 10 are known differences.
  • python3 tools/zig/lean_check.py: 509 problems on main and 509 on the branch, so the fix adds none. All 509 are inherited and none is in the two files touched.

I could not test macOS 26 here. nax.h already uses remove_addrspace_t the same way and ships today, so the wrapped form should still compile there.

…OS 27

On macOS 27 (Metal 4.1) decltype of a cooperative-tensor local keeps its
thread address space, and matmul2d's get_destination_cooperative_tensor
rejects that type, so the qwen27 engine refused to load (LibraryLoad):
first q27_mma_s/q27_mma_o in attention_prompt.metal, then tf_lane_reg on
the first projection. Strip the address space, as nax.h already does.
@ashhart ashhart mentioned this pull request Oct 10, 2026
@ashhart
ashhart merged commit 67b80aa into ashhart:main Oct 10, 2026
1 of 2 checks passed
@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you, @jkuepker. This is in main as 67b80aa, your commit merged as it was, and it fixes #579.

We checked it with macOS 27.0.1's own Metal compiler. Compiling the exact sources the 27B builds at startup, with the engine's options, main's prompt attention fails at lines 535 and 549 and the lane projection's register kernel at line 243, the errors in #579, and your versions compile. At Metal 4.0, the version macOS 26 compiles with, both versions compile. We also looked for any other call that passes a cooperative tensor's own type to get_destination_cooperative_tensor, and there is none; the others pass tensor slices, which compile. The Mac we tested on has no tensor units, so the kernels' bytes on an M5 rest on your receipt for now. @BobClawblaw's #578 made the same change, so main has it once. It ships in the next release. Thanks again!

BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 10, 2026
@jkuepker
jkuepker deleted the qwen27-macos27-compile branch October 10, 2026 15:05
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