---
name: diffusion-lora-coreai lesson 05
description: >-
  Agent recipe for lesson 05: bundle the baked diffusion resource in Xcode 27
  and generate on device with current Core AI Swift utilities.
---
# Run the on-device pipeline

**Lesson id:** `05`  
**One-line goal:** Load the merged Core AI diffusion resource in Xcode 27 and measure one on-device generation.

## Why this matters on a phone

Privacy, speed, and offline use are proven only when the device generates from the baked folder with no adapter download.

## Prerequisites

Lesson 04 resource folder. Xcode 27. Metal Toolchain. Core AI framework.

## Inputs

Intact multi-component resource, a holdout prompt, a fixed seed.

## Outputs and artifacts

A SwiftUI screen, a device screenshot, and a note with prompt, seed, elapsed time, device, and checksum.

## Executable steps

1. Confirm Xcode with `xcode-select --install` and `xcodebuild -version`.
2. Create a SwiftUI App. Add Core AI. Install the Metal Toolchain. Add the whole `personalized` folder to Copy Bundle Resources.
3. Prepare the documented diffusion pipeline once at launch.
4. Generate off the main UI path. Show image, seed, and elapsed time.
5. Compare the same prompt and seed against a base export if you have one.
6. Verify names in the installed SDK docs. Treat course Swift as a shape.

## Constraints

No runtime LoRA load. No invented stable API names. No CUDA, quizzes, Mermaid, or em dashes.

## Failure modes

Flattened folder, prepare-on-tap, main-thread generation, copied placeholder types, Mac-only judgment, adapter-slot loader.

## Key concepts

- Mac export success is not the product. Device generation is.
- Bundle the intact multi-component folder in Xcode 27.
- Prepare the pipeline once at launch. Generate off the main thread.
- The app loads the baked merged resource only. No adapter download.

## Takeaways

- Record prompt, seed, device, checksum, and elapsed time.
- Flattening the folder breaks prepare.
- A second personalization is a second bake and a second resource.

## Done when

Prepare succeeds once. A fixed prompt and seed produce an image and a time on the target. The note says no runtime LoRA was loaded.

**Human lesson:** [Run the on-device pipeline](05-on-device-pipeline.html)
