Foundation Models Custom Adapter Reference
Complete reference for the Adapter Training Toolkit (Python 3.11, build-time) and the SystemLanguageModel.Adapter runtime API (Swift, on-device) for training and loading custom adapters on top of Apple's on-device Foundation Models.
When to Use This Reference
Use this reference when:
- Setting up the Foundation Models Adapter Training Toolkit Python environment (Python 3.11, Apple silicon Mac ≥32 GB or Linux GPU)
- Authoring the training dataset JSONL (basic chat-turn schema or the tool-calling extension)
- Looking up
examples.train_adapter,examples.train_draft_model,examples.generate, orexport.export_fmadapterCLI signatures and hyperparameters - Looking up
SystemLanguageModel.Adapterinitializers, instance methods (compile()), and static lifecycle methods (removeObsoleteAdapters(),compatibleAdapterIdentifiers(name:),isCompatible(_:)) - Looking up
SystemLanguageModel.Adapter.AssetErrorcases - Wiring an adapter into a
LanguageModelSessionand composing it withSystemLanguageModel(adapter:guardrails:) - Configuring the
com.apple.developer.foundation-model-adapterdeployment entitlement - Mapping a system-model OS release to its matching toolkit version
Example Prompts
Questions developers ask that this reference answers:
- "What Python version does the adapter training toolkit require?"
- "What's the JSONL schema for adapter training data, and how do I add tool-calling examples?"
- "What are the CLI arguments for
examples.train_adapter?" - "What LoRA rank does the toolkit use, and is it tunable?"
- "How do I export a trained adapter, and what does the export folder do that I shouldn't modify?"
- "What's the runtime API for picking the right adapter variant on a device?"
- "What
AssetErrorcases should I handle when loading an adapter?" - "How do I request the
com.apple.developer.foundation-model-adapterentitlement?" - "How does an adapter trained on one OS version interact with a device running a later OS?"
What's Covered
- Toolkit setup — Hardware requirements (32 GB Apple silicon Mac OR Linux GPU), Python 3.11 (3.12/3.13 break the
coremltoolspin inexport/), Apple Developer Program gating, conda/venv environment, the sealedexport/folder (modifying it breaks runtime compatibility) - Dataset JSONL schema — basic chat-turn
{"messages": [{"role": ..., "content": ...}]}shape, and the tool-calling extension with requiredid/type: "function"/function.name/function.argumentsfields on assistant turns - Sample volume guidance — Apple's explicit table (100-1,000 for basic, 5,000+ for complex; "quality over quantity")
- Training CLI —
examples.train_adapterwith--train-data,--eval-data,--epochs,--learning-rate,--batch-size,--checkpoint-dir; LoRA rank-32 architecture (fixed by toolkit); target modules and trainable parameter ratio - Checkpoint discipline — retention conventions, run-config tagging, avoiding premature deletion
- Optional draft model —
examples.train_draft_modelfor speculative decoding; rate limit (3 compilations per app per day on non-macOS); caching implications - Evaluation —
examples.generateCLI; the four-axis eval requirement (quantitative + human grading + larger-model grading + safety); locale-specific eval groupings (English-US, English-outside-US, PFIGSCJK: Portuguese, French, Italian, German, Spanish, Chinese-Simplified, Japanese, Korean) - Export —
export.export_fmadapterwith--adapter-name(underscore-only per runtime regex/fmadapter-\w+-\w+/), output.fmadapterpackage shape - Entitlement flow —
com.apple.developer.foundation-model-adapter(Account Holder request via developer portal, deployment-only, not required for local training) - Runtime API —
SystemLanguageModel.Adapterstruct:init(name:),init(fileURL:),compile() async throws,removeObsoleteAdapters() throws,compatibleAdapterIdentifiers(name:) -> [String],isCompatible(_ assetPack: AssetPack) -> Bool; composition viaSystemLanguageModel(adapter:)/SystemLanguageModel(adapter:guardrails:) - AssetError cases —
.compatibleAdapterNotFound(_),.invalidAdapterName(_),.invalidAsset(_)withContextpayload anderrorDescription - Compatibility matrix — per-base-model-version pinning; system-model OS to toolkit version mapping; per-OS variant strategy (
fmadapter-{name}-base26_0,fmadapter-{name}-base26_1, etc.); install-base coverage decision table - End-to-end pattern — build-time CLI sequence (author dataset → train → train draft → eval → export → package for Background Assets) plus runtime Swift example wiring
removeObsoleteAdapters() → compatibleAdapterIdentifiers(name:) → ensureLocalAvailability → init(name:) → compile() → SystemLanguageModel(adapter:) → LanguageModelSession
Documentation Scope
This page documents the foundation-models-adapters-ref skill — the API reference half of the trio.
- For when to train a custom adapter (decision discipline, maintenance contract, pressure scenarios), see Foundation Models Adapters
- For failure modes (
compatibleAdapterNotFoundpost-OS-update, hyphen-in-adapter-name, tool calls silent from adapter, context-window over-consumption), see Foundation Models Adapters Diagnostics - For delivery API (
AssetPackManager,StoreDownloaderExtension, manifest schema), see Background Assets Reference - For base Foundation Models API (
LanguageModelSession,@Generable,Toolprotocol, streaming), see Foundation Models Reference