lora-from-scratch: adapting a small language model to new text by training a small fraction of its weights
Abstract. A small pretrained transformer is adapted to source code by training two thin matrices per layer instead of its weights. The backward pass, the adapters and the merge are written by hand, and every figure below runs the same adapter files in plain JavaScript.
Loading model and adapters...
1Switching an adapter on
The base model has only read Python documentation. An adapter is a small file, a few hundred kilobytes at most, that changes how it writes. Figure 1 generates from one prompt and seed, so any difference between two runs is the adapter and nothing else. Each token is shaded by how unlikely the model found it.
1 is the strength it was trained at; 0 is the plain base model.
Output
adapter off2Measuring it
Looking at samples proves little. Figure 3 scores three 128-token passages the model never trained on, computed in this page with the same forward pass that generated the text above.
3Five experiments
Loading results...
Experiment 1 and 2: base model, full fine-tune and LoRA at three ranks
Experiments 3 and 4: forgetting, and less data
Experiment 5: adapter swapping
docs/results.json. Losses are nats per token on held-out validation documents.4Trying to break it
Three ways to misuse an adapter, and what the code does about each.