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.
Prepare offline
Choose Download entire course or Download entire category first. After completion, code and checks run locally on CPU. The independent example needs no account, remote service or API key.
import torch
base = torch.nn.Linear(6, 3)
a = torch.zeros(2, 6)
b = torch.zeros(3, 2)
print((base.weight + b @ a).shape)Review the evidence
Audit response masks, reference identity, adapter ownership and held-out prompt groups. Review reward/preference provenance and length effects separately before extending this controlled experiment to a real pretrained language model.
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.
The explanation opens here once every check passes.