Commit Message LoRA Fine-Tuning
Problem
Developers often write vague, informal commit messages under pressure (e.g., "fix login bug"). While large language models can rewrite these into clean, professional summaries, deploying a full 7B or 70B parameter model solely for commit formatting is highly cost-inefficient. There is a need for a highly capable but small model that can run efficiently on edge or consumer hardware.
Architecture Diagram
Raw Kaggle Dataset -> Data Cleaning & Sampling (prepare_dataset.py)
│
▼
HuggingFace Dataset
│
┌──────────────────────┼──────────────────────┐
▼ ▼ ▼
Qwen2.5-1.5B LoRA Adapters 4-bit Quantization
│ │ │
└──────────────────────┼──────────────────────┘
▼
TRL SFTTrainer (train.py)
│
▼
FastAPI Inference Endpoints
Workflow
The pipeline starts by downloading and cleaning the GitHub Commit Messages dataset from Kaggle, then sampling 5,000 rows for training. The data is tokenized and formatted into instruction templates. Using Parameter-Efficient Fine-Tuning (LoRA) and 4-bit bitsandbytes quantization, the Qwen2.5-1.5B-Instruct model is fine-tuned without modifying all base weights. Finally, the optimized LoRA adapters are loaded into a PyTorch inference script capable of generating professional commit summaries on a single GPU.
Tech Stack
| Component | Tool |
|---|---|
| Base Model | Qwen/Qwen2.5-1.5B-Instruct |
| Fine-Tuning | LoRA via 🤗 PEFT |
| Trainer | TRL SFTTrainer |
| Quantization | 4-bit (bitsandbytes) |
| Dataset | GitHub Commit Messages — Kaggle |
| Framework | PyTorch + HuggingFace Transformers |
Project Structure
commit-message-lora/ ├── data/ │ └── prepare_dataset.py # Download, clean & sample from Kaggle ├── src/ │ ├── config.py # All hyperparameters in one place │ ├── dataset.py # HuggingFace Dataset + tokenization │ ├── train.py # End-to-end training pipeline │ ├── inference.py # Load adapter & generate messages │ └── utils.py # Prompt templates & text helpers ├── commit_lora/ # Saved LoRA adapter weights (post-training) └── requirements.txt
Quickstart
1. Install dependencies — requires a Kaggle API key at ~/.kaggle/kaggle.json
2. Prepare the dataset — downloads, filters by message length, and samples 5,000 rows to data/prepared.csv
3. Train — 2 epochs with 4-bit quantization + LoRA; adapter saved to ./commit_lora
4. Run inference
from src.inference import load_model_for_inference, generate_commit_message
model, tokenizer = load_model_for_inference()
print(generate_commit_message("add dark mode", model, tokenizer))
# → "Add dark mode support with system preference detection"Training Details
| Hyperparameter | Value |
|---|---|
| LoRA rank (r) | 16 |
| LoRA alpha | 32 |
| Dropout | 0.05 |
| Learning rate | 2e-4 |
| Batch size | 4 |
| Gradient accumulation | 4 steps |
| Epochs | 2 |
| Max sequence length | 256 tokens |
| Quantization | 4-bit NF4 |
Fine-tuning a full 1.5B model requires significant GPU memory and time. LoRA inserts small trainable rank-decomposition matrices into the attention layers, cutting trainable parameters by ~99% while achieving comparable task performance — making the project reproducible on a single consumer GPU (e.g. a T4 on Colab).
Challenges
The main challenge was handling the high memory footprint required for fine-tuning even a 1.5B parameter model on limited hardware. Standard full fine-tuning would cause Out-Of-Memory (OOM) errors on a single T4 GPU. Additionally, carefully constructing the prompt templates was crucial to ensure the model didn't hallucinate context that wasn't in the original sloppy commit message.
Trade-offs
By choosing LoRA over full fine-tuning, I traded a slight potential drop in absolute maximum model capacity for a massive ~99% reduction in trainable parameters, enabling practical training on consumer hardware. Using 4-bit NF4 quantization slightly degraded the model precision but allowed the training script to run within the strict VRAM constraints of the T4 GPU.
Benchmarks
~99%
Reduction in Trainable Params
Via LoRA and 4-bit NF4 quantization vs full fine-tuning
1x T4
Hardware Requirement
For both training and fast inference
GitHub Repository
The fine-tuning pipeline, dataset prep scripts, and inference code are available on GitHub.
sowndappan5/commit-message-lora