Advanced Topics & Extensions
Ongoing exploration: improved normalisation, activation functions, positional encodings, sparse attention, and quantisation.
12.1 Normalisation Variants
RMSNorm
A simpler alternative to LayerNorm that only normalises by the root mean square, without mean-centring. Used in LLaMA and other modern architectures.
GroupNorm
Normalises within groups of channels — useful in settings where batch size is too small for BatchNorm to be stable.
12.2 Improved Activation Functions
GELU
Gaussian Error Linear Units — a smoother alternative to ReLU, used in GPT-2 and BERT.
SwiGLU
Swish-Gated Linear Unit — used in PaLM, LLaMA, and many other recent LLMs. Replaces the FFN's ReLU with a gated variant.
12.3 Positional Encoding Improvements
RoPE — Rotary Position Embeddings
Rather than adding positional encodings to embeddings, RoPE encodes position by rotating the query and key vectors. Extrapolates better to sequences longer than those seen in training and is used in LLaMA, Mistral, and most modern open models.
Relative Position Biases
An alternative approach: bias the attention logits by a learned function of relative distance rather than absolute position (e.g., ALiBi, T5's relative position bias).
12.4 Sparse Attention
Full self-attention is O(n²) in sequence length. For 1B+ models on long documents this becomes a bottleneck. Sparse attention variants restrict which positions attend to which:
- Local attention — each token attends only to a fixed window of nearby tokens
- Strided attention — attend to every k-th token in addition to nearby ones
- BigBird / Longformer — combine local + global + random attention patterns
12.5 Quantisation
Reduce model size for inference by storing weights in lower precision (8-bit or 4-bit integers). Dramatically reduces memory — a 7B model that needs 14GB at FP16 fits in ~4GB at 4-bit.
Where to Go Next
Next Challenges
- Instruction Fine-Tuning — train the model to follow instructions (RLHF/DPO)
- Multimodal Models — add a vision encoder (ViT) alongside the text model
- Code Generation — pretrain or fine-tune on code data
- Context Extension — use RoPE or ALiBi to extend the context window
- Efficiency — flash attention, quantisation-aware training
Essential Papers to Read Next
Haskell Libraries Worth Exploring
- Grenade — neural network library for Haskell
- HMatrix — numeric linear algebra backed by LAPACK/BLAS
Rust Crates Worth Exploring
- tch-rs — Rust bindings to PyTorch's libtorch
- burn — pure-Rust deep learning framework with ROCm/CUDA/WGPU backends
- candle — HuggingFace's minimal Rust inference framework