Short answer
Adapt a model to teach behaviour, such as a fixed output format, and use a lookup for facts. In a measured test, a LoRA adapter took a small model from 0% to about 55% exact on a formatting task with unseen wording, while the same method taught facts that collapsed to 0% when reworded, against 92% for a plain embedding lookup.
Follow-up question How do you decide in ten minutes?
Adapting a model means changing how it behaves by training on examples, usually without touching most of its weights. LoRA does that by freezing the original weights and adding small trainable matrices. For the broader steps and tools, including QLoRA on larger models, see how to fine-tune a small open model. This project asks a narrower question, and puts one task that suits the method beside one that does not.
The model is SmolLM2-135M-Instruct: 135 million parameters, Apache 2.0 licence, about 540 MB in memory. It is tiny and often wrong, which is useful here, because you can see what training changes. The SmolLM2 paper describes the family. All data is synthetic, and the script is 09_adapt_small_model.py.
The adapter itself
from peft import LoraConfig, get_peft_model
cfg = LoraConfig(r=16, lora_alpha=32, lora_dropout=0.05,
target_modules=["q_proj", "k_proj", "v_proj", "o_proj"], task_type="CAUSAL_LM")
model = get_peft_model(model, cfg)
r sets the size of the added matrices, and the target modules are the attention layers. This leaves 1,843,200 trainable parameters, 1.4% of the model. The adapter file is 7.4 MB, next to 538 MB of frozen weights in 32-bit form. The training loop masks the prompt, so the model is only graded on its answer. The file lm_utils.py has the whole loop in about 40 lines.
Each run below took 250 steps with batches of 8, at most about two minutes on an Apple M5 Max's built-in GPU (PyTorch 2.15, Transformers 5.22, PEFT 0.21), on a machine also running other work.
Task A: a good fit, a fixed format
Turn a shop note into one line that software can read:
Rewrite the note as one line: ITEM=<item>; ISSUE=<noise|broken|late|billing>; URGENT=<yes|no>
The snow blower fell apart after a day. It cannot wait, answer right now.Expected: ITEM=snow blower; ISSUE=broken; URGENT=yes. The test uses 100 notes about items never seen in training. One test set also uses wordings never seen.
| Model | New items, familiar wording: exact | New items, new wording: exact |
|---|---|---|
| Untuned, instruction only | 0% | |
| Untuned, instruction plus two examples | 0% | |
| Adapter, 20 training examples | 78% | 53% |
| Adapter, 100 training examples | 84% | 56% |
| Adapter, 400 training examples | 84% | 55% |
Three lessons. The untuned model could not do this at all, even with examples in the prompt. A larger model might, so test instructions first with the model you actually have. Second, 20 examples gave most of the gain, and going to 400 added nothing on new wordings. All 400 came from the same twelve phrasings, so this is project three's variety lesson again. Third, training loss reached 0.000 in all three runs, while exact accuracy on new wording sat near 55%. The loss would have told you that everything was fine.
A 55% model is not ready for use. Its value is in what it shows: format came easily, and generalizing to new wordings did not.
Task B: a bad fit, facts that change
Now teach 12 facts about a fictional community centre, such as the pool's closing time. Train on one phrasing of each question, then ask.
| Method | Trained wording | Slightly changed wording | Really different wording |
|---|---|---|---|
| Untuned model, no context | 0% | ||
| Untuned model, handed the right line | 58% | ||
| Adapter trained on the facts | 100% | 92% | 0% |
| Plain lookup with embeddings, returns the line itself | 100% | 92% |
A perfect score on trained wording looks like success. Reword the question to "How late can I swim at night?" and the tuned model answers "24 hours". Asked what a grown-up member pays per year, it answers "75 dollars", a real value from another fact. It learned to emit values in response to a pattern and it delivers them with the same confidence when wrong.
Then three facts changed, as facts do. The tuned model kept giving all three old values, and correcting it means another training run. The lookup needed three edited lines and three new vectors, and still got 92% on the hard wording. The lookup works exactly as in project eight, with no language model writing anything.
The middle row deserves a note. A model this small, given the right line, still answered correctly only 58% of the time, and sometimes it made up details: it invented a "$25,000" income limit that was on no line. Handing a weak model the right text does not guarantee a right answer, so a retrieved line shown as-is can be the better product.
Try it: Write down one task you want a model for. Put each part in one of two columns, "how it should behave" and "what it should know". Only the first column is a candidate for training.
How do you decide in ten minutes?
Go through these questions in order and stop at the first yes.
| Question | If yes |
|---|---|
| Can ordinary code do it, such as a template or a rule? | Write the code |
| Is the need really a fact, price, policy or date? | Use a lookup or retrieval |
| Do clear instructions with a few examples work on 20 test cases? | Stop there, and keep the prompt |
| Would a larger ready-made model do it within budget? | Use it |
| Is it a repeated format, style or decision, with many correct examples? | Try an adapter, against a held-out test |
Reasons to pick an adapter do exist: a model too small to follow instructions, as here; a need for speed, privacy or offline use; a shape of output that prompting cannot hold steady. The costs include examples to maintain, retraining when the base model changes, a licence to respect and a test set to keep running. Before you train, write the score you need to reach, and what you will do if it stays at 55%.
Download the companion code for this series (zip), with every script and the recorded results.
Sources
- LoRA: Low-Rank Adaptation of Large Language Models — arXiv (Hu et al., Microsoft), June 17, 2021
- SmolLM2-135M-Instruct model card — Hugging Face
- SmolLM2: When Smol Goes Big — arXiv, February 4, 2025
From the Guide to Artificial Intelligence, by Robert Scales, published by Holistic Hybrid Inc. Share and adapt it under CC BY-NC-SA 4.0: credit the guide, link to https://guidetoartificialintelligence.com/en/learn/adapt-small-language-model-when-not/, no commercial use without permission, and keep the same licence.