Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Swift API for MLX

License

NotificationsYou must be signed in to change notification settings

ml-explore/mlx-swift

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.

Examples

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.

Installation

TheMLX Swift package can be built and run from Xcode or SwiftPM. A CMake install is also provided.

More details are in thedocumentation.

Xcode

In Xcode you can addhttps://github.com/ml-explore/mlx-swift.git as a packagedependency and linkMLX,MLXNN,MLXOptimizers andMLXRandom as needed.

SwiftPM

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.

xcodebuild

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'

CMake

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

Contributing

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.

Versions

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.


[8]ページ先頭

©2009-2025 Movatter.jp