huggingface/swift-transformers

Swift Package to implement a transformers-like API in Swift

What it solves

swift-transformers provides a native, idiomatic way for Swift developers to integrate Hugging Face language models into their applications. It bridges the gap between the popular Python-based transformers ecosystem and the Swift/Apple ecosystem, simplifying tasks like tokenization, model downloading, and interaction with on-device models.

How it works

The library offers a set of Swift modules that mirror the functionality of the Python transformers library. It includes a Tokenizers module for processing text, a Hub module for downloading models from the Hugging Face Hub with built-in progress tracking and error handling, and Models/Generation modules that provide utilities for running models via Apple's CoreML framework. It supports modern Swift features like async/await and can be integrated into projects via Swift Package Manager.

Who it’s for

This project is for iOS, macOS, and visionOS developers who want to build on-device AI applications using Hugging Face models, specifically those looking to leverage CoreML for performance.

Highlights

  • Familiar API for those experienced with the Python transformers library.
  • Native support for tokenization and chat templating, including tool-calling formats.
  • Robust model downloading from the Hugging Face Hub with progress reporting and optional high-performance transport via Xet.
  • Utilities for loading and running compiled CoreML models locally.
  • Compatible with Swift Package Manager for easy project integration.

Related

  • Dispatch
  • Dispatch
  • Dispatch
  • Project
  • Project