Skip to content
CAI
Software that uses CAICheck a score

huggingface/swift-transformers

66.3

Adequate · 1 October 2026

8.2k

lines of production code

Swift

primary language

2

measurements over time

CAI band scale
CAI trend line
CAI lens gauges

What this system is

This system is a Swift library that enables running Hugging Face language models on Apple platforms using Core ML. It provides a complete pipeline for downloading models from the Hub, tokenizing text with various algorithms, and performing text generation with configurable sampling strategies. The implementation focuses on high-performance inference and efficient JSON parsing while maintaining strict concurrency safety.

How it got here

2023 — CoreML inference and tokenizer implementation

9 changes.

This period focused on establishing the core infrastructure for on-device machine learning by introducing a Hub module for efficient model configuration loading and a comprehensive Swift tokenizer pipeline. It also implemented the foundational CoreML-backed inference engine for language models, enabling text generation with various sampling strategies and Safetensors weight support.

2025–2026 — CoreML generation control and testing

5 changes.

This period focused on enhancing CoreML-based text generation by introducing logits warpers for fine-grained control over output diversity, including temperature, top-K, top-P, and repetition penalty settings. The work was supported by comprehensive testing of the generation pipeline, weight loading mechanisms, and tokenization performance benchmarks, alongside a new CLI example for the Mistral 7B model.

Features

Initial implementation of the Swift tokenizer pipeline

This change introduces the core tokenization engine for the library, adding the foundational components required to process text into tokens. It includes the \Tokenizer\ protocol and factory for loading models from Hugging Face Hub configurations, as well as specific implementations for BPE, Unigram, and WordPiece tokenization algorithms. The update also brings in the full preprocessing and postprocessing stack, including normalizers (e.g., Bert, NFD/NFC), pre-tokenizers (e.g., Whitespace, Bert, Metaspace), decoders (e.g., ByteLevel, WordPiece), and post-processors (e.g., BertProcessing, RobertaProcessing). Additionally, it provides the \TokenLattice\ structure for Viterbi decoding used by Unigram models and utility extensions for string splitting.

Sources/Tokenizers · high confidence

Introduce CoreML-based language model inference with Safetensors weight loading

This change introduces a new CoreML-backed inference path for language models, available on macOS 15.0+, iOS 18.0+, tvOS 18.0+, visionOS 2.0+, and watchOS 11.0+. It adds a \LanguageModel\ class and \LanguageModelProtocol\ that wrap CoreML models, handling context length management, token prediction, and optional prebuilt tokenizer injection. The \LanguageModel.loadCompiled\ factory method automatically detects stateful KV-cache support and returns the appropriate implementation. Additionally, a \Weights\ struct is added to load model parameters from Safetensors files (with GGUF and MLX formats recognized but currently unsupported), enabling the use of pre-trained models converted to CoreML format.

Sources/Models · high confidence

Introduce CoreML-based text generation with configurable sampling strategies

The Sources/Generation module now provides a complete text generation pipeline for CoreML models, supporting both greedy decoding and multinomial sampling. Users can control generation behavior via GenerationConfig, which applies logit processors for temperature scaling, top-k, top-p, min-p, and repetition penalty. The implementation uses a CPU-based inverse CDF search for sampling to ensure correctness with vocabularies larger than 65,536 tokens, and supports streaming output via callbacks.

Sources/Generation · high confidence

Introduce Hub module with high-performance JSON parsing and configuration loading

The Hub module now provides a new entry point for interacting with the Hugging Face Hub, featuring a \Config\ structure for handling model and tokenizer settings and a \YYJSONParser\ that uses the yyjson library for significantly faster JSON parsing compared to Foundation's \JSONSerialization\. This change includes a \BinaryDistinctString\ type to preserve exact byte sequences without Unicode normalization, which is critical for tokenizer vocabularies, and adds built-in fallback configurations for GPT-2 and T5 tokenizers to ensure robust loading when explicit configuration files are missing.

Sources/Hub · high confidence

New Mistral 7B example and CLI for Core ML text generation

Users can now export the Mistral 7B Instruct v0.3 model to Core ML and generate text using a new command-line interface. The \Examples/Mistral7B\ directory provides a Python script to export the model with a stateful key/value cache for efficient inference, while the \transformers-cli\ tool allows running generation with configurable parameters such as temperature, top-k, top-p, min-p, and repetition penalty, supporting both greedy and sampling decoding modes.

Examples · high confidence

New logits warpers for controlled text generation

Added a new \LogitsWarper\ module in \Sources/Generation/LogitsWarper\ that introduces several \LogitsProcessor\ implementations for CoreML-based generation: \TemperatureLogitsWarper\ for scaling randomness, \TopKLogitsWarper\ and \TopPLogitsWarper\ for nucleus/top-k filtering, \MinPLogitsWarper\ for min-p probability filtering, and \RepetitionPenaltyLogitsProcessor\ to discourage repeated tokens. These processors can be chained via \LogitsProcessorList\ to modify the token probability distribution during generation, giving users finer control over output style and diversity.

Sources/Generation/LogitsWarper · high confidence

Behavioural changes

Swift 6.1 support with strict concurrency and Xet download trait

The package now requires Swift 6.1 and enables strict concurrency checking to improve safety. It introduces an opt-in 'Xet' package trait that allows users to enable fast, parallel downloads from the Hugging Face Hub via swift-xet; when this trait is not enabled, the Hub falls back to the default URLSession-based transport. The project also adopts swift-format for code linting and formatting, and updates the Jinja dependency to version 2.4.2.

(repo-wide) · high confidence

Test coverage

Added benchmark test suite for tokenization performance; Added test coverage for Hub configuration parsing and API interactions; Added test coverage for tokenizer components; Added tests for Weights safetensors loading; Added tests for text generation and logits processing; Removed placeholder test file in tokenizers-tests.

Dependencies

Swift 5.9 upgrade and new library dependencies

The package now requires Swift 5.9 and introduces several new dependencies to support expanded functionality: swift-jinja (2.4.2) for template processing, swift-huggingface (0.8.1) for hub interactions, swift-collections (1.0.0) for data structures, swift-crypto (3.0.0–4.x) for security, and yyjson (0.12.0) for faster JSON parsing. Additionally, the minimum platform versions are set to iOS 16 and macOS 13.

(dependencies) · high confidence

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Score

  • CAI 70 → 66 (-3.4)
  • Rubric changed (rubric-2026.09.11 → rubric-2026.09.18) — scores are not directly comparable.

Lenses

  • Code Health 92 → 92 (+0.2)
  • Architecture 100 → 96 (-4.1)
  • Maturity 58 → 58 (+0.2)
  • Readiness 65 → 67 (+2.6)
  • Security 90 → 94 (+3.9)
  • Performance 65 (new)

Resolved (3)

  • Dependency hygiene PARTLY measured — SwiftPM pinning read, dependency currency NOT established
  • Documentation: no installation or build instructions (README.md)
  • Hotspot: Sources/Tokenizers/BPETokenizer.swift (Sources/Tokenizers/BPETokenizer.swift)

New (10)

  • Coverage not measured — Swift suite
  • Dependency hygiene PARTLY measured — Python dependencies read, no exact pin to grade for currency
  • Duplicate error types in different namespaces. Tokenizers.TokenizerError and Models.TokenizerError both expose errorDescription. If these are distinct types, it forces callers to catch multiple error types for similar failures. If they are meant to be the same, they should be unified.
  • Duplicated block (5 lines × 2) (Sources/Tokenizers/Tokenizer.swift)
  • Inconsistent naming for type-safe accessors. get(or:) is used for optional retrieval with a default, while string() and string(or:) are used for direct value retrieval. The pattern is not uniform across types (e.g., integer(), boolean(), floating() exist, but get() also exists). This creates two different mental models for accessing the same underlying data.
  • Off the main sequence: Hub
  • Overloaded method with implicit default behavior. The two-argument version is redundant if the single-argument version has a sensible default (e.g., addSpecialTokens: true). This forces users to choose between explicitness and brevity without a clear benefit, and can lead to subtle bugs if the default changes.
  • Redundant configuration properties. Both maxLength and maxNewTokens control generation length limits. In most LLM libraries, these are mutually exclusive or one overrides the other, leading to confusion about which to use. maxLength usually implies total sequence length, while maxNewTokens implies generated tokens only.
  • TooManyMethods: HubApi (Sources/Hub/HubApi.swift)
  • UnicodeScalar.isCJKUnifiedIdeograph (cyclomatic 16) (Sources/Tokenizers/Normalizer.swift)

Changes since last survey

  • 1 commits — 1 feature/other, 0 fixes

By area

  • .github/workflows — 1 commit

Notable commits

  • change: Scope GITHUB_TOKEN permissions per job (#394)

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

Survey your own repository

huggingface/swift-transformers was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.

About this page

  • The score is its most recent published measurement, taken on 1 October 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit af520cfccbbdc2127a0b77a1547fa47b7cd1f8d8 — the exact code this score is about.
  • Scored under rubric-2026.09.18 — the same rubric and the same method as every other entry in this index.
  • Measured by watchdog.canine.dev using codehealth-analyzer preprod-e569280dd5e2.