YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

πŸš€ MiniGPT from Scratch

Python PyTorch License

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

python train.py

Generate Text

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.

Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support