swift-litert-lm
A Swift package for running Gemma 4 and other LiteRT-LM models on iPhone and Mac, with in-app download, Metal GPU inference, and an optional Apple Foundation Models backend on iOS 27.
View on GitHub ↗- Stars
- ★ 31
- Last commit
- 11 Nov 2026
- Maintenance
- Active
- Licence
- Apache-2.0
- Category
- On-device AI SDKs
- GitHub
- john-rocky/
swift-litert-lm
Overview
swift-litert-lm is a community Swift package by john-rocky that wraps Google's LiteRT-LM runtime. It is not affiliated with Google or Apple. The simplest route is LiteRTChat, which can download a model, check that the device has enough memory, and stream a chat on the Metal GPU, with text, image and audio on supported models. Video is handled as sampled frames.
A second path, FM mode, exposes LiteRTLanguageModel as a custom backend for Apple's Foundation Models API on iOS 27, including @Generable output, tool calling and image attachments. Audio and video are not available through that API. For earlier systems, the README points to a separate anylanguagemodel-litert-lm package that uses the listed AnyLanguageModel project.
This is a different runtime from the author's CoreML-LLM package, which targets the Neural Engine through Core ML. Fetching upstream LiteRT-LM as a SwiftPM git dependency would need git-lfs. This package avoids that by depending on official prebuilt xcframeworks and vendoring the thin Swift wrapper.
The package is licensed under the Apache-2.0 licence and includes software developed by Google LLC, as described in NOTICE. Each model keeps its own licence. The README gives a speed of about 88 tokens per second for Gemma 4 E2B on an iPhone 18 Pro once warm (5 Nov 2026, LiteRT-LM v0.19.0). That is the author's own measurement and has not been independently verified.
Features
- LiteRTChat with catalogue ids such as .gemma4_E2B, progress callbacks, streaming, and modality options for text, image and audio.
- In-app download of .litertlm files into Application Support (excluded from iCloud backup), or load from a local file or another Hugging Face repo.
- A memory check that refuses to load when the device has less than the documented minimum RAM, instead of letting iOS kill the app.
- LiteRTLanguageModel for Foundation Models sessions on the iOS 27 SDK.
- A sample SwiftUI app at Samples/LiteRTDemo, with a Foundation Models screen and a live tool-call demo.
- Version 0.3.1 runs LiteRT-LM v0.19.1; 0.3.0 runs v0.19.0.
Requirements
- Easy mode: iOS 16 or later, or macOS 13 or later.
- FM mode: the iOS 27 SDK.
- A physical iPhone or a Mac for Metal GPU inference. The iOS Simulator falls back to CPU.
- For Gemma 4 E2B, the README asks for at least 7 GB of RAM. The first download is about 2.6 GB from Hugging Face.
- No extra memory entitlement is required for the sample app, according to the README.
Install
In Xcode, add the package URL https://github.com/john-rocky/swift-litert-lm and select the LiteRTFoundation product, from version 0.3.1.
In a Package.swift, add .package(url: "https://github.com/john-rocky/swift-litert-lm", from: "0.3.1").
For the sample: cd Samples/LiteRTDemo, open LiteRTDemo.xcodeproj, set a development team, and run on a device.
Example
Create a LiteRTChat(.gemma4_E2B) session (the first launch downloads the model) and stream a prompt. For a photo, open the chat with modalities: .textImage and call respond with image data. On iOS 27, wrap the same model in LiteRTLanguageModel and pass it to LanguageModelSession.
Works with
Listed in
- github.com/john-rocky/swift-litert-lm
- github.com/john-rocky/swift-litert-lm/blob/main/README.md
- github.com/john-rocky/swift-litert-lm/blob/main/docs/verified-on-device.md
Read the code before you install anything. SwiftAgents doesn't review or endorse the tools listed here. Active: a commit in the last 90 days. Slowing: last commit within the past year. Stale: older than a year, or archived.
More in this category
apfel
Command-line tool, chat mode and local OpenAI-compatible server for the on-device model in Apple's FoundationModels framework. Needs macOS 26 and Apple silicon.
Argmax OSS Swift (WhisperKit)
Argmax's open-source on-device speech toolkit for Apple silicon, and the home of WhisperKit.
MLX Swift Examples
Example apps and code showing how to use MLX Swift.
SwiftAgents