- Notifications
You must be signed in to change notification settings - Fork103
ml-explore/mlx-swift
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Installation |Documentation |Examples
MLX Swift is a Swift API forMLX.
MLX is an array framework for machine learning on Apple silicon. MLX Swiftexpands MLX to the Swift language, making research and experimentation easieron Apple silicon.
MLX Swift hasmanyexamples,including:
MNISTTrainer: An example that runs onboth iOS and macOS that downloads MNIST training data and trains aLeNet.
MLXChatExample: An example chat app that runs on both iOS and macOS that supports LLMs and VLMs.
LLMEval: A simple example that runs on both iOSand macOS that downloads an LLM and tokenizer from Hugging Face andgenerates text from a given prompt.
StableDiffusionExample: Anexample that runs on both iOS and macOS that downloads a stable diffusion modelfrom Hugging Face and generates an image from a given prompt.
llm-tool: A command line tool for generating textusing a variety of LLMs available on the Hugging Face hub.
TheMLX Swift Examples repocontains the complete code and documentation for these examples, includingguidelines on porting modelsfrom MLX Python.
TheMLX
Swift package can be built and run from Xcode or SwiftPM. A CMake install is also provided.
More details are in thedocumentation.
In Xcode you can addhttps://github.com/ml-explore/mlx-swift.git
as a packagedependency and linkMLX
,MLXNN
,MLXOptimizers
andMLXRandom
as needed.
To useMLX
with SwiftPM you can add this to yourPackage.swift
:
dependencies:[.package(url:"https://github.com/ml-explore/mlx-swift", from:"0.10.0")]
and add the libraries as dependencies:
dependencies:[.product(name:"MLX",package:"mlx-swift"),.product(name:"MLXNN",package:"mlx-swift"),.product(name:"MLXOptimizers",package:"mlx-swift")]
Note
SwiftPM (command line) cannot build the Metal shaders so the ultimate build has to be donevia Xcode.
AlthoughSwiftPM
(command line) cannot build the Metal shaders,xcodebuild
can andit can be used to do command line builds:
# build and run testsxcodebuild test -scheme mlx-swift-Package -destination 'platform=OS X'# build Tutorialxcodebuild build -scheme Tutorial -destination 'platform=OS X'
Building with CMake requires both CMake and Ninja to be installed. You can dothis withHomebrew:
brew install cmakebrew install ninja
With CMake:
mkdir buildcd buildcmake .. -G Ninjaninja./example
Check out thecontribution guidelines for more informationon contributing to MLX. See thedocs for moreinformation on building from source, and running tests.
We are grateful for all ofourcontributors. If you contributeto MLX Swift and wish to be acknowledged, please add your name to the list in yourpull request.
MLX Swift was initially developed by David Koski and Ronan Collobert, and isnow maintained by David Koski. MLX Swift is built on top ofMLX, which was initially developed withequal contribution by Awni Hannun, Jagrit Digani, Angelos Katharopoulos, andRonan Collobert.
SeeReleases. Generally the MLX Swift version number corresponds to the same version number inMLX. Release notes indicate specifics.
All capabilities in MLX (Python) should be available in MLX Swift. If you encounter any that are missing please file an issue or feel free to submit a PR.
About
Swift API for MLX
Topics
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.