kriish446/pythia-160m-lora

Python

0

2 commits

updated Jun 21, 2026

See the code

README

🦾 Pythia-160M LoRA Fine-Tuning

Causal Language Model fine-tuned with LoRA (PEFT) on a diverse 41K-sample corpus spanning news, reviews, stories, sentiment, and encyclopedic text.

Python 3.9+ PyTorch Hugging Face PEFT W&B License: MIT


πŸ“Œ Project Overview

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.

Why LoRA?

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).


πŸ—οΈ Architecture

EleutherAI/Pythia-160M (frozen)
         β”‚
         β–Ό
   LoRA Adapters (r=8)
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚  q_proj  ← rank-8   β”‚
   β”‚  v_proj  ← rank-8   β”‚
   β”‚  alpha = 16         β”‚
   β”‚  dropout = 0.05     β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
  Causal LM Head
ParameterValue
Base ModelEleutherAI/Pythia-160M
Total Parameters~160M
Trainable Parameters~300k (~0.18%)
LoRA Rank8
LoRA Alpha16
Target Modulesquery_key_value

πŸ“Š Dataset Composition

#DatasetDomainSamples
1AG NewsNews Classification~4,000
2IMDBMovie Reviews~4,000
3Yelp Review FullBusiness Reviews~4,000
4WikiText-2Wikipedia / Reference~4,000
5TinyStoriesShort Stories~4,143
6Rotten TomatoesMovie Criticism~4,000
7EmotionSocial Media Emotion~4,000
8DBPediaEncyclopedic Topics~4,143
9SST-2Sentiment Phrases~4,000
10TweetEval SentimentTwitter Sentiment~5,144

Total: 41,430 samples β†’ Train: 37,287 Β· Validation: 4,143


βš™οΈ Training Configuration

# 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

Training Results

MetricValue
Training Loss3.495
HardwareTesla T4 (16GB VRAM)
FrameworkHuggingFace Transformers + PEFT
Experiment TrackingWeights & Biases
Validation Loss : 3.5716
Perplexity : 35.58
Latency : 1.36 sec
Tokens/sec : 36.78

πŸš€ Quick Start

1. Installation

git clone https://github.com/kriish446/pythia-160m-lora.git
cd pythia-160m-lora
pip install -r requirements.txt

2. Prepare Data

python scripts/prepare_data.py --output_dir data/processed

3. Train

python scripts/train.py --config configs/training_config.yaml

4. Inference

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)

5. Evaluate

python scripts/evaluate.py --model_path outputs/final_model --split validation

πŸ“ Repository Structure

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

πŸ”¬ Experiment Tracking

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 epoch
  • eval/loss per epoch
  • eval/perplexity
  • Learning rate schedule
  • GPU memory utilization

πŸ“ˆ Reproducing Results

# 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

πŸ§ͺ Running Tests

pytest tests/ -v --tb=short

πŸ“„ License

This project is licensed under the MIT License. See LICENSE for details.


πŸ™ Acknowledgements

kriish446/pythia-160m-lora

Python

0

2 commits

updated Jun 21, 2026

See the code

README

🦾 Pythia-160M LoRA Fine-Tuning

Causal Language Model fine-tuned with LoRA (PEFT) on a diverse 41K-sample corpus spanning news, reviews, stories, sentiment, and encyclopedic text.

Python 3.9+ PyTorch Hugging Face PEFT W&B License: MIT


πŸ“Œ Project Overview

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.

Why LoRA?

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).


πŸ—οΈ Architecture

EleutherAI/Pythia-160M (frozen)
         β”‚
         β–Ό
   LoRA Adapters (r=8)
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚  q_proj  ← rank-8   β”‚
   β”‚  v_proj  ← rank-8   β”‚
   β”‚  alpha = 16         β”‚
   β”‚  dropout = 0.05     β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
  Causal LM Head
ParameterValue
Base ModelEleutherAI/Pythia-160M
Total Parameters~160M
Trainable Parameters~300k (~0.18%)
LoRA Rank8
LoRA Alpha16
Target Modulesquery_key_value

πŸ“Š Dataset Composition

#DatasetDomainSamples
1AG NewsNews Classification~4,000
2IMDBMovie Reviews~4,000
3Yelp Review FullBusiness Reviews~4,000
4WikiText-2Wikipedia / Reference~4,000
5TinyStoriesShort Stories~4,143
6Rotten TomatoesMovie Criticism~4,000
7EmotionSocial Media Emotion~4,000
8DBPediaEncyclopedic Topics~4,143
9SST-2Sentiment Phrases~4,000
10TweetEval SentimentTwitter Sentiment~5,144

Total: 41,430 samples β†’ Train: 37,287 Β· Validation: 4,143


βš™οΈ Training Configuration

# 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

Training Results

MetricValue
Training Loss3.495
HardwareTesla T4 (16GB VRAM)
FrameworkHuggingFace Transformers + PEFT
Experiment TrackingWeights & Biases
Validation Loss : 3.5716
Perplexity : 35.58
Latency : 1.36 sec
Tokens/sec : 36.78

πŸš€ Quick Start

1. Installation

git clone https://github.com/kriish446/pythia-160m-lora.git
cd pythia-160m-lora
pip install -r requirements.txt

2. Prepare Data

python scripts/prepare_data.py --output_dir data/processed

3. Train

python scripts/train.py --config configs/training_config.yaml

4. Inference

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)

5. Evaluate

python scripts/evaluate.py --model_path outputs/final_model --split validation

πŸ“ Repository Structure

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

πŸ”¬ Experiment Tracking

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 epoch
  • eval/loss per epoch
  • eval/perplexity
  • Learning rate schedule
  • GPU memory utilization

πŸ“ˆ Reproducing Results

# 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

πŸ§ͺ Running Tests

pytest tests/ -v --tb=short

πŸ“„ License

This project is licensed under the MIT License. See LICENSE for details.


πŸ™ Acknowledgements