diff --git a/mlx/backend/metal/jit_kernels.cpp b/mlx/backend/metal/jit_kernels.cpp index aad94eba1e..5cfeebd928 100644 --- a/mlx/backend/metal/jit_kernels.cpp +++ b/mlx/backend/metal/jit_kernels.cpp @@ -1417,22 +1417,37 @@ MTL::ComputePipelineState* get_steel_attention_nax_kernel( bool split_d) { const auto& lib_name = kernel_name; auto lib = d.get_library(lib_name, [&]() { + // attention_nax_dsplit has no BV parameter (its value head dim is BD), so + // it takes the same arguments as its instantiation in + // steel_attention_nax.metal. Passing bv shifts every later argument and + // the library fails to compile. + auto template_def = split_d ? get_template_definition( + lib_name, + "attention_nax_dsplit", + get_type_string(q.dtype()), + bq, + bk, + bd, + wm, + wn, + get_type_string(m.dtype())) + : get_template_definition( + lib_name, + "attention_nax", + get_type_string(q.dtype()), + bq, + bk, + bd, + bv, + wm, + wn, + get_type_string(m.dtype())); std::string kernel_source; concatenate( kernel_source, metal::utils(), metal::steel_attention_nax(), - get_template_definition( - lib_name, - split_d ? "attention_nax_dsplit" : "attention_nax", - get_type_string(q.dtype()), - bq, - bk, - bd, - bv, - wm, - wn, - get_type_string(m.dtype()))); + template_def); return kernel_source; }); return d.get_kernel(kernel_name, lib, hash_name, func_consts);