Three progressive stages teach a model domain knowledge, conversational behavior, and human-preferred quality — each adding a lightweight LoRA adapter then merging it into the weights.
Each stage trains a LoRA adapter then merges it into the weights — the merged result is the foundation for the next stage. Watch the signal travel M0 → M3.
You can't attach LoRA₃ to M0 and get M3. Each merge_and_unload() bakes the adapter's learned knowledge into the weights permanently. The merged model is the correct foundation for the next adapter. Analogy from class: M0 = Class 10 student — you can't attach "Class 12 behavior" on top of Class 10; you must graduate through Class 11 first.
Continued pretraining on raw domain text — no Q&A structure, no instructions. The model learns specialized vocabulary, entity co-occurrences, and statistical patterns from YOUR corpus. Training objective: next-token prediction, identical to original pretraining.
Raw text: PDF → extract → clean → chunk into 512-token blocks. No labels, no answers — just domain text.
Minimize cross-entropy on P(token_n | context). The model learns which pharma terms co-occur, not how to answer questions.
Domain terminology, drug-mechanism collocations, scientific sentence structure. It does NOT learn to "answer" — that's Stage 2.
Yes. If your domain isn't highly specialized, start at Stage 2 on the base model directly. Stage 1 matters most for rare, technical corpora.
Supervised Fine-Tuning on structured instruction–response pairs. Stage 1 taught the model what words belong in pharma text. Stage 2 teaches it how to answer — to follow the Alpaca prompt format and respond usefully to domain questions.
Structured JSONL with instruction, input (optional context), and output fields — the Alpaca format.
Cross-entropy on response tokens only — the instruction is masked. The model learns to produce the answer, not to "guess the question".
M1 — the domain-adapted merged model. LoRA₂ on M1 means the adapter builds on pharma vocabulary already baked in from Stage 1.
1,000–10,000 Q&A pairs is practical for a POC. In regulated domains (pharma, healthcare), quality beats quantity — SME review is non-negotiable.
Stage 2 teaches the model how to answer. Stage 3 teaches it which answer is better. Given a prompt and two responses — one preferred by domain experts, one not — DPO nudges the model to favor the chosen response.
"Study for 48 hours continuously without sleep before your exam."
Plausible-sounding but unrealistic and harmful.
"Focus on high-weight topics, study in 90-minute blocks with breaks, review past papers actively."
Evidence-based, safe, and actionable.
DPO optimizes a policy π to prefer the chosen response over the rejected one, relative to a reference model πref (the model before alignment). The β parameter controls how far the policy can drift.
In plain English: maximize the model's preference for y_w over y_l, but don't let it drift too far from the reference model (β controls this tension).
Full fine-tuning updates every weight in the model — billions of parameters, expensive and prone to catastrophic forgetting. LoRA freezes the base weights and instead trains small rank-decomposed matrices that approximate the update.
Result: a 1.1B model (normally ~4GB) trains in ~2GB VRAM. A 7B model fits on a free T4 Colab GPU. NF4 quantization uses 4-bit NormalFloat — information-theoretically optimal for normally-distributed neural network weights, so accuracy loss is minimal.
Answer all five questions correctly for a confetti celebration. One attempt per question.
{{ item.q }}
You nailed the pipeline: merge between stages, SFT on Alpaca pairs, DPO without a reward model, and LoRA adapters on frozen weights.
Review the highlighted correct answers, then refresh the page to try again.