How dipsankadariya/build-llms-from-scratch works
This is a PyTorch learning implementation of a GPT-2-style language model, progressing from text and attention foundations through model construction, pretraining, and fine-tuning. Its principal workflow prepares token sequences, trains a decoder model on unlabeled text, then adapts it for downstream tasks and instruction-style responses. The README also describes pretrained-weight loading, sampling, evaluation, and LoRA. Several capabilities are documented but their notebook implementations were not sampled, so those links rely on README evidence rather than inspected code.
Main entry points: components.py GPT Model · Pretraining on Unlabeled Data.ipynb Pretraining Loop · 05-Finetuning Instruction Tuning · 5.5 Loading pretrained weights from OpenAI.ipynb Weight Loading
Components 19
Text Preparation
- Source Text
the-verdict.txt - Tokenization
01-Tokenization/WorkingWithTextualData.ipynb - Windowed Batches
03-GPT Architecture/components.py
GPT Model
- Attention Mechanisms
02-Attention Mechanism/Attention.ipynb - GPT Architecture
03-GPT Architecture/llm-arch.ipynb - Model Components
03-GPT Architecture/components.py - GPT Model
04- Pretraining/components.py - Text Generation
04- Pretraining/components.py
Pretraining
- Training Data
04- Pretraining/components.py - Pretraining Loop
04- Pretraining/Pretraining on Unlabeled Data.ipynb - Model Evaluation
04- Pretraining/Pretraining on Unlabeled Data.ipynb - Weight Loading
04- Pretraining/5.5 Loading pretrained weights from OpenAI.ipynb - GPT-2 Checkpoint Loader
04- Pretraining/gpt_download.py - Token Conversion
04- Pretraining/utils.py
Fine-Tuning
- Classification Tuning
05-Finetuning/FinetuningForClassification.ipynb - Instruction Tuning
05-Finetuning - Chat Assistant
05-Finetuning
Other components
- Learner
- GPT-2 Weights
Connections 20
- Learner → Source Text: provides text
README.md - Source Text → Tokenization: tokenizes
README.md - Tokenization → Windowed Batches: prepares tokens
README.md - Windowed Batches → Training Data: batches sequences
04- Pretraining/components.py - Learner → Attention Mechanisms: studies attention
README.md - Attention Mechanisms → GPT Architecture: informs model
README.md - GPT Architecture → Model Components: builds from
03-GPT Architecture/components.py - Model Components → GPT Model: implements model
README.md - GPT Model → Text Generation: generates tokens
04- Pretraining/components.py - Training Data → Pretraining Loop: supplies batches
README.md - Pretraining Loop → GPT Model: trains
README.md - Pretraining Loop → Model Evaluation: evaluates
README.md - Weight Loading → GPT-2 Checkpoint Loader: loads parameters
04- Pretraining/gpt_download.py - GPT-2 Checkpoint Loader → GPT-2 Weights: downloads weights
04- Pretraining/gpt_download.py - Weight Loading → GPT Model: transfers weights
README.md - Token Conversion → Text Generation: converts tokens
README.md - GPT Model → Classification Tuning: fine-tunes for labels
README.md - GPT Model → Instruction Tuning: fine-tunes on instructions
README.md - Instruction Tuning → Chat Assistant: enables chat
README.md - GPT Model → Instruction Tuning: adapts with LoRA
README.md