This repository contains the Swift package for LiteRT, Google's runtime for on-device machine learning, on iOS and macOS. It provides two modules:
LiteRT: a type-safe Swift wrapper over the LiteRT C API for loading, compiling and running models with hardware acceleration (CPU, GPU, NPU). Supports iOS and macOS.TensorFlowLite: the legacy TensorFlow Lite Swift API (Interpreter,SignatureRunner). Supports iOS.
The Swift sources are developed in the
LiteRT repository
and mirrored here, so that Swift Package Manager only has to clone this small
repository. The native runtimes are prebuilt .xcframework archives published
with each LiteRT release,
downloaded on demand and verified by checksum.
- Xcode version 15.0 or later
- An app targeting iOS 15 or later, or macOS 12 or later
- An Apple silicon Mac to run in the iOS Simulator, as the Simulator slices are arm64 only
-
Follow the instructions for adding package dependencies to your app in Xcode.
-
In the search field of the package dialog, enter this GitHub repository:
https://github.com/google-ai-edge/LiteRT-Swift -
Select the version of LiteRT that you want to use. The package versions follow the LiteRT releases. For new projects, we recommend specifying the latest version and using the Up to Next Major Version dependency rule.
-
Choose the products to add to your app target:
Product Contents Platforms LiteRTLiteRTSwift module; SwiftPM picks the linkageiOS, macOS LiteRT_staticLiteRTwith the Swift wrapper linked staticallyiOS, macOS LiteRT_dynamicLiteRTwith the Swift wrapper linked dynamicallyiOS, macOS LiteRtMetalAcceleratorPrebuilt Metal GPU accelerator, as a dynamic framework iOS, macOS CLiteRT_staticStatic LiteRT C API for C and Objective-C, module CLiteRT_staticiOS TensorFlowLiteTensorFlowLiteSwift module, without the Core ML and Metal delegatesiOS Most apps add
LiteRTand, to run models on the GPU,LiteRtMetalAccelerator. -
Add your
.tflitemodel to the app target, so that it is copied into the app bundle, andimport LiteRTin your Swift code.
See the
iOS image segmentation app
in the litert-samples
repository, which uses the LiteRT and LiteRtMetalAccelerator products and
lets you switch between the CPU and GPU backends.
Documentation for LiteRT is available on ai.google.dev/edge/litert. The LiteRT Swift README describes the Swift API, has a usage example, and explains how the package is built and released.
The sources in this repository are mirrored from the LiteRT repository. See the Contributing guide before opening a pull request.
For issues with LiteRT, including this package, file an issue on the LiteRT issue tracker.
This repository adheres to semantic versioning to indicate when backwards-incompatible changes are introduced. Each version tag corresponds to the LiteRT release of the same version.
This project is dedicated to fostering an open and welcoming environment. Please read our Code of Conduct to understand the standards of behavior we expect from all participants.
To report a security issue, follow SECURITY.md. Eligibility for the Google Open Source Software Vulnerability Rewards Program is determined by the Google Open Source Software Vulnerability Reward Program Rules.
LiteRT is licensed under the Apache 2.0 License.