---
name: llm-lora-writing-style lesson 04
description: >-
  Agent recipe for lesson 04: train a PEFT writing-style LoRA on a Mac with MPS
  or CPU and review fixed sample prompts.
---
# Train a LoRA on a Mac

**Lesson id:** `04`  
**One-line goal:** Produce a writing-style LoRA checkpoint you can rebuild, with PEFT on MPS or CPU.

## On-device job

Your writing stays on the Mac. The adapter is a middle step. The device never hot-swaps it.

## Prerequisites

Lessons 01 through 03. Clean JSONL, pinned instruct base, chat template.

## Inputs

`data/clean/train.jsonl`, base revision, rank and step budget.

## Outputs and artifacts

`artifacts/writing-style-lora` with adapter weights, tokenizer, and manifest.

## Executable steps

1. Create the `uv` project before training.
2. Select `mps` if available, else `cpu`. Never CUDA.
3. Load the pinned base. Attach PEFT LoRA to the architecture's projection modules.
4. Train with the same chat template the export and app will use.
5. Save adapter, tokenizer, and manifest (`runtime_lora_swap: false`).
6. Generate review prompts on base and adapter.

## Constraints

Sketch, not a universal trainer. No quizzes, Mermaid, or em dashes.

## Failure modes

CUDA, wrong target modules, missing chat template, adapter treated as the product, memorized secrets.

## Key concepts

- PEFT LoRA trains on a frozen instruct LLM. The adapter is a middle step.
- Use the same chat template as lesson 03 throughout training.
- Review for voice, instruction following, meaning, and memorization.
- MPS preferred, CPU fallback, no CUDA.

## Takeaways

- Save adapter, tokenizer, and a manifest with base, revision, device, rank, and steps.
- Style gain that breaks helpfulness is a failed checkpoint.
- Drop memorized private sentences before export.

## Done when

Adapter directory and manifest exist. Device is MPS or CPU. Review samples exist. Adapter is not called the `.aimodel`.

**Human lesson:** [Train a LoRA on a Mac](04-train-lora-on-mac.html)
