Example MLX Swift programs. The language model examples use models implemented in MLX Swift LM.
-
MNISTTrainer: An example that runs on both iOS and macOS that downloads MNIST training data and trains a LeNet.
-
LLMEval: An example that runs on both iOS and macOS that downloads an LLM and tokenizer from Hugging Face and generates text from a given prompt.
-
VLMEval: An example that runs on iOS, macOS and visionOS to download a VLM and tokenizer from Hugging Face and analyzes the given image and describe it in text.
-
MLXChatExample: An example chat app that runs on both iOS and macOS that supports LLMs and VLMs.
-
LoRATrainingExample: An example that runs on macOS that downloads an LLM and fine-tunes it using LoRA (Low-Rank Adaptation) with training data.
-
LinearModelTraining: An example that trains a simple linear model.
-
StableDiffusionExample: An example that runs on both iOS and macOS that downloads a stable diffusion model from Hugging Face and and generates an image from a given prompt.
-
llm-tool: A command line tool for generating text using a variety of LLMs available on the Hugging Face hub.
-
ExampleLLM: A command line tool using the simplified API to interact with LLMs.
-
image-tool: A command line tool for generating images using a stable diffusion model from Hugging Face.
-
mnist-tool: A command line tool for training a a LeNet on MNIST.
Important
MLXLMCommon, MLXLLM, MLXVLM and MLXEmbedders have moved to a new repository
containing only reusable libraries: mlx-swift-lm.
Previous URLs and tags will continue to work, but going forward all updates to these libraries will be done in the other repository. Previous tags are supported in the new repository.
Tip
Contributors that wish to edit both mlx-swift-examples and mlx-swift-lm can
use this technique in Xcode.
LLM and VLM implementations are available in MLX Swift LM:
- MLXLLMCommon -- common API for LLM and VLM
- MLXLLM -- large language model example implementations
- MLXVLM -- vision language model example implementations
- MLXEmbedders -- popular Encoders / Embedding models example implementations
MLX Swift Examples also contains a few reusable libraries that can be imported with this code in your Package.swift or by referencing the URL in Xcode:
.package(url: "https://github.com/ml-explore/mlx-swift-examples/", branch: "main"),Then add one or more libraries to the target as a dependency:
.target(
name: "YourTargetName",
dependencies: [
.product(name: "StableDiffusion", package: "mlx-libraries")
]),- StableDiffusion -- SDXL Turbo and Stable Diffusion model example implementations
- MLXMNIST -- MNIST implementation for all your digit recognition needs
The application and command line tool examples can be run from Xcode or from the command line:
./mlx-run llm-tool --prompt "swift programming language"
Note: mlx-run is a shell script that uses xcode command line tools to
locate the built binaries. It is equivalent to running from Xcode itself.
See also: