Skip to content

Build a modern LLM from scratch. Every line commented. Explained like we are five.

use cpu torch by defeault

raiyanyahya3ae628a2fcca
diff --git a/.gitignore b/.gitignore
index 73a2c31..47ab1e2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,5 @@
.ipynb_checkpoints/
checkpoints/
+__pycache__/
+*.pyc
+loss_curve.png
diff --git a/README.md b/README.md
index 32a1388..306c8da 100644
--- a/README.md
+++ b/README.md
@@ -119,8 +119,8 @@ python -m venv gpt_env
source gpt_env/bin/activate # Mac/Linux
# gpt_env\Scripts\activate # Windows
-# 3. Install dependencies
-pip install torch tiktoken datasets numpy matplotlib
+# 3. Install dependencies (CPU version — for GPU see below)
+pip install torch tiktoken datasets numpy matplotlib --index-url https://download.pytorch.org/whl/cpu
# 4. Verify GPU (optional but recommended)
python -c "import torch; print(f'CUDA: {torch.cuda.is_available()}')"
@@ -158,7 +158,7 @@ We're going to run this whole project on a very small dataset so you can watch t
```bash
# Install everything you need
-pip install jupyter tiktoken torch numpy datasets matplotlib
+pip install jupyter tiktoken torch numpy datasets matplotlib --index-url https://download.pytorch.org/whl/cpu
# Start with chapter 2 (tokenization)
jupyter notebook notebooks/02_tokenization.ipynb
diff --git a/chapters/01_setup.md b/chapters/01_setup.md
index 58957e2..fcf09b6 100644
--- a/chapters/01_setup.md
+++ b/chapters/01_setup.md
@@ -69,17 +69,17 @@ source gpt_env/bin/activate # Mac/Linux
# gpt_env\Scripts\activate # Windows
# Step 3: Install PyTorch (choose the right one)
-# For NVIDIA GPU (CUDA 11.8):
-pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
-
-# For NVIDIA GPU (CUDA 12.1 - newer cards like RTX 40 series):
-# pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
+# For CPU only (default, works everywhere):
+pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
# For Apple Silicon (M1/M2/M3):
# pip install torch torchvision torchaudio
-# For CPU only:
-# pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
+# For NVIDIA GPU (CUDA 11.8):
+# pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
+
+# For NVIDIA GPU (CUDA 12.1 - newer cards like RTX 40 series):
+# pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
# Step 4: Install remaining packages
pip install tiktoken datasets numpy matplotlib