Why this matters on the device
Your drafts are not a public dataset. Keep your writing on a Mac you control. Then ship a baked .aimodel. The model file is stored on the phone. Chat works without a network. The writing style does not need a vendor adapter in the cloud. Speed is local. If you delete your writing after export, the app still runs, because the style is inside the model file.
That is also the privacy rule. The baked model can still repeat phrases it memorized. Treat the export as sensitive. Do not upload it to a random host to "try a LoRA slot."
coreai.llm.export, or with torch.export plus coreai-torch. Keep the tokenizer sidecar. The device loads one ordinary language model.The steps, one box at a time
Start with writing you own.
Training writes a small LoRA. The instruct base stays frozen. That means the base weights do not change.
Merge bakes the ranks into the base weights. After that you have one ordinary instruct model.
Export writes the Core AI file and the tokenizer files that define its token ids.
The app loads that pair and chats offline. It does not download an adapter.
Adapter versus full fine-tune
A full fine-tune rewrites many weights and takes a lot of disk space. LoRA adds a smaller trainable path to a few layers. That makes experiments cheap to compare. It does not make the adapter a Core AI runtime feature. After you pick a checkpoint, you still merge.
Style is rhythm, how direct you sound, the words you pick, and the shape of an answer. It does not mean the model knows your calendar. Keep facts, retrieval, and writing style as separate questions. The sibling course, Diffusion LoRA to Core AI on device, is the same method for images.
Worked path for this map lesson
Set up the Mac project before any later training command. Use Python 3.11 or newer. Use uv for the environment. Prefer MPS. Use CPU if MPS is missing. Do not use CUDA.
curl -LsSf https://astral.sh/uv/install.sh | sh
mkdir -p writing-style-lora && cd writing-style-lora
uv init --python 3.11
uv venv
uv add torch torchvision transformers peft datasets accelerate safetensors coreai-torch
uv run python -c "import torch; print(torch.__version__); print('MPS:', torch.backends.mps.is_available())"
uv run coreai.llm.export --help
Write the contract you will not break later.
{
"goal": "writing_style",
"base": "qwen3-0.6b",
"success": "Short rewrite requests come back in my usual cadence without inventing private facts.",
"runtime_lora_swap": false,
"keep_corpus_local": true
}
Failure modes
- Treating LoRA as a hot-swap file for Core AI. There is no documented API for that. Bake first.
- Asking the adapter to store secrets as knowledge. Style training will still leak them if they sit in your writing.
- Skipping the tokenizer in this map. Token ids are part of the contract. The sidecar ships with the model.
- Assuming CUDA later. This course stays on MPS or CPU.
Done when
- You can say the five-box chain without adding a runtime swap.
- The
uvproject exists and the MPS check ran. - The contract sets
runtime_lora_swap: falseandkeep_corpus_local: true.
Keep learning
PyTorch to Core AI in Xcode · From the metal to the model · Core AI models, typed · Model architectures in plain English · Diffusion LoRA to Core AI on device
Key concepts
- The chain is your writing, LoRA, merged instruct LLM,
.aimodelplus tokenizer, offline chat. - Style is rhythm, directness, word choice, and answer shape. It is not facts.
- A LoRA still needs merge for Core AI. There is no documented runtime adapter.
- A baked model can memorize phrases. Treat the export as sensitive.
Takeaways
- The contract sets
runtime_lora_swap: falseand keeps the corpus local. - The device loads one ordinary language model, not a live adapter.
- The tokenizer sidecar is required.