Topics / Hands-on labs

Hands-on labs

41 runnable notebooks that turn the questions into code you have run yourself. "Open in Colab" runs them on Google's free GPU in your own Google account; nothing runs on this site's server.

0/41labs done
5paths
25 XPper lab

Build an LLM from scratch 0/14

Write every part of a GPT-style model in PyTorch, then pretrain, fine-tune and align it. From Sebastian Raschka's LLMs-from-scratch.

  • PyTorch in one sittingLLMs-from-scratch
    Tensors, autograd and a training loop: the PyTorch you need for everything after it.
  • Text to tokens to embeddingsLLMs-from-scratch
    Tokenise text, build a byte-pair encoding pipeline and a sliding-window data loader.
  • A BPE tokenizer from scratchLLMs-from-scratch
    Train, encode and decode with your own byte-pair encoder.
  • Code self-attentionLLMs-from-scratch
    From simple attention to causal, multi-head attention, one step at a time.
  • Build a GPT modelLLMs-from-scratch
    Assemble layer norm, the feed-forward block, residuals and the full GPT architecture.
  • Pretrain on unlabelled textLLMs-from-scratch
    Training loop, loss curves, decoding strategies and loading pretrained GPT-2 weights.
  • Fine-tune for classificationLLMs-from-scratch
    Turn the GPT model into a spam classifier and measure it.
  • Instruction fine-tuningLLMs-from-scratch
    Format an instruction dataset, fine-tune, then score the responses with another model.
  • LoRA from scratchLLMs-from-scratch
    Add low-rank adapters to the model and fine-tune only those.
  • DPO from scratchLLMs-from-scratch
    Align the instruction model with direct preference optimisation.
  • Llama 3.2 from scratchLLMs-from-scratch
    See what changes from GPT to a modern architecture: RoPE, RMSNorm, SwiGLU, grouped-query attention.
  • Where the FLOPs goLLMs-from-scratch
    Count the compute in a GPT forward pass.
  • KV cache from scratchLLMs-from-scratch
    Add a key-value cache to the GPT model and measure the speed-up.
  • Mixture of experts from scratchLLMs-from-scratch
    Replace the feed-forward block with routed experts.

Applied LLMs, chapter by chapter 0/12

Twelve notebooks from Hands-On Large Language Models, from tokens to RAG to fine-tuning. Built for the free Colab T4 GPU.

  • Your first LLM callsHands-On Large Language Models
    Load an open model and generate text.
  • Tokens and embeddingsHands-On Large Language Models
    Compare tokenizers and explore token, word and contextual embeddings.
  • Look inside a transformerHands-On Large Language Models
    Trace a forward pass, the KV cache and the language-modelling head.
  • Text classification with LLMsHands-On Large Language Models
    Representation models, zero-shot embeddings and generative classifiers.
  • Clustering and topic modellingHands-On Large Language Models
    Embed, reduce, cluster and label documents with BERTopic.
  • Prompt engineering in practiceHands-On Large Language Models
    Prompt components, in-context learning, chaining and reasoning prompts.
  • Chains, memory and agentsHands-On Large Language Models
    Model I/O, memory and a simple ReAct-style agent.
  • Semantic search and RAGHands-On Large Language Models
    Dense retrieval, reranking and a small RAG pipeline.
  • Multimodal modelsHands-On Large Language Models
    CLIP embeddings and a vision-language model that chats about images.
  • Train an embedding modelHands-On Large Language Models
    Contrastive learning and fine-tuning sentence-embedding models.
  • Fine-tune a representation modelHands-On Large Language Models
    Fine-tune BERT for classification, few-shot with SetFit.
  • Fine-tune a generation modelHands-On Large Language Models
    Supervised fine-tuning with QLoRA, then preference tuning with DPO.

Fine-tune and align 0/6

Supervised fine-tuning, LoRA and QLoRA, DPO and ORPO on free Colab GPUs, with LlamaFactory for config-driven training.

  • Fine-tune Llama 3.1 with UnslothLLM Course (mlabonne)
    Fast, memory-efficient supervised fine-tuning on a free Colab GPU.
  • Fine-tune Mistral-7B with QLoRALLM Course (mlabonne)
    Supervised fine-tuning on the free tier with TRL.
  • Preference tuning with DPOLLM Course (mlabonne)
    Improve a supervised fine-tuned model with direct preference optimisation.
  • Single-stage tuning with ORPOLLM Course (mlabonne)
    Combine supervised fine-tuning and preference alignment in one pass.
  • LlamaFactory quickstartLlamaFactory
    Fine-tune with LoRA or QLoRA from a config file or the LlamaBoard web UI, then chat with and export the result.
  • LlamaFactory training recipesLlamaFactory
    Ready-made configs for supervised fine-tuning, reward modelling, PPO, DPO and KTO across 100+ open models.

Quantize, merge and serve 0/8

Shrink models with GPTQ, GGUF and EXL2, merge them, and put them behind an OpenAI-compatible API.

  • Introduction to weight quantizationLLM Course (mlabonne)
    8-bit quantization from first principles, absmax and zero-point.
  • 4-bit quantization with GPTQLLM Course (mlabonne)
    Quantize an open model to run on consumer hardware.
  • GGUF and llama.cppLLM Course (mlabonne)
    Quantize to GGUF for CPU and laptop inference.
  • ExLlamaV2 (EXL2)LLM Course (mlabonne)
    Quantize and run EXL2 models for fast GPU inference.
  • Decoding strategiesLLM Course (mlabonne)
    Greedy, beam search, top-k and nucleus sampling, with code.
  • Merge models with MergeKitLLM Course (mlabonne)
    Combine fine-tuned models without any GPU training.
  • Knowledge graphs for better answersLLM Course (mlabonne)
    Ground a chatbot's answers in a knowledge graph.
  • Serve an OpenAI-style API with LlamaFactory and vLLMLlamaFactory
    Expose a fine-tuned model behind an OpenAI-compatible endpoint.

Agents 0/1

Notebooks that build and evaluate a tool-using agent.

  • Agentic AI: autonomy in actionAwesome Generative AI Guide
    Notebooks that give a support agent actions, then planning, with test cases to evaluate it.

Free courses to go deeper