Setup & Installation
Please complete this page before the first lecture. It should take 15–45 minutes. If anything fails, bring your laptop 15 minutes early on day 1 and we will fix it together.
There are two ways to run the course code. You only need one, but we recommend setting up both, since each is occasionally more convenient:
- Option A — Google Colab (in the browser, nothing to install). Free, works on any laptop including tablets/Chromebooks, and gives you free GPU time that will be handy for training in Steps 6–8.
- Option B — local installation. Everything runs on your own machine. All models in this course are small enough to train on a laptop CPU (slowly) — no GPU required.
Option A: Google Colab
- You need a Google account.
- Go to colab.research.google.com and choose New notebook.
- In the first cell, type
2 + 2, press Shift+Enter, and confirm you get4. That’s a Jupyter notebook: cells of Python you run one at a time. All course materials are distributed as notebooks. - Paste the verification script below into a cell and run it. Everything the course needs (PyTorch, NumPy, matplotlib) is pre-installed on Colab.
- Optional, for Steps 6–8: Runtime → Change runtime type → T4 GPU gives you a free GPU. Re-run the verification script and it should report the GPU.
Colab disconnects idle sessions and wipes their files, so save notebooks to your Google Drive (Colab does this by default) and re-download data files at the top of each notebook — our notebooks always include the download cell.
Option B: local installation
1. Install Python (3.10 or newer)
We recommend Miniforge, a minimal scientific-Python distribution:
- Download the installer for your OS from github.com/conda-forge/miniforge and run it, accepting defaults.
- macOS/Linux alternative: your system Python is fine if
python3 --versionreports ≥ 3.10. - Windows alternative: the official installer from python.org — check “Add python.exe to PATH” during installation.
2. Create an environment for the course
An environment is an isolated set of installed packages, so this course can’t interfere with anything else on your machine. In a terminal (on Windows: the “Miniforge Prompt” from the Start menu):
# with Miniforge/conda:
conda create -n llm-course python=3.11 -y
conda activate llm-course
or, with plain Python:
python3 -m venv llm-course
source llm-course/bin/activate # macOS / Linux
# llm-course\Scripts\activate # Windows
You must re-run the activate line in every new terminal before working on
the course.
3. Install the course packages
pip install torch numpy matplotlib jupyterlab
Notes:
- This installs the CPU version of PyTorch, which is all we need. If you have an NVIDIA GPU or Apple Silicon and want to use it, see pytorch.org/get-started — but don’t spend time on this now; everything works on CPU.
- Total download is ~1–2 GB.
4. Install an editor (recommended)
Visual Studio Code with the Python and
Jupyter extensions (install both from the Extensions sidebar). VS Code
can open and run .ipynb notebooks directly; when it asks for a kernel,
pick the llm-course environment.
If you prefer the browser: run jupyter lab in your activated environment
and it opens a notebook interface at localhost:8888.
5. Download the dataset
Our training corpus for the whole course is the complete works of Shakespeare as a single 1.1 MB text file:
curl -O https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txt
or just download it in your browser
and save it as input.txt in your course folder.
Verify your setup
Run this in a notebook cell (Colab or local Jupyter/VS Code). It checks everything the course needs:
import sys
print("Python:", sys.version.split()[0])
assert sys.version_info >= (3, 10), "Need Python 3.10+"
import torch, numpy, matplotlib
print("PyTorch:", torch.__version__)
print("NumPy:", numpy.__version__)
# A tiny tensor computation with gradients — the engine of the whole course:
x = torch.tensor([1.0, 2.0, 3.0], requires_grad=True)
loss = (x ** 2).sum()
loss.backward()
assert torch.allclose(x.grad, 2 * x.detach())
print("Autograd: OK (d/dx sum(x^2) = 2x ✓)")
device = ("cuda" if torch.cuda.is_available()
else "mps" if getattr(torch.backends, "mps", None)
and torch.backends.mps.is_available()
else "cpu")
print("Compute device:", device, "(cpu is fine for this course)")
print("\nAll good — see you at Lecture 1.")
Expected output ends with All good — see you at Lecture 1. If you get an
error you can’t decipher, email it to the instructor or bring it to class.
Python primer
If you have never written Python: work through the basic Python worksheets (link to your worksheets here) before Lecture 1. You need:
- variables, arithmetic, strings, lists, dictionaries;
forloops andif;- defining and calling functions;
- running cells in a notebook.
That is genuinely all — the project introduces everything else (NumPy arrays, PyTorch tensors, classes) as it is needed, and each construct is explained the first time it appears.
A good self-contained refresher: the official Python tutorial, sections 3–5.
A note on AI assistants
You will be building a small language model while very large ones offer to autocomplete it for you. Our suggestion: turn Copilot/ChatGPT off for the core implementation in each step — the entire point is the friction of translating mathematics into computation yourself — but use them freely for Python syntax questions, error messages, and the “going further” extensions.