PythiloLesson 7 of 8 · progress kept in this browser

Practice in Lab: Project: train and reload a local DPO policy with LoRA ownership →

Project: train and reload a local DPO policy with LoRA ownership

Preference optimization needs more evidence than a scalar loss formula. This project owns a local supervised base, a frozen reference, trainable low-rank adapters and separate prompt identities for selection and evaluation. Pair responses contain real token sequences, so the optimizer evaluates chosen and rejected prefixes rather than fabricated sequence scores. The exported artifact includes every component required for offline reload. Generated preferences make optimizer and ownership failures reproducible; they do not establish natural-language ability or human alignment.

Your task

Implement the full synthetic preference experiment with the supplied local conditional token model and data helpers. First supervised-train the local base only on training chosen responses, freeze it as the reference, clone it and train only the two rank-two adapter matrices with response-token DPO at beta=.5. Select by validation preference loss, evaluate separate prompt identities, and export a real serialized model/reference/initialization artifact. Report actual loss, preference wins, reference-to-policy KL, parameter ownership, frozen-base hashes and reload equality. Preserve the reference report schema and prevent test preferences from fitting or selecting weights. The base is locally trained on generated pairs, not a downloaded pretrained LLM.

This lesson uses torch, which Python in this browser does not include. Read it here, and run and check it in the Pythilo app on iPhone or iPad.