# Agent brief: Export ClothingCNN for LiteRT

- **Lesson id:** 03
- **Goal:** Convert CPU PyTorch weights into `clothing.tflite` with the official LiteRT Torch path.
- **Prerequisites:** `clothing.pt`, model definition, Linux host, [human lesson](03-export-to-litert.html).
- **Inputs:** CPU weights and Python 3.11 Linux `uv` environment.
- **Outputs/artifacts:** Non-empty `clothing.tflite` with one NCHW float32 input and ten logits.

## Steps

1. Run `uv init --python 3.11`, `uv venv`, and `uv add torch torchvision litert-torch` on Linux.
2. Reload `clothing.pt` into the exact ClothingCNN and call `model.eval()`.
3. Set `example = (torch.zeros(1,1,28,28,dtype=torch.float32),)`.
4. Call `litert_torch.convert(model, example)` and `edge_model.export("clothing.tflite")`.
5. Check the file exists and copy it to `app/src/main/assets/clothing.tflite`.

## Constraints

Use only this PyTorch → LiteRT Torch → `.tflite` path. Keep NCHW. Do not invent ONNX or a Mac converter fallback. No CUDA requirement. Convert on Linux. The official LiteRT Torch converter currently says it supports Linux.

## Key concepts

- Convert on Linux with Python 3.11 and `uv add torch torchvision litert-torch`.
- Call `litert_torch.convert` on `model.eval()` with a CPU float32 `[1, 1, 28, 28]` example.
- Export `clothing.tflite` with positional input buffer 0 and output buffer 0.
- Copy the file to `app/src/main/assets/clothing.tflite`.

## Takeaways

- Do not transpose to NHWC unless you change both export and Kotlin together.
- Required check: a non-empty file plus an Android runtime smoke test.
- If an operator fails, keep the architecture and update the pinned `litert-torch` package.

## Acceptance checks

The file is non-empty, the fixed tensor contract is written down, and the [human lesson](03-export-to-litert.html) link works.
