The Apple fm CLI: Evaluating On-Device Foundation Model Adapters
The Apple fm CLI: Evaluating On-Device Foundation Model Adapters
Exploring the Apple fm CLI local model adapters workflow unlocks customized on-device machine learning without the latency or privacy compromises of cloud LLM routing. The fm command-line utility, bundled with Xcode and macOS developer tools, gives engineers direct terminal access to Apple Intelligence on-device Foundation Models.
Rather than fine-tuning full 3-billion-parameter model weights from scratch—which is computationally impractical on mobile hardware—the fm toolchain facilitates training lightweight Low-Rank Adaptation (LoRA) parameter matrices that plug dynamically into the shared system base model at runtime.
The Verdict
- LoRA adapters keep binary footprints under 50MB: Because the base Foundation Model lives in the operating system partition, app bundles only distribute the differential rank-decomposition matrices (adapters), saving hundreds of megabytes of user bandwidth.
- Dynamic in-memory switching: An iOS app can load and switch between multiple specialized adapters (e.g., a customer support adapter vs. a code generation adapter) in less than 30ms without unloading the base model weights.
- The Catastrophic Forgetting Risk: Training an adapter on narrow, highly repetitive domain JSON can degrade the base model’s ability to interpret general conversational prompts. Evaluation sets must benchmark both domain accuracy and general linguistic coherence.
- Workflow requirement: Quantization-aware training (QAT) is mandatory. An adapter trained against full 16-bit float weights will suffer severe perplexity degradation when loaded onto mobile devices running 4-bit quantized base models.
Training a Domain Adapter with the fm CLI
The fm utility accepts standardized JSON Lines (.jsonl) training corpora consisting of paired prompt-completion samples:
# 1. Validate dataset format and token boundaries
fm dataset validate --input ./training_data.jsonl --tokenizer apple-foundation-v2
# 2. Train a lightweight LoRA adapter on Apple Silicon
fm train \
--model apple-foundation-3b \
--train-data ./training_data.jsonl \
--output-adapter ./MedicalEntityExtractor.fmadapter \
--rank 16 \
--alpha 32 \
--learning-rate 2e-4 \
--epochs 3 \
--quantization int4
The resulting .fmadapter file is an optimized binary bundle containing the low-rank projection weights ready for embedding in an Xcode target.
Consuming Custom Adapters in Swift with Core AI
Once packaged into your app bundle, loading and applying the adapter requires only a few lines of Swift 6 code:
import CoreAI
import Foundation
public final class SpecializedInferenceSession: Sendable {
private let modelSession: LanguageModelSession
public init(adapterResourceName: String) throws {
guard let adapterURL = Bundle.main.url(
forResource: adapterResourceName,
withExtension: "fmadapter"
) else {
throw InferenceError.adapterNotFound(adapterResourceName)
}
// Configure session with dynamic LoRA adapter attachment
var config = LanguageModelSession.Configuration()
config.attachedAdapters = [
LanguageModelSession.Adapter(url: adapterURL, blendWeight: 1.0)
]
self.modelSession = try LanguageModelSession(configuration: config)
}
public func extractStructuredEntities(from clinicalNote: String) async throws -> String {
let prompt = """
[System: Extract clinical entities as strict JSON]
Note: \(clinicalNote)
"""
// Executes inference using the shared base model modulated by the local adapter
return try await modelSession.generateResponse(for: prompt)
}
}
enum InferenceError: Error {
case adapterNotFound(String)
}
Benchmarking Evaluation Metrics
Before deploying an adapter to production, benchmark using fm eval:
- Perplexity Delta: Ensure task-specific perplexity drops by at least 35% while baseline English language perplexity increases by no more than 3%.
- Inference Latency: Verify that attaching the adapter adds no more than 4% overhead to time-to-first-token (TTFT) metrics on physical devices.
Related Deep Dives
fm servein Production: Routing Between On-Device and Private Cloud Compute — production architectures for hybrid Apple Intelligence.- Core AI: On-Device Model Optimization and Quantization — quantization and memory management fundamentals.
- MLX on Apple Silicon: Local Machine Learning Architecture — training and running local ML models on macOS.
References & Documentation
- Apple Developer — Machine Learning Overview — foundation models and developer tools.
- Apple Developer Documentation — Core AI — official API specifications for on-device language models.
- Core ML Tools GitHub — tools for model conversion and quantization pipelines.