Repository navigation
Description
Describe the bug
In JIT-enabled builds (MLX_METAL_JIT=ON), any quantized matrix–vector product that routes through qmv / qmv_fast aborts at runtime with a Metal front-end compile error: the host code passes 6 template arguments to [[kernel]] templates that declare 5 parameters.
Since #3961 ("Optimize large NVFP4 QMV on M5 Max", first released in v0.32.1), qmv() in mlx/backend/metal/quantized.cpp forwards results_per_simdgroup into the template definition:
auto kernel = get_quantized_kernel_wrapped(
d,
kname,
(fast ? "qmv_fast" : "qmv"),
mode,
type_string,
group_size,
bits,
B > 1,
global_scale.has_value(),
results_per_simdgroup); // <-- 6th template argbut the corresponding kernel templates still take 5 parameters — affine_qmv / affine_qmv_fast in mlx/backend/metal/kernels/quantized.h:
template <
typename T,
int group_size,
const int bits,
bool batched,
bool has_global_scale = false>
[[kernel]] void affine_qmv(...)and likewise fp_qmv / fp_qmv_fast in kernels/fp_quantized.h (the results_per_simdgroup parameter exists only on the inner qmv_impl, not on the [[kernel]] wrappers).
So the JIT path emits e.g.
template [[host_name("affine_qmv_float_gs_64_b_4_batch_0")]] [[kernel]]
decltype(affine_qmv<float, 64, 4, 0, 0, 4>) affine_qmv<float, 64, 4, 0, 0, 4>;
which fails to compile ("too many template arguments") and aborts the process on first use.
AOT builds are unaffected: get_quantized_kernel in nojit_kernels.cpp ignores template_def and resolves the kernel by name from the prebuilt metallib, which is why the default build and CI don't catch this.
Still present on main as of 2026-08-18.
To Reproduce
cmake -B build -DMLX_METAL_JIT=ON && cmake --build buildimport mlx.core as mx
w = mx.random.normal((256, 512)).astype(mx.float16)
wq, scales, biases = mx.quantize(w, group_size=64, bits=4)
x = mx.random.normal((1, 512)).astype(mx.float16) # M=1 -> qmv route
out = mx.quantized_matmul(x, wq, scales=scales, biases=biases,
transpose=True, group_size=64, bits=4)
mx.eval(out) # aborts: JIT compile error in affine_qmv instantiation(Observed originally through mlx-swift with a regenerated JIT preamble at core v0.32.1: first 4-bit affine matvec aborted with the affine_qmv<float, 64, 4, 0, 0, 4> instantiation error; switching that build to the no-JIT path confirmed the kernels themselves are fine.)
Expected behavior
JIT and AOT builds compile the same kernels; quantized matvec works under MLX_METAL_JIT=ON.
The straightforward fix seems to be adding int results_per_simdgroup = 4 as a trailing template parameter on the four [[kernel]] qmv wrappers (affine_qmv, affine_qmv_fast, fp_qmv, fp_qmv_fast) and threading it through to qmv_impl / qmv_fast_impl, so the host-side 6-argument instantiation is valid in both modes. Happy to open a PR if that direction sounds right.
Desktop
- OS Version: macOS 15.6 (also reproduced conceptually from source on
main) - Version: v0.32.1 (regression introduced by Optimize large NVFP4 QMV on M5 Max #3961; not present in v0.31.x)
Additional context
Found while maintaining an mlx-swift-based runtime that regenerates the JIT preamble from core v0.32.1. The nojit workaround is fine for us; filing so JIT users don't hit the same runtime abort.
Activity
fixes issue ml-explore#4350, and an adjacent likely copypasta bug in …
zcbenz commentedon Aug 24, 2026
Closed by #4372.