Causal Language Model fine-tuned with LoRA (PEFT) on a diverse 41K-sample corpus spanning news, reviews, stories, sentiment, and encyclopedic text.
This project fine-tunes EleutherAI/Pythia-160M using Low-Rank Adaptation (LoRA) for causal language modeling. By combining 10 diverse text datasets, the model develops robust next-token prediction capabilities across multiple domains β from news articles to tweet sentiment β without modifying base model weights.
LoRA inserts trainable low-rank matrices into the transformer's attention layers, drastically reducing trainable parameters (from ~160M to ~300k) while retaining the expressiveness of the full model. This enables fine-tuning on a single Tesla T4 GPU in under 12 minutes(725 seconds).
EleutherAI/Pythia-160M (frozen)
β
βΌ
LoRA Adapters (r=8)
βββββββββββββββββββββββ
β q_proj β rank-8 β
β v_proj β rank-8 β
β alpha = 16 β
β dropout = 0.05 β
βββββββββββββββββββββββ
β
βΌ
Causal LM Head
| Parameter | Value |
|---|---|
| Base Model | EleutherAI/Pythia-160M |
| Total Parameters | ~160M |
| Trainable Parameters | ~300k (~0.18%) |
| LoRA Rank | 8 |
| LoRA Alpha | 16 |
| Target Modules | query_key_value |
| # | Dataset | Domain | Samples |
|---|---|---|---|
| 1 | AG News | News Classification | ~4,000 |
| 2 | IMDB | Movie Reviews | ~4,000 |
| 3 | Yelp Review Full | Business Reviews | ~4,000 |
| 4 | WikiText-2 | Wikipedia / Reference | ~4,000 |
| 5 | TinyStories | Short Stories | ~4,143 |
| 6 | Rotten Tomatoes | Movie Criticism | ~4,000 |
| 7 | Emotion | Social Media Emotion | ~4,000 |
| 8 | DBPedia | Encyclopedic Topics | ~4,143 |
| 9 | SST-2 | Sentiment Phrases | ~4,000 |
| 10 | TweetEval Sentiment | Twitter Sentiment | ~5,144 |
Total: 41,430 samples β Train: 37,287 Β· Validation: 4,143
# LoRA
lora_r: 8
lora_alpha: 16
lora_dropout: 0.05
target_modules: ["query_key_value"]
# Training
num_train_epochs: 1
learning_rate: 2e-4
per_device_train_batch_size: 4
gradient_accumulation_steps: 4
effective_batch_size: 16
max_seq_length: 128
fp16: true
| Metric | Value |
|---|---|
| Training Loss | 3.495 |
| Hardware | Tesla T4 (16GB VRAM) |
| Framework | HuggingFace Transformers + PEFT |
| Experiment Tracking | Weights & Biases |
| Validation Loss : 3.5716 | |
| Perplexity : 35.58 | |
| Latency : 1.36 sec | |
| Tokens/sec : 36.78 |
git clone https://github.com/kriish446/pythia-160m-lora.git
cd pythia-160m-lora
pip install -r requirements.txt
python scripts/prepare_data.py --output_dir data/processed
python scripts/train.py --config configs/training_config.yaml
from src.model.inference import LoRAInference
model = LoRAInference.from_pretrained("outputs/final_model")
output = model.generate("Once upon a time", max_new_tokens=50)
print(output)
python scripts/evaluate.py --model_path outputs/final_model --split validation
pythia-160m-lora/
βββ configs/ # YAML configuration files
β βββ training_config.yaml # Training hyperparameters
β βββ lora_config.yaml # LoRA adapter configuration
β βββ data_config.yaml # Dataset configuration
βββ src/
β βββ data/ # Data loading & processing
β β βββ __init__.py
β β βββ dataset_loader.py # Loads all 10 datasets
β β βββ preprocessor.py # Tokenization & formatting
β β βββ data_collator.py # Batching utilities
β βββ model/ # Model definition
β β βββ __init__.py
β β βββ lora_model.py # LoRA model setup
β β βββ inference.py # Inference utilities
β βββ training/ # Training loop
β β βββ __init__.py
β β βββ trainer.py # Custom trainer
β β βββ callbacks.py # W&B, checkpointing callbacks
β βββ evaluation/ # Evaluation metrics
β β βββ __init__.py
β β βββ metrics.py # Perplexity, loss metrics
β βββ utils/ # Shared utilities
β βββ __init__.py
β βββ logger.py
β βββ helpers.py
βββ scripts/ # Runnable entry points
β βββ prepare_data.py
β βββ train.py
β βββ evaluate.py
βββ notebooks/ # Jupyter exploration
β βββ 01_data_exploration.ipynb
β βββ 02_model_inference.ipynb
βββ tests/ # Unit & integration tests
β βββ test_data.py
β βββ test_model.py
β βββ test_training.py
βββ docs/ # Extended documentation
β βββ training_details.md
βββ .github/
β βββ workflows/
β βββ ci.yml # GitHub Actions CI
βββ requirements.txt
βββ setup.py
βββ .gitignore
βββ LICENSE
All runs are tracked with Weights & Biases. To view:
wandb login
# Metrics are auto-logged during training
Key tracked metrics:
train/loss per step and epocheval/loss per epocheval/perplexity# Set seed for reproducibility
export PYTHONHASHSEED=42
# Full pipeline
python scripts/prepare_data.py
python scripts/train.py --config configs/training_config.yaml --seed 42
python scripts/evaluate.py --model_path outputs/final_model
pytest tests/ -v --tb=short
This project is licensed under the MIT License. See LICENSE for details.
Causal Language Model fine-tuned with LoRA (PEFT) on a diverse 41K-sample corpus spanning news, reviews, stories, sentiment, and encyclopedic text.
This project fine-tunes EleutherAI/Pythia-160M using Low-Rank Adaptation (LoRA) for causal language modeling. By combining 10 diverse text datasets, the model develops robust next-token prediction capabilities across multiple domains β from news articles to tweet sentiment β without modifying base model weights.
LoRA inserts trainable low-rank matrices into the transformer's attention layers, drastically reducing trainable parameters (from ~160M to ~300k) while retaining the expressiveness of the full model. This enables fine-tuning on a single Tesla T4 GPU in under 12 minutes(725 seconds).
EleutherAI/Pythia-160M (frozen)
β
βΌ
LoRA Adapters (r=8)
βββββββββββββββββββββββ
β q_proj β rank-8 β
β v_proj β rank-8 β
β alpha = 16 β
β dropout = 0.05 β
βββββββββββββββββββββββ
β
βΌ
Causal LM Head
| Parameter | Value |
|---|---|
| Base Model | EleutherAI/Pythia-160M |
| Total Parameters | ~160M |
| Trainable Parameters | ~300k (~0.18%) |
| LoRA Rank | 8 |
| LoRA Alpha | 16 |
| Target Modules | query_key_value |
| # | Dataset | Domain | Samples |
|---|---|---|---|
| 1 | AG News | News Classification | ~4,000 |
| 2 | IMDB | Movie Reviews | ~4,000 |
| 3 | Yelp Review Full | Business Reviews | ~4,000 |
| 4 | WikiText-2 | Wikipedia / Reference | ~4,000 |
| 5 | TinyStories | Short Stories | ~4,143 |
| 6 | Rotten Tomatoes | Movie Criticism | ~4,000 |
| 7 | Emotion | Social Media Emotion | ~4,000 |
| 8 | DBPedia | Encyclopedic Topics | ~4,143 |
| 9 | SST-2 | Sentiment Phrases | ~4,000 |
| 10 | TweetEval Sentiment | Twitter Sentiment | ~5,144 |
Total: 41,430 samples β Train: 37,287 Β· Validation: 4,143
# LoRA
lora_r: 8
lora_alpha: 16
lora_dropout: 0.05
target_modules: ["query_key_value"]
# Training
num_train_epochs: 1
learning_rate: 2e-4
per_device_train_batch_size: 4
gradient_accumulation_steps: 4
effective_batch_size: 16
max_seq_length: 128
fp16: true
| Metric | Value |
|---|---|
| Training Loss | 3.495 |
| Hardware | Tesla T4 (16GB VRAM) |
| Framework | HuggingFace Transformers + PEFT |
| Experiment Tracking | Weights & Biases |
| Validation Loss : 3.5716 | |
| Perplexity : 35.58 | |
| Latency : 1.36 sec | |
| Tokens/sec : 36.78 |
git clone https://github.com/kriish446/pythia-160m-lora.git
cd pythia-160m-lora
pip install -r requirements.txt
python scripts/prepare_data.py --output_dir data/processed
python scripts/train.py --config configs/training_config.yaml
from src.model.inference import LoRAInference
model = LoRAInference.from_pretrained("outputs/final_model")
output = model.generate("Once upon a time", max_new_tokens=50)
print(output)
python scripts/evaluate.py --model_path outputs/final_model --split validation
pythia-160m-lora/
βββ configs/ # YAML configuration files
β βββ training_config.yaml # Training hyperparameters
β βββ lora_config.yaml # LoRA adapter configuration
β βββ data_config.yaml # Dataset configuration
βββ src/
β βββ data/ # Data loading & processing
β β βββ __init__.py
β β βββ dataset_loader.py # Loads all 10 datasets
β β βββ preprocessor.py # Tokenization & formatting
β β βββ data_collator.py # Batching utilities
β βββ model/ # Model definition
β β βββ __init__.py
β β βββ lora_model.py # LoRA model setup
β β βββ inference.py # Inference utilities
β βββ training/ # Training loop
β β βββ __init__.py
β β βββ trainer.py # Custom trainer
β β βββ callbacks.py # W&B, checkpointing callbacks
β βββ evaluation/ # Evaluation metrics
β β βββ __init__.py
β β βββ metrics.py # Perplexity, loss metrics
β βββ utils/ # Shared utilities
β βββ __init__.py
β βββ logger.py
β βββ helpers.py
βββ scripts/ # Runnable entry points
β βββ prepare_data.py
β βββ train.py
β βββ evaluate.py
βββ notebooks/ # Jupyter exploration
β βββ 01_data_exploration.ipynb
β βββ 02_model_inference.ipynb
βββ tests/ # Unit & integration tests
β βββ test_data.py
β βββ test_model.py
β βββ test_training.py
βββ docs/ # Extended documentation
β βββ training_details.md
βββ .github/
β βββ workflows/
β βββ ci.yml # GitHub Actions CI
βββ requirements.txt
βββ setup.py
βββ .gitignore
βββ LICENSE
All runs are tracked with Weights & Biases. To view:
wandb login
# Metrics are auto-logged during training
Key tracked metrics:
train/loss per step and epocheval/loss per epocheval/perplexity# Set seed for reproducibility
export PYTHONHASHSEED=42
# Full pipeline
python scripts/prepare_data.py
python scripts/train.py --config configs/training_config.yaml --seed 42
python scripts/evaluate.py --model_path outputs/final_model
pytest tests/ -v --tb=short
This project is licensed under the MIT License. See LICENSE for details.