# Agent brief: Training must give conversion a model it can use

- **Lesson id:** 06-training-owes-conversion
- **Goal:** Show how Fashion-MNIST choices, fixed shapes, class order, and portable CPU weights make conversion possible.
- **Prerequisites:** Complete 05; know the original ClothingCNN training recipe.
- **Inputs:** Fashion-MNIST, `ToTensor()`, `ClothingCNN`, Mac MPS or CPU, `clothing.pt`.
- **Outputs/artifacts:** Training-to-conversion obligation diagrams and device-safe weight-save sketch.
- **Concrete steps:**
  1. Tie `ToTensor()` to grayscale float32 0 to 1 input.
  2. Tie ClothingCNN to fixed `[1,1,28,28]` export shape.
  3. Train on MPS when available or CPU, never CUDA.
  4. Move to CPU, evaluate, and save `clothing.pt` before export.
  5. Preserve the ten-class Fashion-MNIST order through logits and UI.
- **Constraints:** Mac only; no CUDA; no separate-hobby framing; no Mermaid, quizzes, or em dashes.
- **Acceptance checks:** Device policy, weight portability, fixed shape, preprocessing, and class order are explicit; original training lesson is linked; brief link is present.
- **Human lesson:** [06-training-owes-conversion.html](06-training-owes-conversion.html)

## Environment setup

Use macOS with Python 3.11+ and `uv`:

```bash
curl -LsSf https://astral.sh/uv/install.sh | sh
mkdir -p clothing-coreai && cd clothing-coreai
uv init --python 3.11
uv venv
uv add torch torchvision coreai-torch
uv run python -c "import torch, torchvision; print(torch.__version__, torchvision.__version__); print('MPS:', torch.backends.mps.is_available())"
uv run python train.py
```

Run lesson scripts with `uv run`. Prefer MPS on Apple silicon, and use CPU as the fallback. Do not add CUDA.

## Key concepts

- Conversion asks questions training must answer: shape, class order, ops, and portable weights.
- Fashion-MNIST `ToTensor()` gives one grayscale channel, float32 0-1.
- Train on MPS when available, else CPU. No CUDA. Save CPU weights in `clothing.pt`.
- The ten output positions map to Fashion-MNIST order through training, conversion, and UI.

## Takeaways

- Move the model to CPU, call `eval()`, then save weights the export environment can load.
- Class order is part of the graph's meaning, not a SwiftUI decoration.
- Training preprocessing must match the app's float32 NCHW 0-1 tensor.
