| description | How to synchronize Apple MLX ecosystem updates into SharpAI forks and triage SSD-streaming bugs |
|---|
This workflow documents the architecture for maintaining Apple MLX forks within the SharpAI repository ecosystem, executing upstream synchronization, and resolving bugs within the ssd_streamer custom extensions.
The mlx-server repository now cleanly references the upstream Swift layer SharpAI/mlx-swift via Swift Package Manager (SPM).
mlx-server (SharpAI/SwiftLM)
│
└── SPM Dependency: SharpAI/mlx-swift (The Swift wrapper wrapper)
├── .gitmodules
│ ├── submodules/mlx -> https://github.com/SharpAI/mlx (Branch: main)
│ └── submodules/mlx-c -> https://github.com/SharpAI/mlx-c (Branch: main)
Never bundle C++ source files directly into mlx-swift. All Apple core Engine updates and C-wrapper modifications MUST be executed in the SharpAI/mlx and SharpAI/mlx-c forks respectively.
When Apple releases new features to ml-explore/mlx or ml-explore/mlx-c, follow this systematic process to verify, integrate, and validate the changes before bringing them into the SharpAI ecosystem.
Before syncing, verify if Apple's upstream actually fulfills all your custom requirements (which informs whether you should safely drop your custom patches):
- Review Upstream Logging/Releases: Actively monitor the Apple MLX Releases page or the
maincommit history for mentions of "quantization", "streaming", "memory-mapped operations", or "out-of-core inference". - Examine Target C++ Kernels:
- Look primarily in
mlx/backend/metal/andmlx/core/. - Has upstream Apple added an equivalent to
moe_stream_op.cppnatively? - Do the Metal shaders in
mlx/backend/metal/kernels/natively introduce block execution / memory-mapped loading primitives similar to ourssd_streamer.mmandfence.airlogic?
- Look primarily in
- Check Exported C-APIs: Look at
mlx/c/ops.handmlx/c/fast.hinml-explore/mlx-c. If Apple has added official C-bindings for out-of-core tensor operations, you can securely begin stripping out the custom SharpAI C++ bridging codebase.
If Apple's features are highly beneficial (e.g., core Metal optimizations) but do not explicitly replace our SSD streaming, we need to pull their features while maintaining the SharpAI SSD kernels.
- Pull Upstream to SharpAI forks:
git clone https://github.com/SharpAI/mlx && cd mlx git remote add upstream https://github.com/ml-explore/mlx git fetch upstream # Rebase Apple's latest main directly under our custom SSD commits git rebase upstream/main # Resolve any merge conflicts specifically around `fast.cpp` or Make/CMake builds git push -f origin main
- Execute the identical rebasing process for
SharpAI/mlx-c, monitoringmlx_c/ops.cpp. - In
SharpAI/mlx-swift, update the submodule pointers to mount your freshly rebased commits:cd LocalPackages/mlx-swift git submodule update --remote --recursive git commit -am "chore: sync latest Apple MLX components and re-graft SSD patches" git push origin main
Do not deploy binary updates to the inference engine without executing the extreme validation matrix.
- Clean Re-Build: Always execute a destructive cache wipe before a Metal compilation test.
# In mlx-server framework rm -rf .build ./build.sh - Swift API Layer Verification: Run the test suites within your wrapper to certify that the Swift
->C->C++ bindings remain structurally unified.cd LocalPackages/mlx-swift swift test
- Extreme Context Benchmarking (The Harness):
- Run the dedicated
/run-benchmarkworkflow from the rootmlx-serverdirectory (utilizingrun_benchmark.shorprofile_runner.py). - Specifically target models invoking >32k token contexts. High prompt generation latency, GPU thrashing, or hard Out-of-Memory (OOM) faults directly indicate that the Metal barrier (
fence.air) orssd_streamer.mmbroke silently during the git rebase.
- Run the dedicated
The SSD streaming kernels introduce custom memory synchronization routines (ssd_streamer.h, ssd_streamer.mm) that interact with Apple's core MLX framework (mlx/core/moe_stream_op.cpp).
Triage Protocol:
- Crash in Metal Execution (
fence.air,moe_stream.metal): Identify if Apple's upstream Metal API (mlx/backend/metal/device.h) changed rendering assumptions. Navigate toSharpAI/mlxand patchmlx/backend/metal/ssd_streamer.mm. - C-API Mapping Errors (
fast.cpp,ops.cpp): Swift throws errors linking to underlying kernels. Navigate toSharpAI/mlx-cand ensuremlx/c/ops.cppcleanly wraps the updated arguments fromSharpAI/mlx'smoe_stream_op.h. - Memory Leaks/High Swap Usage: Typically arises if the
fence.airstreaming barrier lacks synchronization with the newly upstreamed Apple thread-pool executors.
Warning
The ultimate goal is to delete the SharpAI/mlx and SharpAI/mlx-c forks and point SharpAI/mlx-swift directly to ml-explore/mlx natively.
Indications for Dropping the Fork:
- Apple officially merges Turbo Quant framework into
ml-explore/mlx/fast/turbo_quant.hor equivalent upstream PR. - Apple natively supports out-of-core SSD context offloading (e.g., streaming inference blocks directly from Non-Volatile Memory to GPU) in
ml-explore/mlx/backend/metal/. - If Apple's
moe_stream_opnative implementations match or exceed the latency speedups provided by your customssd_streamer.mm.
If any of these conditions are met, simply rewrite SharpAI/mlx-swift/.gitmodules back to https://github.com/ml-explore/mlx and delete your Github forks!
As of April 2026, the following specific features exist ONLY in our custom forks. Knowing precisely what we added is the key to knowing exactly when we can revert to Apple's native upstream (ml-explore).
Compared to ml-explore/mlx:main
feat: custom ssd-streaming kernels and custom MLX I/O fast loaders- Added
moe_stream_opprimitives enabling SSD flash streaming (out-of-core execution).
- Added
fix(metal): align moe_stream_op add_temporary signature with latest apple upstream- Custom extensions needed maintaining against newer MLX memory-pool updates.
fix(metal): add default initialization loop for bound encoder contexts in async- Patched
device.cppso thread pool reassignments by Swift's async engine don't result in fatal runtime aborts due to missing context dictionaries.
- Patched
Compared to ml-explore/mlx-c:main
chore: rebase SharpAI custom ops onto latest Apple MLX-C upstream to fix fft/dequantize signaturesfix(ops): align c wrappers with mlx 0.30.0+ upstream signatures for dequantize, qqmm, and fftfix(fft): restore Shape type for fft methods n parameter&fix(fft): remove invalid norm from fftshift calls- Resolves signature drift and struct mismatches linking the new C++ API modifications down to Swift C headers.
Compared to ml-explore/mlx-swift:main
Restoration of missing MLX custom extensions including C-API and Swift bridge&Update custom C++ kernel patches for SSD Streaming- Recreated Swift integrations bridging into out-of-core functionality.
chore: isolate SharpAI custom MLX/MLX-C engines into dedicated GitHub forks- Submodule remotes internally pinned from
ml-exploretracking links toSharpAIecosystem forks.
- Submodule remotes internally pinned from
fix(build): bump cxxLanguageStandard to .gnucxx20 for Apple MLX upstream compatibility- Custom
Package.swiftoverride explicitly permitting C++20 standard since upstream didn't upgrade constraints simultaneously.
- Custom
fix(mlx): build steel_conv_3d C++ string for Cmlx target- Added missing header dependencies specifically isolated by recent upstream migrations.
fix(jit): update generated mlx c++ metal headers and fix fast.h signature to match fast.cpp- Recompiled Metal header string buffers internally inside
mlx-generatedensuringaffine_qmm_t_splitkand other functions are dynamically injected at runtime.
- Recompiled Metal header string buffers internally inside