What it is
Most AI headshot apps upload 10–20 photos and train a model per customer on a server. I wanted to measure how much of that can happen on the device, with no upload and no per-user training.
It's built in stages on Stable Diffusion 1.5. I started with DDPM written from scratch (a 6.5M-param UNet with DDPM and DDIM samplers), then rewrote SD 1.5's sampling loop by hand until it matched diffusers pixel for pixel, then built the eval harness before training anything. Every stage after that (a face LoRA, zero-shot FaceID, Core ML conversion, quantisation and few-step sampling) is judged by the same numbers.
How it works
- 1
Measure first
Identity is scored by two independent face recognizers (buffalo_l and antelopev2, AUC 0.993 and 0.992 on 1,000 LFW pairs), prompt adherence by CLIP ViT-L/14, and passport framing by 13 checks built on MediaPipe landmarks. A cosine of 0.30 is the same-person line.
- 2
Teach it the face
A LoRA on the SD 1.5 UNet learns one face from 17 audited photos (rank 16, 2,000 steps, about 13.5 min on a rented RTX 3090). Every checkpoint is scored by the harness and the pick is made by the curve.
- 3
Fold and convert
The face LoRA and an LCM-LoRA are folded into the UNet weights and converted to Core ML. All 3,057 UNet ops land on the Neural Engine with no switches to other devices.
- 4
Frame the head
A pose ControlNet with a skeleton placed from the passport geometry spec keeps the head in frame. Without it the head was cut off in 5 of 6 images; with it, 0 of 8.
- 5
Shrink and speed up
The UNet is palettised to 8 bits (1,721 MB to 862 MB) and LCM cuts sampling from 25 steps to 4. On the M4 Neural Engine that is 1.34 s per image.
Decisions and trade-offs
One selfie beat 17 photos
Zero-shot IP-Adapter FaceID from one selfie scored 0.67 identity against 0.49 for the trained LoRA, with no training at all, which is the property an on-device product needs. The costs: unprompted desaturated outputs, a non-commercial licence, and no blind human test yet.
Fewer steps kept the face better
I expected 4-step LCM to lose the face. It went the other way: identity rose from 0.45 to 0.63, because strong guidance in the 25-step baseline pulled faces toward a generic 'corporate man'. The cost is less variety of expression and a smoother, airbrushed look.
How small before it stops being you
8-bit is free: half the size, same identity. 4-bit per-tensor breaks the face (identity 0.33) while CLIP and the compliance count barely move, so I added image PSNR against the FP16 output to catch texture damage the other metrics miss.
