- What it is: A tiny AI model for iPhone, iPad and Mac that turns a request like "turn off Wi-Fi" into the actual device action, asking first before anything risky.
- Why it matters: Device control stays on the device, private, behind a safety check the model cannot skip.
- Key result: On familiar phrasing, my from-scratch model (~4.1M parameters) beats a fine-tuned Qwen2.5 model 120x its size: 67.2% vs 51.6% of tasks (43 vs 33 of 64, McNemar p = 0.013). On new phrasing that lead disappears: 32.7% vs 36.4% (18 vs 20 of 55, p = 0.82), a statistical tie. Unsafe actions: 0% for every model.
- What I did: Solo: model, tokenizer, training data, benchmark and Swift execution layer.
- Built with: Python, PyTorch, Hugging Face Transformers, LoRA, Swift/SwiftUI, App Intents, Core ML.
- Try it:
make test(no GPU or Apple hardware needed).
An on-device, agentic Small Language Model whose only job is device control on iPhone, iPad, and Mac. Not a chatbot: it maps a natural-language request to a structured OS command (or asks / declines) and takes the action — locally, privately, under a non-bypassable confirmation gate.
The centerpiece is DCSLM, a transformer built from scratch (our own architecture,
tokenizer, and weights trained from random init on our own data — see
docs/paper/provenance.md). Pretrained open models (Qwen2.5,
SmolLM2), specialized with LoRA, are kept as honest baselines.
| Model | Params | In-distribution (n=64) | Held-out phrasing (n=55) | UER |
|---|---|---|---|---|
| DCSLM (from scratch) | ~4.1M | 67.2% [55, 78] | 32.7% [20, 45] | 0% |
| Qwen2.5-0.5B fine-tuned | 494M | 51.6% [39, 64] | 36.4% [24, 49] | 0% |
| Qwen2.5-0.5B base | 494M | 29.7% [19, 41] | 27.3% [16, 40] | 0% |
Paired comparisons, DCSLM vs fine-tuned Qwen on the same tasks (exact McNemar):
| Split | DCSLM | Qwen-ft | Only DCSLM solved / only Qwen solved | p | Reading |
|---|---|---|---|---|---|
| In-distribution | 43 / 64 | 33 / 64 | 12 / 2 | 0.013 | DCSLM better |
| Held-out phrasing | 18 / 55 | 20 / 55 | 9 / 11 | 0.82 | tie |
The honest headline: the tiny from-scratch model beats the fine-tuned 120x-larger model on
phrasing like its training data, and that lead disappears on new phrasing, where the two are
statistically tied. DCSLM's own drop is real (67% to 33%, Fisher p < 0.001); the fine-tuned
Qwen's drop is not significant at this size (52% to 36%, p = 0.14), and the gap between the two
drops is not significant either. So pretraining looks like the source of robustness, but n=55
cannot confirm it. The confirmation gate holds regardless (unsafe-execution rate = 0% for
every model). Full analysis: docs/paper/results.md.
| Path | What |
|---|---|
scratch/ |
The from-scratch transformer (model, training, sampling). |
dcslm/ |
Device-control corpus generator + the eval backend adapter. |
finetune/ |
LoRA specialization of open bases (portable HF + MLX). |
bench/ |
DeviceControlBench: catalog, sandbox, checkers, harness, stats, tasks/ (seed) + tasks_ood/ (held-out). |
python/agentcore/ |
Portable agent loop, parser, tool registry, safety gate. |
apple/DeviceControlKit/ |
Swift runtime + App Intents / Shortcuts / Accessibility execution layer. |
apple/DeviceControlApp/ |
Minimal SwiftUI app (iOS/iPadOS/macOS). |
tools/ |
App Intents generator, Core ML export, contamination gate. |
results/ |
Run manifests + leaderboard. |
make test # agent-core + benchmark unit tests
make gold # gold-replay both splits (every task passes its own checker)
make contamination # train/test leakage gate (0 leaks)
# the from-scratch device SLM, end to end (CPU):
python -m dcslm.gen_corpus --n 40000 # build the corpus
python -m scratch.train --data dcslm/data/corpus.txt --out dcslm/out --iters 5000
python -m bench.harness --backend scratch --model dcslm/out/ckpt.pt # in-dist
python -m bench.harness --backend scratch --model dcslm/out/ckpt.pt --tasks-dir bench/tasks_ood
make summarize # aggregate results/ -> leaderboardOn a Mac: python tools/gen_appintents.py && swift test --package-path apple/DeviceControlKit,
python tools/export_coreml.py for the Core ML model, then open apple/DeviceControlApp in Xcode.
request → DCSLM → command DSL ("set_wifi|enabled=false ; set_brightness|level=30" / ASK / REFUSE)
→ agent loop → confirmation gate (safe/confirm/blocked)
→ per-OS recipe: Direct API → Shortcuts/App Intents → Accessibility → (unsupported)
The recipe is how iOS system toggles (no direct API) still work — via system Shortcuts actions.
One catalog.json drives the model's commands, the benchmark, and the App Intents (they can't drift).
Executable success (device state, not string match), bootstrap 95% CIs + McNemar, held-out OOD
split, a contamination gate, determinism + run manifests, and CI on every push
(unit tests, gold replay, leakage gate, Swift build/test). See
docs/paper/testing.md.
| Doc | Covers |
|---|---|
research-plan.md |
Contributions, RQs, statistics, ablations, threats. |
dcslm-architecture.md |
The from-scratch model + system design. |
benchmark-design.md |
DeviceControlBench spec + datasheet. |
eval-protocol.md · testing.md |
Metrics/stats; test methodology. |
results.md |
All findings (in-dist, OOD, fine-tune, cross-base). |
model-card.md · provenance.md |
Model card; what's from scratch. |
- OOD generalization gap (from-scratch model); small held-out set (n=55): the held-out
comparison is a tie, and the difference between the models' drops is not significant.
read_query= 0% by design. English-only. On-device execution controllers and Core ML export are validated by structure/CI but finalized on a Mac (they need Apple SDKs).