Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ option(MLX_BUILD_METAL "Build metal backend" ON)
option(MLX_BUILD_CPU "Build cpu backend" ON)
option(MLX_BUILD_CUDA "Build cuda backend" OFF)
option(MLX_METAL_DEBUG "Enhance metal debug workflow" OFF)
option(MLX_DISABLE_NAX
"Skip the Metal-4 nax tensor GEMM/qmm/attention kernels even when the build environment otherwise qualifies (MLX_METAL_VERSION>=400 + SDK>=26.2). Lets downstream projects opt out of the nax codepath on hosts where the installed Metal toolchain miscompiles those kernels — e.g. macOS 26 metalfe-32023.x silently produces wrong matmul outputs for M>~8 rows. The existing else() branch of the metal-version/SDK gate already defines MLX_METAL_NO_NAX, so C++ dispatchers fall back automatically. Default OFF preserves current behaviour."
OFF)
option(MLX_ENABLE_X64_MAC "Enable building for x64 macOS" OFF)
option(MLX_BUILD_GGUF "Include support for GGUF format" ON)
option(MLX_BUILD_SAFETENSORS "Include support for safetensors format" ON)
Expand Down
6 changes: 5 additions & 1 deletion mlx/backend/metal/kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ if(NOT MLX_METAL_JIT)
build_kernel(steel/attn/kernels/steel_attention ${STEEL_ATTN_HEADERS})

if((MLX_METAL_VERSION GREATER_EQUAL 400) AND (MACOS_SDK_VERSION GREATER_EQUAL
26.2))
26.2) AND (NOT MLX_DISABLE_NAX))

build_kernel(steel/gemm/kernels/steel_gemm_fused_nax ${STEEL_NAX_HEADERS})
build_kernel(steel/gemm/kernels/steel_gemm_gather_nax ${STEEL_NAX_HEADERS})
Expand All @@ -172,6 +172,10 @@ if(NOT MLX_METAL_JIT)
${STEEL_NAX_ATTN_HEADERS})

else()
# Reached when (a) the toolchain doesn't qualify (METAL_VERSION<400 or
# SDK<26.2), or (b) MLX_DISABLE_NAX=ON. Either way the nax kernels
# aren't in the metallib; MLX_METAL_NO_NAX tells C++ dispatchers to
# take the non-nax codepath.
target_compile_definitions(mlx PRIVATE MLX_METAL_NO_NAX)
endif()

Expand Down