Skip to content

Commit 135a109

Browse files
authored
Bump MLX pin to v32.2 (pytorch#22495)
As titled
1 parent 5bcf795 commit 135a109

8 files changed

Lines changed: 85 additions & 195 deletions

File tree

‎.github/workflows/mlx.yml‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,37 @@ jobs:
7171
${CONDA_RUN} cmake --build cmake-out --target op_test_runner multi_thread_test_runner mlx_mutable_state_test mlx_sequence_cache_test mlx_cell_cache_test -j$(( $(sysctl -n hw.ncpu) - 1 ))
7272
echo "::endgroup::"
7373
74+
echo "::group::Check MLX artifact sizes"
75+
size_check_failed=0
76+
check_artifact_size() {
77+
local path="$1"
78+
local max_size="$2"
79+
local baseline_size="$3"
80+
81+
if [[ ! -f "${path}" ]]; then
82+
echo "::error file=${path}::Expected MLX artifact not found"
83+
size_check_failed=1
84+
return
85+
fi
86+
87+
local actual_size
88+
actual_size=$(wc -c < "${path}" | tr -d '[:space:]')
89+
echo "${path}: ${actual_size} bytes (baseline ${baseline_size}, limit ${max_size})"
90+
if (( actual_size > max_size )); then
91+
echo "::error file=${path}::MLX artifact is ${actual_size} bytes, exceeding the ${max_size}-byte limit (baseline ${baseline_size})"
92+
size_check_failed=1
93+
fi
94+
}
95+
96+
# Baselines recorded from the MLX v0.32.2 Release build on 2026-09-02.
97+
check_artifact_size cmake-out/backends/mlx/libmlxdelegate.a 5000000 4159552
98+
check_artifact_size cmake-out/backends/mlx/mlx/libmlx.a 14000000 11458544
99+
check_artifact_size cmake-out/backends/mlx/mlx/mlx/backend/metal/kernels/mlx.metallib 2000000 1460840
100+
echo "::endgroup::"
101+
if (( size_check_failed )); then
102+
exit 1
103+
fi
104+
74105
echo "::group::Run mutable-state (multi-session) unit test"
75106
./cmake-out/backends/mlx/test/mlx_mutable_state_test
76107
echo "::endgroup::"

‎backends/mlx/CMakeLists.txt‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ endif()
167167
# with add_subdirectory would drop its whole project into ExecuTorch's
168168
# target/option namespace, which collides with shared deps MLX fetches (e.g.
169169
# nlohmann_json) and leaks MLX's MLX_BUILD_* options into our cache. The
170-
# isolated scope runs MLX's FetchContent in its own namespace, so no collision
171-
# and no submodule patching are needed.
170+
# isolated scope runs MLX's FetchContent in its own namespace, so dependency
171+
# collisions do not require patching. The platform packaging patches below are
172+
# still applied before the external configure step.
172173
include(ExternalProject)
173174

174175
set(_mlx_binary_dir ${CMAKE_CURRENT_BINARY_DIR}/mlx)
@@ -185,11 +186,9 @@ message(
185186
# mismatch after an MLX bump fails loudly rather than silently no-op'ing. See
186187
# each patch file under patches/ for its rationale.
187188
set(_mlx_patches
188-
${CMAKE_CURRENT_SOURCE_DIR}/patches/mlx_nax_jit_sdk_gate.patch
189-
${CMAKE_CURRENT_SOURCE_DIR}/patches/mlx_qmm_splitk_bk_align.patch
190-
${CMAKE_CURRENT_SOURCE_DIR}/patches/mlx_gather_mm_rhs_lda.patch
191189
${CMAKE_CURRENT_SOURCE_DIR}/patches/mlx_metal_sdk_per_platform.patch
192190
${CMAKE_CURRENT_SOURCE_DIR}/patches/mlx_swiftpm_metallib_name.patch
191+
${CMAKE_CURRENT_SOURCE_DIR}/patches/mlx_metal_remove_addrspace_compat.patch
193192
)
194193
# In a framework build the delegate is static, so MLX cannot find a colocated
195194
# metallib and instead loads one from a SwiftPM resource bundle. SWIFTPM_BUNDLE

‎backends/mlx/patches/mlx_gather_mm_rhs_lda.patch‎

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Keep Steel integral constants compatible with older Metal frontends.
2+
3+
MLX supports macOS 14 and selects Metal language 3.1 there. The Metal 4.1
4+
address-space fix uses metal::remove_addrspace_t, but that trait is unavailable
5+
in the Xcode 15.4 Metal standard library. Because integral_constant.h is embedded
6+
in runtime-JIT sources, this prevents kernels from compiling on that supported
7+
toolchain.
8+
9+
Use remove_addrspace_t on Metal 4.1+, where explicit thread qualifiers make it
10+
necessary and the trait is available. For older language versions, preserve the
11+
previous decltype behavior with an identity alias.
12+
13+
Upstream candidate; carried locally until MLX includes the compatibility fix.
14+
15+
diff --git a/mlx/backend/metal/kernels/steel/utils/integral_constant.h b/mlx/backend/metal/kernels/steel/utils/integral_constant.h
16+
index 2f153f48..97022416 100644
17+
--- a/mlx/backend/metal/kernels/steel/utils/integral_constant.h
18+
+++ b/mlx/backend/metal/kernels/steel/utils/integral_constant.h
19+
@@ -47,11 +47,19 @@ using Int = integral_constant<int, val>;
20+
// Binary Operators on Integral constants
21+
///////////////////////////////////////////////////////////////////////////////
22+
23+
+#if __METAL_VERSION__ >= 410
24+
+template <typename T>
25+
+using remove_addrspace_t = metal::remove_addrspace_t<T>;
26+
+#else
27+
+template <typename T>
28+
+using remove_addrspace_t = T;
29+
+#endif
30+
+
31+
#define integral_const_binop(__op__, __operator__) \
32+
template <typename T, T tv, typename U, U uv> \
33+
METAL_FUNC constexpr auto __operator__( \
34+
integral_constant<T, tv>, integral_constant<U, uv>) { \
35+
constexpr auto res = tv __op__ uv; \
36+
- using res_t = metal::remove_addrspace_t<decltype(res)>; \
37+
+ using res_t = remove_addrspace_t<decltype(res)>; \
38+
return integral_constant<res_t, res>{}; \
39+
}

‎backends/mlx/patches/mlx_nax_jit_sdk_gate.patch‎

Lines changed: 0 additions & 112 deletions
This file was deleted.

‎backends/mlx/patches/mlx_qmm_splitk_bk_align.patch‎

Lines changed: 0 additions & 42 deletions
This file was deleted.

‎backends/mlx/runtime/MLXInterpreter.h‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,15 @@ inline void exec_sdpa(const SdpaNode& n, ExecutionState& st, StreamOrDevice s) {
293293
}
294294

295295
array out = fast::scaled_dot_product_attention(
296-
Q, K, V, static_cast<float>(n.scale), mask_mode, mask_arr, sinks, s);
296+
Q,
297+
K,
298+
V,
299+
static_cast<float>(n.scale),
300+
mask_mode,
301+
mask_arr,
302+
sinks,
303+
false,
304+
s);
297305
st.set_tensor(n.out, std::move(out));
298306
}
299307

@@ -382,6 +390,7 @@ inline void exec_update_and_attend(
382390
mask_mode,
383391
spec.mask,
384392
std::nullopt,
393+
false,
385394
s);
386395
// Honor the op's output-dtype contract (unset -> SDPA's native output).
387396
if (n.out_dtype) {

‎backends/mlx/third-party/mlx‎

Submodule mlx updated 367 files

0 commit comments

Comments
 (0)