Skip to documentation

Frameworks

MLX Swift Examples

MLX Swift Examples Swift example code for MLX and MLXNN. @Metadata { @CallToAction( purpose: download, url: "https://github.com/ml explore/mlx swift examples/archive/refs/heads/main.zip") @PageKind(sampleCode) } Overview Examples using MLX

MLX Swift Examples

Swift example code for MLX and MLXNN.

@Metadata { @CallToAction( purpose: download, url: "https://github.com/ml-explore/mlx-swift-examples/archive/refs/heads/main.zip") @PageKind(sampleCode) }

Overview

Examples using MLX and MLXNN are available in mlx-swift-examples (example applications and tools) and mlx-swift-lm (implementations of various LLM and VLM model architectures). The examples include:

  • MNISTTrainer: An example that runs on both iOS and macOS that downloads MNIST training data and trains a LeNet.

  • 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 iOS and macOS that downloads an LLM and tokenizer from Hugging Face and generates text from a given prompt.

  • StableDiffusionExample: An example that runs on both iOS and macOS that downloads a stable diffusion model from Hugging Face 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.

and several more. Much of the code is also available as a SwiftPM package -- use this as a starting point to build your own applications.