MiniGPT / README.md
mrshibly's picture
Upload README.md with huggingface_hub
1c92cd0 verified
|
Raw History Blame Contribute Delete
2.78 kB
---
title: MiniGPT-from-Scratch
emoji: πŸš€
colorFrom: indigo
colorTo: purple
sdk: gradio
sdk_version: 5.16.2
app_file: app.py
pinned: false
---
# MiniGPT-from-Scratch πŸš€
A from-scratch implementation of a decoder-only Transformer (GPT) language model, built in 30 days. This project is designed as a deep-dive into LLM engineering, following the architecture of GPT-2.
## 🌟 Features
- **Custom BPE Tokenizer**: Fully trained on the dataset using Hugging Face `tokenizers`.
- **GPT Architecture**: Multi-head causal self-attention, GELU MLPs, LayerNorm (Pre-Norm), and residual connections.
- **Optimized Training**: Supports PyTorch AMP (Mixed Precision), Cosine Decay with Warmup, and weight tying.
- **Interactive Demo**: Built-in Gradio web app for real-time text generation.
- **Evaluation**: Integrated perplexity calculation for model benchmarking.
## πŸ› οΈ Tech Stack
- **Language**: Python 3.10+
- **Deep Learning**: PyTorch
- **Tokenization**: Hugging Face Tokenizers
- **Interface**: Gradio
- **Data**: FineWeb-Edu (Sample)
## πŸ“ Project Structure
```text
MiniGPT/
β”œβ”€β”€ data/ # Raw and processed datasets
β”œβ”€β”€ notebooks/ # Colab/Kaggle training templates
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ datasets/ # Data loading and preprocessing logic
β”‚ β”œβ”€β”€ model/ # Transformer architecture (GPT, Attention, Blocks)
β”‚ β”œβ”€β”€ tokenizer/ # BPE training and wrapper
β”‚ β”œβ”€β”€ train/ # Training loop with AMP and validation
β”‚ └── app.py # Gradio Web Demo
β”œβ”€β”€ checkpoints/ # Saved model weights (.pt)
└── requirements.txt # Project dependencies
```
## πŸš€ How to Use
### 1. Setup
```bash
git clone https://github.com/mrshibly/MiniGPT-from-Scratch.git
cd MiniGPT-from-Scratch
pip install -r requirements.txt
```
### 2. Preprocess Data
```bash
python src/datasets/download_fineweb.py
python src/datasets/clean_text.py
python src/tokenizer/train_tokenizer.py
python src/datasets/prepare_data.py
```
### 3. Train
To train locally (CPU/GPU):
```bash
python src/train/train.py
```
*Note: For full 50M training, use the [Colab Template](notebooks/Colab_Training_Template.ipynb).*
### 4. Interactive Demo
Once you have a checkpoint in `checkpoints/ckpt.pt`:
```bash
python src/app.py
```
## πŸ“Š Model Configurations
| Config | Params | Layers | Heads | d_model |
|--------|--------|--------|-------|---------|
| Tiny | ~7M | 4 | 4 | 256 |
| Standard| ~50M | 6 | 8 | 512 |
## πŸ“Š Latest Training Benchmarks
- **Dataset**: 500MB FineWeb-Edu
- **Parameters**: 27.54 Million
- **Validation Loss**: 4.8415
- **Perplexity**: 126.65
- **Status**: Successfully generating coherent English-like sentences.
## πŸ“„ License
MIT