Skip to content

fix(kernel): strip the address space from the pair-code table field - #5

Merged
jason-fxz merged 1 commit into
mainfrom
fix/pair-code-addrspace
Nov 18, 2026
Merged

jason-fxz merged 1 commit into
mainfrom
fix/pair-code-addrspace

Conversation

@jason-fxz

Copy link
Copy Markdown
Collaborator

On macOS 27, any checkpoint with pair-coded experts (e.g. Ornith-1.5-35B-A3B-4bit) fails at startup:

RuntimeError: [metal::Device] Unable to build metal library from source
utils.h:5419:13: error: field may not be qualified with an address space
  PairTable pairs;
note: in instantiation of template class 'PairCodeScales<bfloat, 13, const device bfloat *thread>'

MLX compiles these kernels at runtime at the newest Metal language version the OS supports, which is 4.1 on macOS 27. From 4.1, decltype(pairs) keeps the variable's own thread address space, and a struct field may not carry one. PairCodeScales now strips it with metal::remove_addrspace_t, which keeps the pointee's device/constant space, so both decltype(pairs) call sites (gather qmv, down-combine) are fixed unchanged.

A standalone repro of the pattern, compiled with MTLCompileOptions.languageVersion on macOS 27:

3.1 3.2 4.0 4.1
Holder<decltype(pairs)> (main) OK OK OK fails
remove_addrspace_t field (this PR) OK OK OK OK

Tested on M4 (24 GB), macOS 27.2.1:

  • uv run pytest tests/kernel/moe/affine/test_affine_{gather_qmv_pair_codes,down_combine,glu_pending}.py: 65 failed / 54 passed on main, 119 passed here
  • uv run pytest tests/: 1923 passed, 5 skipped (FTMETAL_TEST_MODEL_PATH unset)
  • uv run ftm serve --model <ckpt> --port 18997 for Ornith-1.5-35B-A3B-4bit, Qwen3.6-35B-A3B-4bit and Flint-40B-A2.5B-int4: each starts and answers "What is 17 * 23?" with 391; Ornith on main exits at CommandGraph capture

Not run on a macOS 15 machine: the 3.1/3.2 results use macOS 27's own Metal headers.

From Metal 4.1 (macOS 27), decltype(pairs) keeps the variable's own thread
address space, and a struct field may not carry one, so the pair-code gather
qmv and down-combine kernels failed to build. Metal 3.1 to 4.0 are unaffected.
@jason-fxz
jason-fxz merged commit c22fafb into main Nov 18, 2026
1 check passed
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.

1 participant