Repository navigation
Description
Environment: Apple M2 Max (30-core GPU, Metal 4), 32 GB, macOS 26.6.2, TensorFold v0.3.6.3 (1911880), mlx 0.32.2, serving Vontra/Qwen3.8-27B-MLX-4bit + z-lab/Qwen3.8-27B-DFlash2, --context 8192, TENSORFOLD_MEMORY_LIMIT_GB=25.
What I found
simd_qmm.install() (src/tensorfold/kernels/qwen/dense/v1/simd_qmm.py:546) is the only function that routes a model's nn.QuantizedLinear modules through simd_qmm globally. It has no callers:
grep -rn "simd_qmm" src/ --include='*.py' | grep -v 'dense/v1/simd_qmm.py' | grep install
# (no output)
grep -rn "QuantizedLinear.__call__" src/ --include='*.py'
# row_matmul.py:199 _draft_call (drafted modules only, via _DRAFT_ATTR)
# simd_qmm.py:553 _call (only from simd_qmm.install — uncalled)
# lane_qmm.py:387 _call (M5 tensor units only)On the M1–M4 row path, install_row_decoder() (families/qwen3_5/__init__.py:63) calls row_matmul.install(model, backend), which sets BACKEND and stacks weights but never patches nn.QuantizedLinear.__call__. route_drafter does patch it, but only flags the drafter's own modules, so target-model linears fall through to _draft_orig.
Net effect on this machine:
| path | runs |
|---|---|
decode (row_forward → row_matmul.project) |
simd_qmm |
lm_head (row_matmul.logits) |
simd_qmm |
prefill body (families/qwen3_5/family.py:95, self.core(...)) |
stock mx.quantized_matmul |
Measurements
Raw MLX on this box, group-64 4-bit, N=17408 K=5120, mean of 10 timed repetitions (mx.eval + mx.synchronize), run alongside an idle serving process holding ≈19 GiB of Metal memory:
| rows (M) | stock quantized_matmul |
simd_qmm |
simd / stock |
|---|---|---|---|
| 16 | 2.20 ms | 1.65 ms | 1.33× |
| 64 | 4.11 ms | 4.88 ms | 0.84× |
| 256 | 10.17 ms | 10.08 ms | 1.01× |
| 1024 | 31.50 ms | 40.03 ms | 0.79× |
| 2048 | 62.24 ms | 79.84 ms | 0.78× |
| 4096 | 124.60 ms | 217.77 ms | 0.57× |
Stock plateaus at 5.85 TFLOP/s; simd_qmm at 4.57. bf16 mx.matmul reaches 8.26 TFLOP/s at the same shapes — 41% above the 4-bit path.
import mlx.core as mx
from tensorfold.kernels.qwen.dense.v1 import row_matmul
N, K, M = 17408, 5120, 2048
w = mx.random.normal((N, K)).astype(mx.bfloat16)
pw, s, b = mx.quantize(w, group_size=64, bits=4)
backend = row_matmul.simd_qmm_backend()
backend.prepare([(pw, s, b, 64, 4)])
x = mx.random.normal((M, K)).astype(mx.bfloat16)
# time backend(x, pw, s, b, 64, 4) against
# mx.quantized_matmul(x, pw, s, b, group_size=64, bits=4, transpose=True)Questions
- Is
simd_qmm.install()intentionally unused — superseded by therow_matmul+row_forwardrouting — or is a call site missing? Its docstring says "including serial calls", which reads as if it should be wired in. - If it were wired in, prefill would regress ~22% at 2,048 rows, so I assume it should stay unwired. Either way a comment on the function would help.
- Is the stock-MLX prefill path a deliberate choice for bit consistency?
family.py:96says "a fresh prompt and a resumed one get the same chunks and bits", which suggests yes. If so,simd_qmm.install's docstring is the only thing misleading.
Observed throughput (context, not a complaint)
Cold prefill on this box, --context 8192, unique prompts: 623 → 91 tok/s, 1,828 → 81, 2,132 → 82, 3,978 → 72, 5,602 → 68. That is 3.9–5.1 TFLOP/s against the 5.85 measured ceiling, i.e. 67–95% of achievable. Decode is bandwidth-bound: 14.4 GB/token ÷ 52 ms/row = 277 GB/s of the M2 Max's 400.
The recipe's 1,834 tok/s (DGX Spark / NVFP4) and 423 tok/s (M5 Pro, tensor units) aren't comparable to the M1–M4 row path, so no doc change needed there — but a one-line M1–M4 prefill figure would have saved me an hour of chasing it.
Possibly related: this is a follow-up to #91 (the simd_qmm threadgroup crash), same file.
Activity
christrade215 commentedon Sep 29, 2026
Follow-up: does a wider representation buy prefill speed? (motivated by #94, where widening 2-bit → 4-bit gained 44% on a Bonsai 2 model)
Same box (M2 Max, 32 GB, mlx 0.32.2), same shapes as the table above, mean of 10 timed reps:
gate/up — N=17408, K=5120
down — N=5120, K=17408
At prefill's chunk size (2,048 rows):
Memory, per the same shapes' packed bytes (0.0415 / 0.0830 / 0.1660 GiB for that one weight):
So the widening lever that #94 exploits is closed here: #94's model starts at 2-bit and widens to where a 4-bit checkpoint already sits, whereas moving 4-bit → bf16 doesn't fit. 4-bit → 8-bit would fit but buys ~1%.
That closes the question this issue left open — there's no cheaper-but-faster representation reachable from this box. The stock-MLX 4-bit prefill path at 67–95% of the measured 5.85 TFLOP/s ceiling looks like the right call.
Benchmark script
docs: triage notes for parked upstream issues (ashhart#85, ashhart#87, …
ashhart commentedon Sep 30, 2026
Thanks for tracing this so carefully, and for the timings, which are the kind we would have had to take on trust. You
were right that
install()had no callers: it was left over from before the row decoder, which callssimd_qmmdirectly for decode's 1 to 16 rows, where your table has it 1.33x faster than MLX's
quantized_matmul. Prefillstaying on
quantized_matmulis the right call by the same table (0.78x at 2,048 rows, 0.57x at 4,096), so nothingrouted through the patch either way, and in 0.6.0 the 67 lines that made it look that way are gone:
install(), itsQuantizedLinear.__call__patch,_first,enabledand_ORIG. Nothing changes at runtime, so no measurement wasneeded; the suites that cover that path passed before the deletion. Your bf16 figure is the useful follow-on: 8.26
TFLOP/s for
mx.matmulagainst 5.85 for the stock 4-bit path at the same shape. We would not answer that bydequantizing the 4-bit weights to bf16, because that rounds the weights differently from the quantized path and would
break a resumed prompt equalling a fresh one, so a faster prompt matmul has to keep the bits. Your timings are the
scoreboard for any attempt at it.