LLM From Scratch in PyTorch

This project implements a small GPT-style language model from the ground up in PyTorch. It covers tokenization, token and positional embeddings, masked self-attention, transformer blocks, next-token training, checkpointing, and autoregressive text generation.

The goal was to understand and build the internals of a language model without relying on high-level model APIs, making the implementation clear, inspectable, and easy to extend.

Technical Scope

  • Masked self-attention
  • Transformer blocks
  • Next-token prediction
  • Autoregressive generation
  • PyTorch training loop and checkpointing

GitHub