Skip to content

qwen3_5_moe: a Mac reads an unquantized bf16 checkpoint through the row decoder - #272

Closed
bunnyfu wants to merge 3 commits into
ashhart:mainfrom
bunnyfu:qwen3_5_moe-bf16-mac
Closed

bunnyfu wants to merge 3 commits into
ashhart:mainfrom
bunnyfu:qwen3_5_moe-bf16-mac

Conversation

@bunnyfu

@bunnyfu bunnyfu commented Oct 2, 2026 •

Copy link
Copy Markdown

What

This adds a bf16 recipe for qwen3_5_moe on a Mac: the family can now serve a wholly unquantized checkpoint of this architecture. Before this, check refused every checkpoint that lacked MLX affine 4-bit metadata — even though load goes through mlx_lm, which happily reads bf16 weights as stored. So a 35B checkpoint like junafinity/Ornith-1.5-35B-A3B-uncensored (67 GB bf16, 17 shards, fused experts.gate_up_proj layout) was loadable and unservable. Now it serves.

Two changes make it work. First, check admits an unquantized checkpoint on darwin only; quantized checkpoints and every CUDA host keep the existing 4-bit/groups-of-64 rule untouched. Second, the row decoder gains a plain bf16 backend: every projection becomes its own one-row mx.matmul. That per-row loop is deliberate — a batched bf16 matmul is not row-exact (we measured row-bit mismatches at several projection shapes on M3 Max), and a drafted or shared window's row must keep exactly its one-row bits. A model with any quantized linear still requires the simd_qmm path, so no existing checkpoint changes reading.

One subtlety worth flagging: mlx_lm's sanitize drops the vision tower and the MTP tensors a bf16 checkpoint carries. The MTP weights are simply not read by the Mac lane today (it drafts with the DFlash v1 head); whether a Mac-lane MTP drafter makes sense is an open question — #274.

Receipts

New tests — tests/test_qwen36_moe_bf16.py, 7 tests, all green: window rows and shared streams equal one-row steps bit for bit on a tiny unquantized Qwen3.6-MoE-shaped model; plain projections equal their modules' bits; a partly quantized model is refused; check admits unquantized on a Mac only; load routes bf16 through the row decoder.

Focused gate over every touched consumer — 405 passed across test_qwen36_moe_bf16, test_qwen36_moe_rows, test_qwen36_family, test_qwen3_5_load, test_row_forward, test_unsupported_checkpoints, test_hub_and_checks, test_simd_qmm, test_simd_qmm_bits, test_affine_rows, test_affine_rows_metal, and the two test_lane_server admission tests.

Full Mac suite — 4,758 collected (--ignore=tests/cuda --ignore=tests/test_glm_exl3_bits.py, the latter CUDA-only since it imports triton): 4,371 passed / 376 skipped / 16 failed. All 16 fail identically on a pristine 0.6.2 worktree of main (14), or pass in isolation (2, order-dependent) — pre-existing baseline, none introduced by this branch. Upstream main carries no CI workflow at this SHA and recent PRs show zero checks, so these local runs are the receipt surface.

Real-checkpoint parity, staged (mlx_lm reference saved first, recipe lane second, never co-resident — they don't fit in RAM together). Greedy continuations: prompts 1 and 2 agree with the reference on all 8 decode steps; prompt 0 diverges at an exact top-2 tie in the reference itself — p(id 11) = p(id 13) = 0.43236102 in fp64, the recipe's step-0 argmax is the other half of the tie at ref-rank 0 — after which the continuation legitimately differs. Teacher-forced NLL delta over the reference's greedy 8-step paths: +0.0123 and +0.0385 nats. Max logit difference at prompt end: 0.44–0.84 across the 248,320 vocab logits, which is bf16 accumulation-order noise between mlx_lm's batched forward and the lane's one-row arithmetic; the engine's own contract — row-exactness against its serial decode — was verified to 128 rows on the real weights at load time.

Serve smoke on a spare port (M3 Max 128 GB, --context 4096 --no-drafts, 65.0 GiB resident, 49 s load): coherent chat, deterministic greedy repeats, three concurrent streams each byte-identical to the solo reply, ~29.7 tok/s serial decode.

Notes for review

  • Recipe book: docs/recipes/qwen3.6-moe.md gains a Mac execution section (Ornith layout, one-row matmul bits, MTP tensors not read on Mac, 128 GB / small --context guidance); the recipes table and RUNBOOK get pointers.
  • The plain backend's per-row loop is deliberately unbatched: the exactness receipts above depend on it. Batched variants measured non-exact on this hardware (MLX 0.32.3) — worth knowing before anyone "optimizes" it.

Bunny Fu added 3 commits October 2, 2026 22:22
…ow decoder

The family's check refused every checkpoint without MLX affine metadata, though its Mac lane
loads through mlx_lm, which reads bf16 weights as stored. A Mac now takes that case and keeps
the 4-bit/groups-of-64 rule for anything quantized and for every CUDA host; the row decoder
gains a plain backend whose projections are one-row mx.matmul calls, so a window's row keeps
its one-row bits, and a model with any quantized linear still needs the simd_qmm path.
… bits on the plain backend

A tiny unquantized Qwen3.6-MoE-shaped TextModel (16 experts, 8 a token, a shared expert) checks
window rows and shared streams against one-row steps, plain projections against their modules,
that a partly quantized model is refused rather than misread, that check admits unquantized
weights on a Mac only, and that load routes bf16 through the row decoder.
…16 checkpoint

The recipe page gains a Mac execution section (Ornith's 67 GB bf16 layout, the row decoder's
one-row bits, the MTP tensors a Mac does not read), the recipe table a bf16 column, and the
runbook a pointer beside the 27B's Mac notes.
@ashhart

ashhart commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Thank you, @bunnyfu. The receipts here are thorough, and you measured why the plain backend has to loop one row at a time: MLX's batched bf16 matmul is not row-exact on these shapes. Working out that prompt 0 split on an exact top-2 tie in the reference itself was careful too.

The Python engine is frozen (#286), so this won't merge there. Qwen3.6 MoE isn't on the Zig engine yet, so unquantized checkpoints for it wait for that family. The Zig engine already has bf16 projection kernels that fix each sum's order, so a row gets its one-row bits whether it runs alone or inside a window on the matrix units, and the family shouldn't need a per-row loop. Your tests, windows and shared streams equal to one-row steps, are the checks it gets, with your credit.

@ashhart ashhart closed this Oct 6, 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