| # π MiniGPT from Scratch | |
|  | |
|  | |
|  | |
| A decoder-only GPT implementation built completely from scratch using PyTorch. | |
| This project was created as part of my journey to understand how modern Large Language Models work internally instead of simply using existing libraries. | |
| --- | |
| # Features | |
| - β Character-level Tokenizer | |
| - β Token Embeddings | |
| - β Positional Embeddings | |
| - β Multi-Head Self Attention | |
| - β FlashAttention (`scaled_dot_product_attention`) | |
| - β Feed Forward Network (MLP) | |
| - β Residual Connections | |
| - β Layer Normalization | |
| - β Decoder-only GPT Architecture | |
| - β Autoregressive Text Generation | |
| - β Top-K Sampling | |
| - β Top-P (Nucleus) Sampling | |
| - β Temperature Sampling | |
| --- | |
| # Architecture | |
| ``` | |
| Input Tokens | |
| β | |
| βΌ | |
| Token Embedding | |
| β | |
| βΌ | |
| Position Embedding | |
| β | |
| βΌ | |
| Transformer Block Γ 4 | |
| β | |
| βΌ | |
| LayerNorm | |
| β | |
| βΌ | |
| Linear Head | |
| β | |
| βΌ | |
| Vocabulary Logits | |
| β | |
| βΌ | |
| Next Token | |
| ``` | |
| --- | |
| # Project Structure | |
| ``` | |
| MiniGPT-from-Scratch/ | |
| βββ model.py | |
| βββ train.py | |
| βββ generate.py | |
| βββ utils.py | |
| βββ config.py | |
| βββ requirements.txt | |
| βββ notebook/ | |
| βββ checkpoints/ | |
| βββ outputs/ | |
| βββ images/ | |
| βββ data/ | |
| ``` | |
| --- | |
| # Dataset | |
| Tiny Shakespeare | |
| https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txt | |
| --- | |
| # Training | |
| ```bash | |
| python train.py | |
| ``` | |
| --- | |
| # Generate Text | |
| ```bash | |
| python generate.py | |
| ``` | |
| --- | |
| # Sample Output | |
| ``` | |
| FANH: | |
| A Prusjortus: | |
| Weath the too, | |
| eyes glorls cobsuess fewn. | |
| ``` | |
| --- | |
| # Future Work | |
| - KV Cache | |
| - Mixed Precision | |
| - LoRA Fine-tuning | |
| - Beam Search | |
| - HuggingFace Integration | |
| - Distributed Training | |
| - Triton Kernels | |
| --- | |
| # Author | |
| Built with β€οΈ while learning PyTorch Internals and Transformer Architecture. | |