This project fine-tunes LLaMA-2-7B using QLoRA (4-bit quantization + LoRA adapters) on the Finance-Alpaca dataset.
The goal is to efficiently adapt a large language model to a financial question-answering domain using modern, resource-efficient techniques.
Large models like LLaMA-2 normally require significant GPU memory to fine-tune.
This project uses QLoRA, which combines:
- 4-bit quantization (BitsAndBytes) → drastically reduces memory usage
- LoRA adapters (PEFT) → trains only low-rank matrices in attention layers
- TRL SFTTrainer → streamlined supervised fine-tuning
This enables full fine-tuning of a 7B model on a single consumer GPU / Colab instance.
The model was trained on:
- 1,000 training examples
- 300 evaluation examples
from the gbharti/finance-alpaca dataset.
- Load the Finance-Alpaca dataset (Hugging Face)
- Sample 1000 train / 300 test examples
- Convert each example into Alpaca-style prompts:
Evaluate the pretrained LLaMA-2-7B using ROUGE metrics:
- ROUGE-1
- ROUGE-2
- ROUGE-L
- ROUGE-Lsum
- Load LLaMA-2-7B in 4-bit mode using
BitsAndBytesConfig - Add LoRA adapters to:
q_projv_proj- Train using
SFTTrainer(1 epoch, efficient batch configuration) - Save adapter weights
Reload the model with LoRA adapters and re-run ROUGE evaluation on the 300-sample test set.
| Metric | Pretrained | Fine-Tuned |
|---|---|---|
| ROUGE-1 | 0.1205 | 0.2519 |
| ROUGE-2 | 0.0203 | 0.0400 |
| ROUGE-L | 0.0802 | 0.1371 |
| ROUGE-Lsum | 0.0818 | 0.1526 |
All evaluation metrics improved significantly after domain-specific fine-tuning.
- Hugging Face Transformers
- PEFT (LoRA Adapters)
- TRL (SFTTrainer)
- BitsAndBytes (4-bit quantization)
- evaluate / ROUGE
- PyTorch
- Must be ran using T4 GPU Install dependencies:
pip install transformers peft trl bitsandbytes datasets evaluate rouge_score