user@devops:~$ cat README.md
Foundation Models — Fine-tuning with LoRA
# Description
LoRA (Low-Rank Adaptation, Hu et al. 2021) is the standard method for fine-tuning foundation models: instead of updating the pretrained weights W, two low-rank matrices A and B are injected (W' = W + (α/r)·B·A) into the attention projections and only those matrices are trained. This project demonstrates it on distilgpt2 (82M parameters, 6 layers) by teaching it arithmetic: 2-digit + 1-digit additions (11-90 + 1-9). With r=8, α=16 and dropout 0.05 on q_attn/c_attn/c_proj, only 589,824 parameters (0.72% of the total) are trainable: optimization memory (gradients + 2 AdamW states) drops from ~984 MB for full fine-tuning to ~4.9 MB with LoRA (~200x less). The dataset is synthetic: 1,600 training problems and 300 held-out. Key tokenization finding: GPT-2's BPE collapses '68' into a single token, turning the task into memorizing (a,b)→token pairs; by space-separating digits ('A: 6 8') the model learns the algorithm digit by digit. Results (exact-match, greedy decoding): base model 0.0% (≈ random 1.2%) vs LoRA 29.7% (+29.7 pp) after 6 epochs on CPU. Error analysis shows the expected pattern: carry additions are harder than non-carry, and the tens digit accuracy (93.7%) far exceeds the ones digit (29.7%): the local ones computation is the bottleneck. 6 visualizations: loss curve + epoch-wise exact-match, base vs LoRA vs random, difficulty by carry, per-digit accuracy, parameter/memory breakdown and real generations before vs after.
# Key features
$ LoRA (Low-Rank Adaptation) via the PEFT library: W' = W + (α/r)·B·A with r=8, α=16, dropout 0.05
$ Only 589,824 trainable parameters (0.72% of distilgpt2's 82M): 99.5% stays frozen
$ Optimization memory: ~984 MB (full fine-tuning) vs ~4.9 MB (LoRA) — ~200x less
$ Task: 2-digit + 1-digit additions (11-90 + 1-9), 1,600 synthetic train examples / 300 held-out
$ Tokenization finding: BPE collapses '68' into one token → space-separated digits ('A: 6 8') to learn digit by digit
$ Held-out exact-match: base 0.0% → LoRA 29.7% (+29.7 pp), deterministic greedy decoding
$ Error analysis: carry additions harder than non-carry; tens digit (93.7%) far more accurate than ones (29.7%); carry near-perfect (93.7%)
$ Adapter saved (artifacts/lora_adapter, ~1.5 MB) + 6 visualizations + reproducible history JSON
# Gallery
# Technologies used