ML · NLP · 2025
Parameter-Efficient Adaptation of GPT-2
Implemented a GPT-2-style Transformer and compared lightweight adaptation methods across sentiment classification, paraphrase detection, and conditional sonnet generation.
LoRA and ReFT approached or exceeded full fine-tuning on short-form sentiment while updating a fraction of the parameters, but the advantage did not transfer uniformly across longer classification inputs and generation tasks.
- Role
- Machine Learning Engineer
- Team
- 3
- Backbone
- GPT-2 small
- Tasks
- 3

Trainable parameters, highlighted SST ReFT run
Best individual ReFT run on SST
Memory reduction under the selected CFIMDB configuration
Development chrF, not classification accuracy
Downstream NLP tasks
Metrics come from different task-specific configurations and should not be interpreted as one combined model result.
Overview
How much of a language model actually needs to change?
Frozen encoder
Last linear layer
Input adaptation
Soft prompts
Representation adaptation
ReFT
Weight adaptation
LoRA
Full-model adaptation
Full fine-tuning
We compared whether task behavior could be changed by modifying only the classifier, learned inputs, hidden representations, low-rank attention updates, or the entire model.
For generation, can inference-time decoding decisions matter more than additional training?
The central question was not whether GPT-2 could be adapted, but where adaptation should occur — and how much of the model actually needed to change.
Backbone
What we implemented
The team implemented this decoder-only architecture and loaded pretrained GPT-2 weights into it — the pretrained language model itself was not trained from scratch.
Token + positional embeddings
Transformer block × 12
Pre-LayerNorm → causal multi-head self-attention → residual → Pre-LayerNorm → feed-forward → residual
Final LayerNorm
Autoregressive LM head
Tied to the input embedding weights
| Component | Implementation detail |
|---|---|
| Architecture | Decoder-only Transformer |
| Attention | Causal multi-head self-attention |
| Normalization | Pre-LayerNorm |
| Embeddings | Token and positional embeddings |
| Output | Tied input/output embedding weights |
| Classification representation | Final non-padding token |
| Generation | Autoregressive next-token prediction |
| Optimizer | AdamW |
| Model selection | Best development checkpoint |
| Random seed | 11711 for primary experiments |
- Architecture
- Decoder-only Transformer
- Attention
- Causal multi-head self-attention
- Normalization
- Pre-LayerNorm
- Embeddings
- Token and positional embeddings
- Output
- Tied input/output embedding weights
- Classification representation
- Final non-padding token
- Generation
- Autoregressive next-token prediction
- Optimizer
- AdamW
- Model selection
- Best development checkpoint
- Random seed
- 11711 for primary experiments
Methods
Where does each method modify the model?
Full fine-tuning
- Where
- All model parameters
- Mechanism
- Update the entire pretrained backbone and task head.
- Strength
- Maximum adaptation capacity.
- Cost
- Highest trainable-parameter count and GPU-memory use.
Tasks
One backbone, three different adaptation problems
Sentiment classification
Datasets
SST, CFIMDB
Objective
- 5-class sentence sentiment
- Binary movie-review sentiment
Compared
- Last linear layer
- Full fine-tuning
- LoRA
- ReFT
Metric
Development accuracy
Paraphrase detection
Dataset
Quora question pairs
Objective
- Binary paraphrase classification
Compared
- Full fine-tuning
- LoRA
- ReFT
- Soft prompt tuning
Metric
Development accuracy and final full-model test accuracy
Parameter-efficient experiments used a 25% training subset; the full-model result used the complete training set.
Conditional sonnet generation
Dataset
Shakespeare sonnets
Objective
- Continue a sonnet from its first three lines
Compared
- Full fine-tuning
- LoRA and ReFT experiments
- DPO
- Hyperparameter tuning
- Sampling and reranking
Metric
chrF
| Dataset | Task | Train | Dev | Test |
|---|---|---|---|---|
| SST | 5-class sentiment | 8,544 | 1,101 | 2,210 |
| CFIMDB | Binary sentiment | 1,701 | 245 | 488 |
| Quora | Paraphrase detection | 283,003 | 40,429 | 80,858 |
| Sonnets | Conditional generation | 131 | 12 | 12 |
- SST — 5-class sentiment
- Train: 8,544Dev: 1,101Test: 2,210
- CFIMDB — Binary sentiment
- Train: 1,701Dev: 245Test: 488
- Quora — Paraphrase detection
- Train: 283,003Dev: 40,429Test: 80,858
- Sonnets — Conditional generation
- Train: 131Dev: 12Test: 12
Experimental workflow
- Source dataset
- Tokenize & batch
- Load shared pretrained backbone
- Apply adaptation method
- Train for up to 10 epochs
- Select best development checkpoint
- Evaluate performance
- Record trainable parameters & GPU memory
Classification
- 1.Final-token representation
- 2.Linear head
- 3.Accuracy
Generation
- 1.Next-token loss
- 2.Autoregressive decoding
- 3.chrF
DPO
- 1.Construct synthetic preferred/dispreferred pairs
- 2.Preference loss
- 3.Generate on held-out prompts
- 4.chrF
Test data was not used for hyperparameter selection.
Efficiency
Sentiment classification: performance versus efficiency
Representative best-run configurations, not five-seed means (see the multi-seed analysis below).
Point size represents peak GPU memory — larger points used more memory.
| Method | Trainable parameters | Peak GPU memory | Accuracy |
|---|---|---|---|
| Last linear layer | 0.0031% | 681.36 MB | 0.467 |
| Full fine-tuning | 100% | 4865.96 MB | 0.520 |
| ReFT | 0.0178% | 2398.49 MB | 0.526 |
| LoRA | 0.1209% | 2861.55 MB | 0.519 |
- Last linear layer
- Trainable parameters: 0.0031%Peak GPU memory: 681.36 MBAccuracy: 0.467
- Full fine-tuning
- Trainable parameters: 100%Peak GPU memory: 4865.96 MBAccuracy: 0.520
- ReFT
- Trainable parameters: 0.0178%Peak GPU memory: 2398.49 MBAccuracy: 0.526
- LoRA
- Trainable parameters: 0.1209%Peak GPU memory: 2861.55 MBAccuracy: 0.519
- On SST, the highlighted ReFT run slightly exceeded the full-model baseline while updating 0.0178% of parameters.
- On CFIMDB, full fine-tuning retained the highest accuracy.
- ReFT reduced CFIMDB peak GPU memory from 2,710.30 MB to 1,032.63 MB.
- The last-linear-layer baseline was cheapest but lost substantial accuracy.
Layers
Where you intervene mattered more than how large the intervention was
Layer number within the 12-layer GPT-2 small stack
SST accuracy
0.526
CFIMDB accuracy
0.971
- Early — layer 2
- SST: 0.507CFIMDB: 0.976
- Middle — layer 5
- SST: 0.504CFIMDB: 0.967
- Late — layer 11
- SST: 0.480CFIMDB: 0.873
- Distributed — layers 1, 6, 11
- SST: 0.526CFIMDB: 0.971
- Late cluster — layers 8, 9, 10
- SST: 0.507CFIMDB: 0.976
| ReFT placement, rank 4 | SST accuracy | CFIMDB accuracy |
|---|---|---|
| Early — layer 2 | 0.507 | 0.976 |
| Middle — layer 5 | 0.504 | 0.967 |
| Late — layer 11 | 0.480 | 0.873 |
| Distributed — layers 1, 6, 11 | 0.526 | 0.971 |
| Late cluster — layers 8, 9, 10 | 0.507 | 0.976 |
- Distributed interventions produced the strongest individual SST result.
- A single final-layer intervention performed poorly, especially on CFIMDB.
- Placement produced larger changes than modest rank adjustments.
- The result suggests — but doesn't prove — that sentiment information is developed across multiple stages of the network.
More adaptation capacity was not always better
Rank 8, α = 16
SST
0.517
CFIMDB
0.939
Rank 4, α = 8
SST
0.519
CFIMDB
0.971
Rank 8, α = 32
SST
0.509
CFIMDB
0.820
Rank 16, α = 32
SST
0.515
CFIMDB
0.898
Moderate rank and scaling produced the most stable performance, while larger update magnitudes degraded CFIMDB accuracy.
Paraphrase
Parameter efficiency did not transfer equally to every task
The full-model baseline and parameter-efficient methods were not trained on equal amounts of data, so this is not a perfectly controlled head-to-head comparison.
| Method | Training setting | Dev accuracy | Test accuracy |
|---|---|---|---|
| Full fine-tuning | Full Quora training set | 0.898 | 0.859 |
| LoRA | 25% training subset | 0.856 | Not reported |
| ReFT | 25% training subset | 0.817 | Not reported |
| Soft prompt tuning | 25% training subset | 0.743 | Not reported |
- Full fine-tuning
- Full Quora training set
- Dev: 0.898Test: 0.859
- LoRA
- 25% training subset
- Dev: 0.856Test: Not reported
- ReFT
- 25% training subset
- Dev: 0.817Test: Not reported
- Soft prompt tuning
- 25% training subset
- Dev: 0.743Test: Not reported
- Full-model fine-tuning produced the strongest result.
- LoRA retained more performance than ReFT or soft prompts in the reduced-data experiment.
- Input-level adaptation alone was insufficient under the tested soft-prompt configuration.
- Longer or pairwise reasoning tasks may require greater adaptation capacity or better tuning — a hypothesis, not a settled conclusion.
Generation
For generation, inference strategy mattered more than another training objective
Train
- Fine-tune GPT-2 on complete sonnets
- Condition evaluation on the first three lines
- Predict the continuation autoregressively
Sample
- Temperature
- Top-p
- Candidate-pool size
- Multiple continuations
Rerank
- Repetition penalty
- Incorrect line-count penalty
- Structural-issue penalty
Best development chrF
Final test chrF
Best candidate strategy
Best-of-5 and best-of-15 performed worse.
How reranking picks a continuation
Illustrative diagram of the mechanism — not real project output. Descriptors are representative structural scores, not recorded generations.
When preference optimization made generation worse
| Negative-construction strategy | Development chrF |
|---|---|
| Line shuffling after truncation | 41.30 |
| Partial continuation replacement | 41.04 |
| Full continuation replacement | 41.27 |
- Line shuffling after truncation
- chrF: 41.30
- Partial continuation replacement
- chrF: 41.04
- Full continuation replacement
- chrF: 41.27
- Synthetic corrupted continuations were used because the dataset did not contain human preference pairs.
- None of the DPO configurations exceeded the best reranked full-model result.
- Qualitative inspection found genre drift, repetition, prose-like narration, and text corruption.
- The preference pairs likely did not encode the qualities most important for sonnet continuation.
A preference objective is only as useful as the preference data used to define it.
Statistics
Single best runs were not the whole story
| Method | SST mean ± std | CFIMDB mean ± std |
|---|---|---|
| ReFT, layer 2 | 0.5124 ± 0.0046 | 0.9696 ± 0.0040 |
| ReFT, layers 1/6/11 | 0.5148 ± 0.0078 | 0.9670 ± 0.0057 |
| LoRA | 0.5216 ± 0.0053 | 0.9666 ± 0.0135 |
| Full fine-tuning | 0.5080 ± 0.0105 | 0.9808 ± 0.0018 |
| Last linear layer | 0.4630 ± 0.0060 | 0.8586 ± 0.0108 |
- ReFT, layer 2
- SST: 0.5124 ± 0.0046CFIMDB: 0.9696 ± 0.0040
- ReFT, layers 1/6/11
- SST: 0.5148 ± 0.0078CFIMDB: 0.9670 ± 0.0057
- LoRA
- SST: 0.5216 ± 0.0053CFIMDB: 0.9666 ± 0.0135
- Full fine-tuning
- SST: 0.5080 ± 0.0105CFIMDB: 0.9808 ± 0.0018
- Last linear layer
- SST: 0.4630 ± 0.0060CFIMDB: 0.8586 ± 0.0108
SST significance (vs. full fine-tuning)
- LoRA vs. full fine-tuningp = 0.0411
- ReFT layer 2 vs. fullp = 0.4910
- ReFT distributed vs. fullp = 0.2353
CFIMDB significance (vs. full fine-tuning)
- LoRA vs. fullp = 0.0653
- ReFT layer 2 vs. fullp = 0.0070
- ReFT distributed vs. fullp = 0.0041
- LoRA's SST mean was significantly higher than the full-model mean under the five tested seeds.
- ReFT was statistically indistinguishable from full fine-tuning on SST.
- Full fine-tuning retained a statistically significant advantage over ReFT on CFIMDB.
- LoRA's CFIMDB difference did not meet the p < 0.05 threshold.
- Five seeds are not enough for a highly robust statistical conclusion.
My role
My focus: paraphrase detection and generation
This was a three-person team project. ReFT, LoRA, and DPO were primarily implemented by other members of the team — the contributions below describe what I personally worked on.
Paraphrase detection
- Implemented the GPT-2-based paraphrase-detection pipeline
- Encoded question pairs for binary classification
- Built and evaluated full-model and parameter-efficient experiments
Soft prompt tuning
- Implemented learned continuous prompt embeddings
- Integrated prompt positions with the frozen GPT-2 backbone
- Evaluated soft prompting on Quora paraphrase detection
Sonnet generation
- Implemented and improved the conditional sonnet-generation pipeline
- Tuned training and decoding hyperparameters
- Explored candidate generation and best-of-N reranking
- Helped analyze why decoding improvements outperformed the tested DPO configurations
Communication
- Contributed to experiment interpretation and the final technical report
Engineering judgment
Technical challenges and decisions
Challenge 1
One model had to support classification and generation
Decision
Use a shared decoder-only GPT-2 backbone and task-specific heads or objectives.
Lesson
A shared architecture makes method comparisons easier, but task behavior still differs substantially.
Challenge 2
Efficiency has multiple dimensions
Decision
Measure accuracy, percentage of trainable parameters, and peak GPU memory.
Lesson
Low parameter count does not automatically imply proportionally low memory use because activations and optimizer behavior still matter.
Challenge 3
ReFT required choosing intervention locations
Decision
Sweep rank and layer placement separately.
Lesson
Layer placement affected performance more strongly than modest rank changes.
Challenge 4
Likelihood training did not guarantee strong poetic structure
Decision
Tune sampling and rerank multiple candidates using lightweight structural penalties.
Lesson
For open-ended generation, inference-time selection can be as important as the training objective.
What worked and what did not
What worked
- LoRA and ReFT offered strong SST performance with very small trainable parameter budgets
- ReFT substantially reduced CFIMDB GPU-memory use
- Distributed ReFT interventions performed well on SST
- Moderate LoRA rank and scaling were more stable than aggressive configurations
- Best-of-10 reranking produced the strongest sonnet-generation result
- Multi-seed analysis revealed differences hidden by individual runs
What did not consistently work
- The last-linear-layer baseline lost substantial accuracy
- Soft prompting underperformed on the tested paraphrase configuration
- Late-only ReFT intervention degraded CFIMDB performance
- Larger LoRA scaling did not improve results
- PEFT did not match full fine-tuning on the reduced-data paraphrase setting
- Synthetic-corruption DPO did not outperform decoding-based reranking
What this experiment does — and does not — establish
Limitations
- Experiments used GPT-2 small
- Compute limited the number of random seeds
- Hyperparameter sweeps were not exhaustive
- Some task comparisons used different training-data amounts
- Sonnet evaluation relied heavily on chrF
- Synthetic DPO negatives may not reflect genuine human preferences
- Results may not transfer directly to larger models
- Development metrics were used for model selection
Next steps
- Repeat experiments with more seeds
- Equalize training data across paraphrase methods
- Explore additional ReFT layer combinations
- Tune LoRA rank and scaling more systematically
- Compare wall-clock training time and energy use
- Evaluate larger backbones
- Use human evaluation for generation quality
- Create preference pairs that explicitly encode meter, rhyme, structure, and semantic coherence
- Compare learned rerankers with hand-designed penalties
- Analyze whether task complexity predicts the best adaptation location
Tech & topics
- Python
- PyTorch
- Transformers
- GPT-2
- LoRA
- ReFT
- Soft Prompt Tuning
- DPO
- Hyperparameter Tuning
- Autoregressive Decoding
- Statistical Analysis