fareedkhan-dev/train-llm-from-scratch

A straightforward method for training your LLM, from downloading data to generating text.

View on GitHub ↗Jump to charts ↓

Summary Information

Updated 29 minutes ago
Added to GitGenius on September 6th, 2026
Created on January 12th, 2025
Open Issues & Pull Requests: 7 (+0)
GitHub issues: Enabled
Number of forks: 1,321
Total Stargazers: 9,561 (+1)
Total Subscribers: 78 (+0)

Repository Insights (GitGenius)

Median issue/PR response: 4.9 days
Mean response time: 106.2 days
90th percentile: 382.8 days
Tracked items: 11

How this project is maintained

Around half of the issues opened in the past year never receive a reply. Only 17% of issues opened in the past year have been closed. Three people close 100% of everything that gets resolved.

Charts & Analytics

Fetching additional details & charts...

Issue Activity (beta)

Open issues: 4
New in 7 days: 0
Closed in 7 days: 0
Avg open age: 153 days
Stale 30+ days: 3
Stale 90+ days: 0

Recent activity

Opened in 7 days: 0
Closed in 7 days: 0
Comments in 7 days: 0
Events in 7 days: 0

Top labels

  • enhancement (1)

Most active issues this week

No issue events were indexed in the last 7 days.

Detailed Description

Train LLM From Scratch is a tutorial and implementation framework that teaches how to build and train a language model end-to-end using PyTorch, from raw text through model alignment.

The project addresses the challenge of understanding how large language models work by implementing a transformer architecture from scratch based on the Attention is All You Need paper. Rather than relying on high-level libraries, all components are written directly in PyTorch, including the transformer blocks, attention mechanisms, and post-training algorithms. The approach walks through the complete pipeline: data preparation, model construction from individual pieces like multi-head attention and MLPs, pretraining on raw text, text generation, and post-training alignment using techniques like supervised fine-tuning, reward modeling, DPO, ORPO, KTO, PPO, and GRPO.

This tool suits students learning how transformers function, developers who want to train small language models on a single GPU, and researchers interested in post-training algorithms. The project explicitly targets different audiences: students get step-by-step explanations with expected outputs, developers get ready-to-run commands and file paths, and researchers can focus on the post-training implementations. The codebase demonstrates training models ranging from million to billion parameter scales on consumer hardware. The documentation site and Streamlit control panel provide interfaces for interacting with trained models.

The project maintains a complete, self-contained implementation where every algorithm is hand-written rather than delegated to external libraries like transformers, trl, or peft. The repository includes a structured progression through seven steps covering the entire training journey, with code organized to support both learning and practical application. Documentation is available both in the README and on a dedicated documentation site, supporting multiple entry points for different user types.