Go bindings for Apple MLX β a high-performance machine learning framework designed for Apple Silicon.
Note: This is a hobby project and public release of v0.1.0. Expect problems, API changes, and occasional breakage between releases while the library is still maturing.
- π Native Apple Silicon Performance β Leverage Metal GPU acceleration for ML workloads
- π§ Go Ecosystem Integration β Build inference servers with Go's concurrency primitives
- π¦ Simple, Familiar API β NumPy-like operations with idiomatic Go patterns
- π§ ML-Ready Operations β Comprehensive support for transformers, attention mechanisms, and more
- β‘ Lazy Evaluation β Efficient computation graph optimization
- π― Early-Stage but Ambitious β Strong foundations, but still evolving quickly
package main
import (
mx "github.com/guptaaryan16/mlx_go/core"
)
func main() {
// Create arrays
a := mx.FromSlice([]float32{1, 2, 3, 4})
b := mx.FromSlice([]float32{5, 6, 7, 8})
// Operations are lazily evaluated
c := mx.Add(a, b)
d := mx.Multiply(c, c)
// Trigger computation
d.Eval()
d.PrintArray() // Output: [36, 64, 100, 144]
}MLX-Go now uses a one-time native install plus ordinary Go module usage.
darwin/arm64with Apple Silicon and Apple frameworkslinux/amd64with system BLAS/LAPACK and the usual C++ runtime libraries
go run github.com/guptaaryan16/mlx_go/cmd/mlxgo-install@v0.1.0The installer downloads the native MLX release asset for your platform, installs the headers and static libraries into the standard local prefix, verifies the installation, and prints the exact next-step commands.
On Linux, installing into /usr/local may require sudo.
go get github.com/guptaaryan16/mlx_go@v0.1.0Then import it in your application:
import mx "github.com/guptaaryan16/mlx_go/core"And build as usual:
go build ./...If you need a custom prefix or an unsupported environment, build and install the native MLX libraries from source:
git clone --recursive https://github.com/guptaaryan16/mlx_go
cd mlx_go
./scripts/install.shIf you are modifying csrc/mlx or csrc/mlx-c, build contributor-local native
artifacts and use the explicit vendor mode:
./scripts/build_local.sh
go test -tags mlx_vendor ./...For detailed installation instructions, see docs/installation.md.
- Array Creation:
Zeros,Ones,Eye,Arange,Linspace,FromSlice - Element-wise Math:
Add,Multiply,Exp,Log,Sqrt,Power,Sin,Cos,Tanh - Reductions:
Sum,Mean,Max,Min,Prod,Std,Var - Broadcasting: Automatic shape broadcasting following NumPy semantics
- Reshaping:
Reshape,Flatten,Squeeze,ExpandDims,Transpose - Indexing: Advanced NumPy-style slicing and indexing
- Activations:
ReLU,GELU,SiLU,Sigmoid,Softmax,LogSoftmax - Normalization:
RMSNorm,LayerNorm - Attention: Scaled Dot-Product Attention with causal masking support
- Position Encoding: Rotary Position Embeddings (RoPE)
- Layers:
Linear,Embedding,Dropout - Convolutions:
Conv1d,Conv2d(via C API)
- Decompositions: QR, SVD, LU, Cholesky, Eigendecomposition
- Solvers: Linear systems, triangular solvers
- Operations: Matrix multiplication, norms, inverse, pseudo-inverse, trace
- Distributions: Uniform, Normal, Truncated Normal, Gumbel, Laplace
- Sampling: Categorical, Permutation, Randint
- Seeding: Reproducible random number generation
| Resource | Description |
|---|---|
| Installation Guide | Installer flow, source fallback, troubleshooting |
| Usage Guide | Comprehensive API overview with examples |
| Examples | Working code samples for common tasks |
| API Reference | Full API documentation on pkg.go.dev |
Check out the examples/ directory for complete working examples:
- Linear Regression β Training a simple linear model
- Autograd Basics β Grad, ValueAndGrad, JVP, VJP, and Checkpoint walkthroughs
- Compiled Training β JIT-compiled linear regression training step
- BERT β Tiny BERT demo plus safetensors weight loading
- ResNet β Forward pass and optimizer-driven training loop
- Save/Load β Serializing and loading array data
More examples coming soon: LLaMA inference, custom layers, distributed serving.
MLX-Go includes a comprehensive benchmarking tool to compare performance against Python MLX:
cd benchmark
go build -o benchmark_tool .
./benchmark_tool --quickSee benchmark/README.md for details.
MLX-Go aims to bring production-grade machine learning capabilities to the Go ecosystem:
- Performance: Match or exceed Python MLX performance through efficient CGO usage
- Ergonomics: Provide an idiomatic Go API that feels natural to Go developers
- Completeness: Support the full range of MLX operations needed for inference and training
- Reliability: Maintain strong type safety and comprehensive error handling
Read more about the project vision in GOAL.md.
We welcome contributions! Please see CONTRIBUTING.md for guidelines on:
- Setting up your development environment
- Running tests and benchmarks
- Code style and best practices
- Submitting pull requests
- Core array operations and broadcasting
- Neural network primitives (layers, activations, attention)
- Linear algebra operations
- Comprehensive test coverage
- Training support (autograd, optimizers)
- Quantization (INT8, INT4 support)
- Model implementations (LLaMA, Whisper, CLIP)
- Distributed training support
- Performance optimizations (operation fusion, memory pooling)
This project is licensed under the MIT License - see the LICENSE file for details.
MLX-Go is built on top of Apple's MLX and MLX-C libraries.
- Apple's ML Explore team for creating MLX
- The Go community for excellent tooling and ecosystem
- I don't like to admit but Google's Antigravity helped me a lot for the project
Star this repo β if you find it useful! Contributions and feedback are always welcome.
