Fine-Tuning SLMs for Multi-Step Tool Calling on iOS
The latest versions of iOS utilize Apple Intelligence and Gemini integration to handle complex tasks, but they heavily rely on cloud routing for heavy lifting. This requires an internet connection, introduces latency, and pushes data off-device.
100% Offline. No API keys. No cloud servers. No internet required. The goal: force complex, multi-step LLM reasoning entirely onto the iPhone's local A-series chip, guaranteeing zero latency and absolute user privacy.
Unlike massive LLMs (100B+ parameters) requiring data centers, SLMs operate under 3B parameters, small enough to run in mobile RAM.
Incredibly lightweight, pre-trained specifically by Google to understand JSON schemas and execute tool calls, rather than engaging in open chat.
Google's LiteRT-LM manages the actual lifecycle of the model on-device, wrapped in a custom Swift Actor to ensure thread-safe execution.
When the AI outputs JSON, LiteRT pauses inference, hands the data to our Swift ToolRegistry to run real iOS code, and feeds the results back in.
LiteRT is cross-platform. Using WebAssembly and WebGPU, we test our raw FunctionGemma model directly in a browser before moving to Xcode.
Base models are "jacks of all trades." We need a model trained specifically on our iOS application's custom JSON tool schemas.
The model must learn to stop talking, wait for the CategorizeTool to return the user's available lists, and only then fire the ReminderTool.
Swift expects strict JSON decoding. If the model adds conversational filler like "I can help with that: {json}", the app crashes.
Retraining 270 million parameters requires massive server farms. Instead, we use Parameter-Efficient Fine-Tuning (PEFT).
Using LoRA (Low-Rank Adaptation), we freeze the base model and only train a tiny, lightweight "adapter" layer.
(The same math used to teach Stable Diffusion specific art styles!)
.jsonl files matching the google/mobile-actions format.Executing the LoRA training loop locally on Apple Silicon (Mac GPU). Merging the adapter and exporting to a highly compressed .litertlm file.
We take our newly trained .litertlm file and drop it back into our WebGPU testing environment.
.litertlm file is bundled into the Xcode project.Thank you for exploring the mechanics of on-device fine-tuning.
Run the fine-tuned FunctionGemma model directly in your browser via WebGPU.
No cloud. No API key. No setup.
Open the chat panel →