Prerequisites
Set up Xcode properly on your Apple Silicon Mac before installing MLX.
1
Install Xcode
- Open the App Store
- Search for "Xcode" and install
- Wait for download completion (several GB)
2
Accept License
Open Xcode once to accept the initial license agreements.
3
Configure Command Line Tools
$ sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
Password: ********
$ sudo xcodebuild -license accept
License accepted
Build from Source
Once Xcode is configured, build MLX from source.
$ rm -rf build && mkdir build && cd build
$ cmake ..
-- The C compiler identification is AppleClang 15.0.0.15000040
-- The CXX compiler identification is AppleClang 15.0.0.15000040
-- Found Metal: /System/Library/Frameworks/Metal.framework
-- Configuring done
-- Build files have been written to: /Users/username/mlx/build
$ make -j8
[ 1%] Building CXX object CMakeFiles/mlx.dir/mlx/backend/metal/kernels.cpp.o
...
[100%] Built target metal_capture
Verify Installation
Test the build to ensure everything works correctly.
$ ./tests/tests
Running all tests.
....................
All tests passed!
$ ./examples/cpp/tutorial
array([[1, 1],
[1, 1]], dtype=float32)
Build Artifacts
The build process creates several important components:
Core Library
libmlx.a
- Main MLX static library
Example Programs
linear_regression
- Linear regression examplelogistic_regression
- Logistic regression exampletutorial
- Basic operations tutorialmetal_capture
- Metal performance profilingdistributed
- Distributed computing example
Test Suite
tests/tests
- Comprehensive test executable
System Configuration
Build Settings
CMAKE_BUILD_TYPE=Release
MLX_BUILD_TESTS=ON
MLX_BUILD_EXAMPLES=ON
MLX_BUILD_METAL=ON
MLX_BUILD_CPU=ON
System Requirements
- macOS 13.5 or later (Sonoma recommended)
- Python 3.9 or later
- Apple Silicon (M1/M2/M3/M4)
- 8GB RAM minimum (16GB+ recommended)
Key Features
- Unified Memory: Zero-copy CPU/GPU data sharing
- Lazy Evaluation: Compute-on-demand optimization
- Metal Integration: Native Apple GPU support
- Multi-Device: Seamless CPU/GPU execution
Usage Examples
Basic Python Usage
$ python3 -c "import mlx.core as mx; print(mx.zeros((2,2)))"
array([[0., 0.],
[0., 0.]])
Performance Profiling
$ MTL_CAPTURE_ENABLED=1 python3 your_script.py
Capturing Metal trace for analysis
Environment Variables
DEVICE=gpu|cpu
- Select compute deviceMTL_CAPTURE_ENABLED=1
- Enable Metal captureLOW_MEMORY=1
- Optimize for low memory systems
Testing Framework
Run All Tests
$ python scripts/run_tests.py
π Starting MLX Test Suite
β
All required dependencies found
π Running C++ tests...
π Running Python tests...
All tests completed successfully
Test Categories
- CPU Tests: Basic array operations and math functions
- GPU Tests: Metal-accelerated computations
- Distributed Tests: Multi-node operations
- Integration Tests: End-to-end workflows