Skip to content

Merge upstream ml-explore/mlx-c main 57731b0 (2026-10-22) - #17

Merged
Gajesh2007 merged 19 commits into
mainfrom
sync/upstream-2026-10-22
Oct 23, 2026
Merged

Gajesh2007 merged 19 commits into
mainfrom
sync/upstream-2026-10-22

Conversation

@davidtai

@davidtai davidtai commented Oct 22, 2026 •

Copy link
Copy Markdown

Summary

This PR merges upstream ml-explore/mlx-c main at 57731b0 (2026-10-21, "bump to v0.32.4") into the fork. It is one signed merge commit. The previous merge-base was fba4470b.

Upstream commits brought in

Commit Title
57731b0 bump to v0.32.4 (ml-explore#140)
a341b49 version 0.7.0 (ml-explore#135)
ebc88f1 Implement missing stream functions (ml-explore#132)
2f8700a fix custom io reader/writer API (ml-explore#130)
c74db53 example-ops (ml-explore#121)
538ff9b Bind new_thread_unsafe_stream (ml-explore#122)
d4afaec Support MLX v0.32.2 (ml-explore#123)

Fork changes preserved

Fork change Status
Allocation-cap C API and core pin (#16) Kept
Explicit math modes for custom Metal kernels (#13) Kept
Mutable-input kernel declarations (#10) Kept
Allocator snapshots, footprint policy, buffer ownership (#8) Kept
Non-evaluating array identity (#7) Kept
mlx_thread_unsafe_{cpu,gpu}_stream_new (#3) Kept beside the upstream name (see below)
mlx_get_num_resources / mlx_get_resource_limit (#1) Kept
Forkdiff page, gate and pinned actions (#11, #12) Kept
SDPA call adapted to 0.32.2 (#5) Replaced by upstream ml-explore#123

Conflicts and resolutions

File Resolution
CMakeLists.txt Keep the fork FetchContent block on Layr-Labs/mlx. Upstream v0.32.4 tag is not used. Later commits move GIT_TAG to 83dbdb0414bb (see Downstream pins).
mlx/c/fast.cpp Take upstream. The SDPA binding now forwards the new bool force_fused C argument. The fork passed a fixed false and kept the old C signature. Upstream fast.h adds the argument, and upstream mlx-swift passes forceFused.
mlx/c/memory.h Keep both. The fork allocator API stays. Upstream mlx_get_array_buffer_size is added after it.
python/mlxhooks.py Keep both. The fork mlx_get_memory_snapshot hook stays. The upstream mlx_compile hook follows it.

Auto-merged overlap files (mlx/c/fast.h, mlx/c/memory.cpp, mlx/c/stream.cpp, mlx/c/stream.h) were read after the merge. Both sides are present in each.

Thread-unsafe stream symbols

Upstream ml-explore#122 adds mlx_stream_new_thread_unsafe(mlx_device dev). It calls the same core function, mlx::core::new_thread_unsafe_stream, as the fork functions mlx_thread_unsafe_cpu_stream_new(void) and mlx_thread_unsafe_gpu_stream_new(void). Both sets of names exist after this merge. Layr-Labs/mlx-swift Source/MLX/Stream.swift calls the fork names today. Upstream mlx-swift calls the upstream name. Remove the fork names when Layr-Labs/mlx-swift moves to the upstream name. fork.yaml records this.

Sections changed in fork.yaml

  • base.hash moves to 57731b00e8bed710e0750e7356da9f18f8eb3e20. The base comment now describes merges.
  • The SDPA bullet is removed from the "Fast" section. The section title changes to "Fast: mutable inputs and per-kernel math modes".
  • The "Stream" section names the upstream mlx_stream_new_thread_unsafe and the removal condition for the fork names.
  • No section is dropped. Every glob still matches a changed path.

FORKDIFF.md: the "Rebasing onto newer upstream" paragraph now describes the upstream merge procedure.

Downstream pins

  • CMakeLists.txt pins Layr-Labs/mlx at 83dbdb0414bb27e3d3ee7e19f68a210e42fda71b, the head of Merge upstream ml-explore/mlx main afc03c511 (2026-10-23) mlx#38 (branch sync/upstream-2026-10-22). It is the merge of upstream ml-explore/mlx c6abf0dbb (3c3750f4ed40), two commits that repair the quantized Metal kernels (e5b6550d5898), one commit that changes only fork C++ tests (780b57ea90cc), one commit that guards INT_MIN / -1 in the CPU SIMD floor_divide (dbf463fc93ca), one commit that computes the JACCL ring wire offsets in 64 bits after the CodeQL review (089acfe101d4), one commit that computes the vector SDPA layout check in 64 bits (4588237cdce4), a CI and test commit (aaec1b63bc96), one commit where CPU qqmm refuses a global scale (1f7e90633b8f), commits where CPU BLAS gemm calls clear C when beta is 0 (cb73247a1554), array::is_uniquely_referenced() (699649d38164), an async_eval that does not throw a stored stream task error (36f043ec3947), and 9 more upstream mlx commits through afc03c511 (83dbdb0414bb). It is PROVISIONAL until Merge upstream ml-explore/mlx main afc03c511 (2026-10-23) mlx#38 CI is green. If the final mlx head changes source files, a further commit moves GIT_TAG again.
  • Pin history on this branch: ad5966879ec5 (before the merge), then 3c3750f4ed40 (commit 45258f9fc268), then e5b6550d5898 (commit 17c0df0ed53a), then 780b57ea90cc (commit b1cc36e81bc5), then dbf463fc93ca (commit ef55d7c74095), then 089acfe101d4 (commit 9b45eb2ed2cf), then 4588237cdce4 (commit 3b55cf767a63), then 1f7e90633b8f (commit bcf75801c096), then cb73247a1554 (commit 447634588cee), then 699649d38164 (commit e1b98733df21), then 36f043ec3947 (commit c4d9f8052b63), then 83dbdb0414bb (commit cb19abf6945b). Do not pin 3c3750f4ed40: its quantized Metal kernels do not compile.
  • The old pin ad5966879ec5 has the same tree as Layr-Labs/mlx main (ad4745a2d6). ad4745a2d6 is the first parent of 3c3750f4ed40, so no fork core change is lost.
  • The Layr-Labs/mlx-swift sync PR will point its mlx-c gitlink at the head of THIS PR.
  • Merge order: Layr-Labs/mlx, then Layr-Labs/mlx-c, then Layr-Labs/mlx-swift, then Layr-Labs/mlx-swift-lm.
  • Merge with a MERGE COMMIT. Do not squash or rebase. A squash changes the sha that dependents pin, and they must then re-pin.

Test plan

  • python3 scripts/check_forkdiff.py --upstream-ref upstream/main passes locally: 21 changed files, 21 described.
  • CI forkdiff-check.yml ("fork.yaml describes the fork") passes on this PR.
  • CI CodeQL (actions, c-cpp, python) passes on this PR.
  • forkdiff-pages.yml runs only on a push to main. It runs after the merge.
  • This fork has no build job. The Layr-Labs/mlx-swift CI compiles this tree as the Cmlx submodule. That CI is the compile proof for this merge. It runs on the mlx-swift sync PR after its gitlink points at this head.
  • No build or test ran on a laptop.
  • Full box build on ai-server (compile and link only, no GPU tests) at 17c0df0ed53a, with FetchContent of Layr-Labs/mlx e5b6550d5898: BUILD_OK, 0 errors. The MLX core and mlx.metallib build, including the quantized Metal kernels. libmlxc.a builds from 27 sources. All 12 examples and metal_kernel_options_test link. All 1417 warnings are ld notes that the objects target macOS 26.6.2 and the link targets 26.0. There are no compiler warnings.
  • Later mlx commits (780b57ea90cc, dbf463fc93ca, 089acfe101d4, 4588237cdce4, aaec1b63bc96, 1f7e90633b8f, cb73247a1554) change MLX tests and CI, two CPU SIMD headers, the JACCL ring files, one line of the Metal SDPA, a qqmm check in mlx/ops.cpp, the CPU BLAS gemm call sites and fork.yaml. The mlx-c sources up to 447634588cee are the same as at 17c0df0ed53a.
  • An earlier box compile at 45258f9fc268 against 3c3750f4ed40 compiled all 27 mlx-c sources and stopped in the MLX core quantized Metal kernels. e5b6550d5898 fixes those kernels.

Checklist

This repository has no PR template. Checklist:

  • One signed merge commit and four signed pin commits. GitHub API reports all signatures verified.
  • Fork API additions kept. Upstream wins elsewhere. The fork SDPA copy that upstream absorbed is dropped.
  • fork.yaml and FORKDIFF.md updated. The forkdiff gate passes locally.
  • Core pin moved to the provisional Merge upstream ml-explore/mlx main afc03c511 (2026-10-23) mlx#38 head 83dbdb0414bb (commit cb19abf6945b).
  • Compile proof through Layr-Labs/mlx-swift CI (the box build above passes).

AI authorship

Claude Code (Claude Opus 5.5) did the merge, the conflict resolution, the fork.yaml edits and this description. A person must review it before merge.

🤖 Generated with Claude Code

Buffer uniqueness (commit e1b98733df21)

mlx_array_get_buffer_info set unique from is_donatable(). Upstream mlx 5dbe9991 (#4634) made is_donatable() also require that MLX owns the buffer, so a wrapped external buffer always read as not unique. The field means "no other array references this array or its data". mlx-swift-lm uses it for paged KV segments, checkpoint memory accounting and MTP state. unique now comes from array::is_uniquely_referenced() in Layr-Labs/mlx 699649d3. This is the one mlx-c source change since the merge.

andresy and others added 15 commits August 27, 2026 14:44
* bump to MLX v0.32.0

* fix generator (parser not supporting thread_local)

* overloads for mlx_astype

* regenerate

* fix const char* return assignement

* regenerate

* bump to MLX v0.32.1

* fix overloads to maintain backward-compatibility

* add support for mlx_compile_cache (std::weak_ptr<mlx::core::detail::CompileCache> aka CompileCacheWeakPtr)

* regenerate C files

* bump to MLX v0.32.2

* regenerate

* add missing mlx_compile_cache new/free functions

* fix mlx_string return type (again)

* add support for some missing overloads

* fix flip overloads
Streams are thread affine as of mlx 0.31.2: a stream's GPU command encoder
is registered in a thread_local map, so evaluating on a stream from a thread
other than the one that created it raises "There is no Stream(gpu, N) in
current thread."

mlx added `new_thread_unsafe_stream` for language bindings that do their own
locking (ml-explore/mlx#3578), but mlx-c does not expose it, so those bindings
have no way to reach it. mlx-swift currently carries a local C shim for this.

Requires mlx 0.32.0, so the pin moves from v0.31.2. The existing bindings
build and the examples pass unchanged against it.
* Add examples for ops added in 0.32.0

* fix examples

---------

Co-authored-by: Ronan Collobert <collobert@apple.com>
* prefer forward-declaration to avoid circular references

* support for missing stream functions

* cosmetics
Bring in upstream through 57731b0 (bump to v0.32.4): MLX 0.32.2 support,
new_thread_unsafe_stream binding, example-ops, custom io reader/writer fix,
missing stream functions, version 0.7.0 and the v0.32.4 bump.

Conflicts:
- CMakeLists.txt: keep the Layr-Labs/mlx FetchContent repository and pin.
- mlx/c/fast.cpp: take upstream force_fused parameter in the SDPA binding.
  This replaces the fork's hard-coded false (#5).
- mlx/c/memory.h: keep the fork allocator API and add upstream
  mlx_get_array_buffer_size.
- python/mlxhooks.py: keep the fork mlx_get_memory_snapshot hook and add
  the upstream mlx_compile hook.

fork.yaml: move base.hash to 57731b0, drop the SDPA bullet, record the
upstream mlx_stream_new_thread_unsafe name beside the fork stream names.
FORKDIFF.md: describe the upstream merge procedure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the FetchContent GIT_TAG from ad5966879ec5 to 3c3750f4ed40.
That commit merges upstream ml-explore/mlx main c6abf0dbb into
Layr-Labs/mlx main. Its parent on Layr-Labs/mlx main has the same tree
as ad5966879ec5, so no fork core change is lost. The new revision adds
the core functions that the upstream bindings call, for example
new_thread_local_stream and get_array_buffer_size.

GIT_REPOSITORY stays on Layr-Labs/mlx. fork.yaml describes the new pin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the FetchContent GIT_TAG from 3c3750f4ed40 to e5b6550d5898.
e5b6550d5898 is 3c3750f4ed40 plus two commits on the Layr-Labs/mlx
sync branch. They repair the merge in the quantized Metal kernels
(qmm_t_impl template parameters and the fp_gather_qmv_fast_tail
adjust_matrix_offsets call). At 3c3750f4ed40 quantized.metal and
fp_quantized.metal did not compile.

The pin stays provisional until the Layr-Labs/mlx sync PR is green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the FetchContent GIT_TAG from e5b6550d5898 to 780b57ea90cc, the
head of Layr-Labs/mlx#38. 780b57ea90cc adds one commit over
e5b6550d5898. It changes only tests/allocator_tests.cpp and
tests/gptoss_mxfp4_tests.cpp, so the core library sources are the same.

The pin stays provisional until Layr-Labs/mlx#38 CI is green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the FetchContent GIT_TAG from 780b57ea90cc to dbf463fc93ca, the
new head of Layr-Labs/mlx#38. dbf463fc93ca adds one commit over
780b57ea90cc. It changes the CPU SIMD headers base_simd.h and
accelerate_simd.h (guard INT_MIN / -1 in floor_divide) and fork.yaml.

The pin stays provisional until Layr-Labs/mlx#38 CI is green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Layr-Labs/mlx#38 moved from dbf463fc to 089acfe1. The new commit computes
the JACCL ring wire offsets in 64 bits (CodeQL review fix). It changes only
mlx/distributed/jaccl/lib/jaccl/ring.cpp, ring_impl.h and fork.yaml, so no
mlx-c source changes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Layr-Labs/mlx#38 moved from 089acfe1 to 4588237c. The new commit computes
the vector SDPA query layout check in 64 bits (CodeQL alert 29). It changes
only mlx/backend/metal/scaled_dot_product_attention.cpp and fork.yaml, so no
mlx-c source changes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Layr-Labs/mlx#38 moved from 4588237c through aaec1b63 (tests and CI only)
to 1f7e9063. The code change is in mlx/ops.cpp: qqmm raises "Global scale
is only supported on the GPU" on a CPU stream, because the CPU kernel has no
global-scale input and returned wrong results. No mlx-c source changes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
davidtai added a commit to Layr-Labs/mlx-swift that referenced this pull request Oct 23, 2026
Layr-Labs/mlx#38 moved to 1f7e9063: CPU qqmm now raises "Global scale is
only supported on the GPU" instead of returning wrong results, plus test and
CI changes. Layr-Labs/mlx-c#17 moved to bcf75801, which only moves its CMake
GIT_TAG to the same mlx commit. The change is in mlx/ops.cpp, which Cmlx
compiles directly, so no generated sources change.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Layr-Labs/mlx#38 moved from 1f7e9063 to cb73247a. The code change: every
CPU BLAS gemm call with beta 0 clears its output region first, because
Accelerate can read C even when beta is 0 and a reused buffer can hold NaN
(latent upstream bug). No mlx-c source changes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
davidtai added a commit to Layr-Labs/mlx-swift that referenced this pull request Oct 23, 2026
Layr-Labs/mlx#38 moved to cb73247a: every CPU BLAS gemm call with beta 0
clears its output region first, because Accelerate can read C even when
beta is 0 and a reused buffer can hold NaN (latent upstream bug; affects
CPU matmul, gather_mm, block-masked matmul and convolution). Layr-Labs/mlx-c#17
moved to 44763458, which only moves its CMake GIT_TAG to the same mlx commit.
The changed files are C++ sources that Cmlx compiles directly, so no generated
sources change.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
davidtai and others added 3 commits October 23, 2026 00:15
mlx_array_get_buffer_info set `unique` from is_donatable(). Since upstream
mlx 5dbe9991 (#4634), is_donatable() also requires that MLX owns the buffer,
so a wrapped external buffer always read as not unique. The field means "no
other array references this array or its data", and mlx-swift-lm relies on
that for paged KV segments, checkpoint memory accounting and MTP state.

Use array::is_uniquely_referenced() from Layr-Labs/mlx 699649d3 and pin the
core there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Layr-Labs/mlx#38 moved from 699649d3 to 36f043ec: async_eval no longer
throws an error that an earlier CPU stream task stored. It fixes an
upstream ordering race between #3742 and #4338, and synchronize still
raises the error. No mlx-c source changes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Layr-Labs/mlx#38 merged 9 more upstream ml-explore/mlx commits, through
afc03c511 (2026-10-23): large-offset gather/scatter and pad fixes, a ring
send/recv data race fix, mx.take negative indices, normal loc/scale shapes,
padding jvp/vjp, and wider affine qmv_wide row tiles. No mlx-c source changes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Gajesh2007
Gajesh2007 merged commit 1452a12 into main Oct 23, 2026
5 checks passed
@Gajesh2007
Gajesh2007 deleted the sync/upstream-2026-10-22 branch October 23, 2026 19:15
davidtai added a commit that referenced this pull request Oct 24, 2026
Restore the upstream sync history squashed by #17
jonathan308 added a commit that referenced this pull request Oct 26, 2026
Brings in mlx-c main at 3a06ddb (2026-10-24): the upstream ml-explore/mlx-c
sync to 57731b0 (#17, history restored by #18) and the core pin bump #19.

Conflicts and how they were resolved:
- CMakeLists.txt: the core pin stays at this branch's a1d75679 (the stack
  rule: the coordinator repins every layer to the merged core tips at the
  end). Main pins ff4bb35b. Main's new wrappers call core functions that
  a1d75679 does not have (for example gather_qmm with a global scale), so
  this commit builds only once the pin moves to a merged cluster core.
- fork.yaml: main's file with this branch's sections. The core pin
  paragraph keeps this branch's description of the cluster pin. The fast
  section title drops "the SDPA signature" as main's does (upstream binds
  the same signature now) and keeps "fenced inputs".

fast.h and fast.cpp merged without conflicts: main's 0.32.4 bindings beside
this branch's fenced-input constructor and prepared launches.

Tests (Ultra A):
- check_forkdiff.py --upstream-ref upstream/main: 29 changed files, all
  described, base 57731b0 is the merge-base.
- Built with examples and MLX_C_BUILD_TESTS=ON against the merged cluster
  core (Layr-Labs/mlx merge/41 ce21a37d: its non-JIT library, built from
  the merge tree, installed; the installed MLX package names jaccl::jaccl
  and needs gguflib without exporting them, so the local build supplied
  both): every example and the test built; ctest metal_kernel_options:
  1 of 1 passed.
- tests/standalone/run_startup_wait_tests.py --core <merged core>: PASS
  (refusals=17, no RDMA, no GPU).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants