Setup Guide
Resources & Environment Setup
Everything you need before starting Module 1: tools, hardware, data, and verified links to all course materials.
Setup Checklist
- ROCm installed and verified with
rocm-smi - GHC 9.4+ and Cabal installed via
ghcup - Rust installed via
rustup - Shakespeare corpus downloaded (
data/shakespeare.txt, ~5.4 MB) - Project structure created and
cabal buildsucceeds - Rust GPU code compiles:
cargo build --release - Can run a hello-world in GHCi
- GPU seated and powered; sufficient VRAM (8GB+ recommended)
- ~50GB free disk space
Hardware Requirements
| Configuration | Minimum | Recommended |
|---|---|---|
| GPU | AMD RDNA 2/3 (RX 6700+), 8GB VRAM | RX 6800 XT or MI100, 16GB VRAM |
| System RAM | 8 GB | 16 GB+ |
| Storage | 50 GB | 100 GB SSD |
| OS | Ubuntu 20.04+ / Fedora 34+ | Same |
CPU-only training is possible but ~50–100× slower. The Shakespeare small model would take weeks per epoch instead of minutes.
Step 1: Install ROCm
Bash — Ubuntu / Debian
wget -q -O - https://repo.radeon.com/rocm/rocm.gpg.key | sudo apt-key add -
echo 'deb [arch=amd64] https://repo.radeon.com/rocm/apt/ubuntu focal main' \
| sudo tee /etc/apt/sources.list.d/rocm.list
sudo apt update
sudo apt install -y rocm-dkms rocm-libs rocm-hipclang rocm-cmake
sudo usermod -a -G video $USER # Log out and back in after this
# Verify
rocm-smi
hipcc --version
Bash — Fedora
sudo dnf install rocm-hip rocm-smi rocm-cmake
rocm-smi # Verify
Step 2: Install Haskell (GHC + Cabal)
Bash
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
source ~/.ghcup/env # Or restart your shell
ghc --version # Recommended: 9.4.5+
cabal --version
Sample cabal project template
llm.cabal
cabal-version: 2.4
name: llm-from-scratch
version: 0.1.0.0
library
exposed-modules: Math, Layer, Transformer, Optimizer
build-depends: base >=4.16 && <5,
array, hmatrix, vector,
random, bytestring, binary
hs-source-dirs: src
ghc-options: -Wall -O2 -fllvm
executable llm-train
main-is: Main.hs
build-depends: base >=4.16 && <5, llm-from-scratch, time
hs-source-dirs: app
ghc-options: -Wall -O2 -threaded -rtsopts -with-rtsopts=-N
Step 3: Install Rust
Bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
rustc --version
cargo --version
# Create GPU kernel library
cargo new --lib llm-hip-kernels
Cargo.toml
[package]
name = "llm-hip-kernels"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"] # Shared library for Haskell FFI
Step 4: Download Shakespeare Corpus
Bash
mkdir -p data
wget https://raw.githubusercontent.com/brunoklein99/deep-learning-notes/master/shakespeare.txt \
-O data/shakespeare.txt
# Verify (~5.4 MB)
wc -c data/shakespeare.txt
head -20 data/shakespeare.txt
Troubleshooting
| Problem | Likely cause | Fix |
|---|---|---|
rocm-smi shows no devices |
Driver issue | sudo apt install --reinstall rocm-dkms && sudo reboot |
| GPU at 0% during training | Using CPU fallback | Verify hipcc --version works; check FFI linkage |
| Out of memory during training | Batch too large | Reduce microBatchSize; enable gradient checkpointing |
| Haskell stack overflow at compile | GHC default stack | export HSTACKSIZE=256m && cabal build |
| Missing Haskell dependencies | Stale index | cabal update && cabal clean && cabal build |
Complete Paper List
Foundational (read in order)
Learning Representations by Back-Propagating Errors (1986)
doi.org/10.1038/323533a0
Long Short-Term Memory (1997)
MIT Press
Attention Is All You Need (2017)
arxiv.org/abs/1706.03762
Language Models are Unsupervised Multitask Learners (GPT-2, 2019)
PDF
Language Models are Few-Shot Learners (GPT-3, 2020)
arxiv.org/abs/2005.14165
Training Compute-Optimal Large Language Models (Chinchilla, 2022)
arxiv.org/abs/2203.15556
Supplementary papers
Adam: A Method for Stochastic Optimisation (2014)
arxiv.org/abs/1412.6980
An Overview of Gradient Descent Optimisation Algorithms (2016)
arxiv.org/abs/1609.04747
On the Difficulty of Training RNNs (2001)
arxiv.org/abs/1211.1541
Neural Machine Translation by Jointly Learning to Align and Translate (2014)
arxiv.org/abs/1409.0473
Scaling Laws for Neural Language Models (2020)
arxiv.org/abs/2001.08361
Root Mean Square Layer Normalisation (2019)
arxiv.org/abs/1910.07468
GLU Variants Improve Transformer (2020)
arxiv.org/abs/2002.05202
RoFormer: Enhanced Transformer with Rotary Position Embedding (2021)
arxiv.org/abs/2104.09864
Longformer: The Long-Document Transformer (2020)
arxiv.org/abs/2004.05150
LLM.int8(): 8-bit Matrix Multiplication for Transformers (2022)
arxiv.org/abs/2208.07339
Training Language Models to Follow Instructions (InstructGPT, 2022)
arxiv.org/abs/2203.02155
Automatic Differentiation in Machine Learning: A Survey (2018)
arxiv.org/abs/1502.05767
Books
Introduction to Linear Algebra (5th ed.)
math.mit.edu/~gs/linearalgebra/
Neural Networks and Deep Learning (free online)
neuralnetworksanddeeplearning.com
Deep Learning
deeplearningbook.org
Mathematics for Machine Learning (free PDF)
mml-book.github.io
Video series
MIT 18.06 Linear Algebra
YouTube playlist
3Blue1Brown — Neural Networks
YouTube playlist
Stanford CS231n — CNNs for Visual Recognition
cs231n.stanford.edu
Stanford CS224n — NLP with Deep Learning
web.stanford.edu/class/cs224n/
Yannic Kilcher — Paper Explanations
Particularly: "Attention Is All You Need" and BERT explainers.
YouTube channel
Blogs & interactive
The Illustrated Transformer
jalammar.github.io/illustrated-transformer/
Chris Olah's Blog
Understanding LSTMs, Backpropagation, Functional Programming & NNs.
colah.github.io
Lil'Log (Lilian Weng)
Attention, policy gradients, meta-learning — deep technical content.
lilianweng.github.io
The Annotated Transformer
nlp.seas.harvard.edu
nanoGPT
github.com/karpathy/nanoGPT