Lab file downloads
Every complete script, configuration file and notebook in this course is a real file that you can download and run.
The pages do not contain their own copy of the code. Each page reads the file from disk when the site is built, which means the code you read in a lab and the file you download here are the same bytes. They cannot drift apart, and if a file were ever missing the site would fail to build rather than quietly show you something that does not exist.
How to use these files
Section titled “How to use these files”- Download the file, or use the copy button on the code block in the lab.
- Read the header first. Every file states its purpose, the platform track it was written for, the smallest memory it needs and what it assumes about your setup.
- Run it on the track it names. A script written for the DGX Spark’s aarch64 CUDA stack will not work unchanged on a Mac, and the page says what changes.
- Check the page’s validation line to see whether the file was executed on that track before release, and with which versions.
A word about what these are
Section titled “A word about what these are”These files are written to be read and understood, not to be run blind. Several of them deliberately do things you must not do on a machine you care about: the challenge pages ship broken configurations on purpose so that you can diagnose them, and they say so at the top of the file in capital letters. Read the header before you reuse anything.
Nothing here is a recommendation of a particular model, engine or machine. See the disclaimer.
267 files across 28 parts.
Part 1 — Machine Learning Foundations for LLM Work
labbook-template.mdused in Lab: Your Python Environment and a First Trained Modelplot-curves.pyused in Lab: Your Python Environment and a First Trained Modelreload-mnist.pyused in Lab: Your Python Environment and a First Trained Modelsetup-env-spark.shused in Lab: Your Python Environment and a First Trained Modelsetup-env.shused in Lab: Your Python Environment and a First Trained Modeltrain-mnist-mlx.pyused in Lab: Your Python Environment and a First Trained Modeltrain-mnist.pyused in Lab: Your Python Environment and a First Trained Model
Part 2 — What a Language Model Is
Part 3 — How Models Are Made and Improved
Part 4 — The Open-Weight Model Landscape
Part 5 — Your Hardware: Four Platforms, One Course
bandwidth-test.pyused in Lab: Measure Your Memory Bandwidth and Computematmul-test.pyused in Lab: Measure Your Memory Bandwidth and Computemlx-bandwidth-test.pyused in Lab: Measure Your Memory Bandwidth and Computepredict-decode.pyused in Lab: Measure Your Memory Bandwidth and Computeprepare-mac.shused in Lab: Prepare Your Machineprepare-nvidia.shused in Lab: Prepare Your Machineprepare-spark.shused in Lab: Prepare Your Machineprepare-strix.shused in Lab: Prepare Your Machinerecord-baseline.pyused in Lab: Prepare Your Machinesetup-model-storage.shused in Lab: Prepare Your Machine
Part 6 — First Inference with llama.cpp
bench-reference-models.shused in Lab: Run and Benchmark the Course Reference Modelsbench-to-labbook.pyused in Lab: Run and Benchmark the Course Reference Modelsbuild-llama-cpp.shused in Installing and Building llama.cpp on Your Platformdiagnose-slow-inference.shused in Challenge: The Model That Runs at Two Tokens per Secondkv-memory-ladder.shused in Lab: Run and Benchmark the Course Reference Modelsoffload-split.pyused in Challenge: The Model That Runs at Two Tokens per Secondsummarise-benchmarks.pyused in Lab: Run and Benchmark the Course Reference Models
Part 7 — Ollama, LM Studio and the Desktop Experience
backup-webui.shused in Lab: A Private Chat Service for Your Home Networkcaddy.confused in Lab: A Private Chat Service for Your Home Networkcompose-amd.yamlused in Lab: A Private Chat Service for Your Home Networkcompose-llama-server.yamlused in Lab: A Private Chat Service for Your Home Networkcompose-nvidia.yamlused in Lab: A Private Chat Service for Your Home Networkcompose.yamlused in Lab: A Private Chat Service for Your Home Networkcontext-truncation-test.pyused in Reality Check: 'The Default Context Is Enough'env-example.txtused in Lab: A Private Chat Service for Your Home Networkprobe-lan-exposure.shused in Lab: A Private Chat Service for Your Home Networkstart-webui-native.shused in Lab: A Private Chat Service for Your Home Network
Part 8 — Platform-Native Engines: MLX, TensorRT-LLM and ROCm
compare-engines.pyused in Lab: Same Model, Every Enginefeature-probe.pyused in Lab: Same Model, Every Engineserve-exllamav3.shused in Lab: Same Model, Every Engineserve-lemonade.shused in Lab: Same Model, Every Engineserve-llama-cpp.shused in Lab: Same Model, Every Engineserve-mlx.shused in Lab: Same Model, Every Engineserve-trtllm.shused in Lab: Same Model, Every Engineserve-vllm.shused in Lab: Same Model, Every Enginesummarise-engines.pyused in Lab: Same Model, Every Engine
Part 9 — Serving at Scale: vLLM and SGLang
check-gateway.shused in Project: Your Local Model Gatewaycompose-amd.yamlused in Project: Your Local Model Gatewaycompose-nvidia.yamlused in Project: Your Local Model Gatewaycompose.yamlused in Project: Your Local Model Gatewayenv-example.txtused in Project: Your Local Model Gatewaygateway-template.mdused in Project: Your Local Model Gatewaylitellm-config.yamlused in Project: Your Local Model Gatewayllama-swap.yamlused in Project: Your Local Model Gatewayload-test.pyused in Lab: Serve a Model to Twenty Concurrent Usersserve-llama-parallel.shused in Lab: Serve a Model to Twenty Concurrent Usersserve-vllm-container.shused in Lab: Serve a Model to Twenty Concurrent Usersserve-vllm-native.shused in Lab: Serve a Model to Twenty Concurrent Users, Lab: Serve a Model to Twenty Concurrent Usersstart-gateway-native.shused in Project: Your Local Model Gatewaysummarise-load.pyused in Lab: Serve a Model to Twenty Concurrent Users
Part 10 — Putting Models to Work
ask.pyused in Project: A Private Document Question-Answering Servicecontinue-config.yamlused in Local Coding Assistants: Autocomplete and Chat in Your Editoreval-qa.pyused in Project: A Private Document Question-Answering Serviceingest.pyused in Project: A Private Document Question-Answering Servicejudge.pyused in Lab: Benchmark Local Models on Your Own Tasksqa-questions.jsonused in Project: A Private Document Question-Answering Servicerun-eval.pyused in Lab: Benchmark Local Models on Your Own Taskssample-docs/machine-inventory.mdused in Project: A Private Document Question-Answering Servicesample-docs/model-policy.mdused in Project: A Private Document Question-Answering Servicesample-docs/service-runbook.mdused in Project: A Private Document Question-Answering Serviceserve-qa.pyused in Project: A Private Document Question-Answering Servicestructured-extract.pyused in Structured Output and JSON Modetasks-template.jsonused in Lab: Benchmark Local Models on Your Own Tasks
Part 11 — The Training Toolchain
make-dataset.pyused in Lab: Your First Training Runmerge-and-export.pyused in Lab: Your First Training Runrunlog.pyused in Experiment Tracking and Reproducibilitytrain-sft-mlx.shused in Lab: Your First Training Runtrain-sft.pyused in Lab: Your First Training Run, Lab: Your First Training Run, Lab: Your First Training Runverify-training-step.pyused in Setting Up a Training Environment on Each Platform
Part 12 — Pretraining a Small Model from Scratch
compare-models.pyused in Project: A Domain Micro-Modelcontinue-pretraining.pyused in Project: A Domain Micro-Modeldomain-tasks.jsonused in Project: A Domain Micro-Modelfetch-gutenberg-corpus.shused in Project: A Domain Micro-Modelmake-domain-shards.pyused in Project: A Domain Micro-Modelprepare-data.shused in Lab: Train a 10M to 125M Parameter Model in an Afternoonsample-and-record.pyused in Lab: Train a 10M to 125M Parameter Model in an Afternoontrain-small.shused in Lab: Train a 10M to 125M Parameter Model in an Afternoon
Part 13 — Supervised Fine-Tuning: LoRA, QLoRA and Full Fine-Tunes
decontaminate.pyused in Building an SFT Dataset, Lab: Fine-Tune a 1B to 4B Model to Follow Your Format, Project: A Specialist Assistantdiagnose-fine-tune.pyused in Challenge: The Fine-Tune That Got Worseevaluate-against-base.pyused in Lab: Fine-Tune a 1B to 4B Model to Follow Your Format, Project: A Specialist Assistantexport-gguf.shused in Lab: Fine-Tune a 1B to 4B Model to Follow Your Formatmake-domain-dataset.pyused in Project: A Specialist Assistantmake-format-dataset.pyused in Lab: Fine-Tune a 1B to 4B Model to Follow Your Formatmerge-adapter.pyused in Lab: Fine-Tune a 1B to 4B Model to Follow Your Formatreport-template.mdused in Project: A Specialist Assistantsftlog.pyused in Lab: Fine-Tune a 1B to 4B Model to Follow Your Format, Project: A Specialist Assistanttrain-lora-mlx.shused in Lab: Fine-Tune a 1B to 4B Model to Follow Your Formattrain-lora.pyused in Lab: Fine-Tune a 1B to 4B Model to Follow Your Formattrain-qlora.pyused in Project: A Specialist Assistant
Part 14 — Preference Optimisation and Reinforcement Learning
compare-before-after.pyused in Lab: DPO a Model to Prefer Your Styledistil-baseline.pyused in Reality Check: 'RL Makes Small Models Reason'eval-pass-at-1.pyused in Lab: GRPO on a Maths or Code Task on One Machinemake-preference-pairs.pyused in Lab: DPO a Model to Prefer Your Stylemake-tasks.pyused in Lab: GRPO on a Maths or Code Task on One Machinerewards.pyused in Reward Functions: Maths, Code Tests, Format and Lengthtest-rewards.pyused in Reward Functions: Maths, Code Tests, Format and Lengthtrain-dpo.pyused in Lab: DPO a Model to Prefer Your Styletrain-grpo.pyused in Lab: GRPO on a Maths or Code Task on One Machine
Part 15 — Knowledge Distillation: Big Teacher, Small Student
compare-students.pyused in Lab: Logit Distillation with TRL's Distillation Trainersdiagnose-distillation.pyused in Challenge: The Student That Learned the Teacher's Mistakesdistil-config.yamlused in Project: The Distillation Pipelinedistilabel-pipeline.pyused in Generating Synthetic Data with a Local Teacherdistillog.pyused in Lab: Sequence-Level Distillation of a 30B-Class Teacher into a 4B Studentevaluate-triplet.pyused in Lab: Sequence-Level Distillation of a 30B-Class Teacher into a 4B Studentfilter-and-dedupe.pyused in Lab: Sequence-Level Distillation of a 30B-Class Teacher into a 4B Studentgenerate-teacher-data.pyused in Lab: Sequence-Level Distillation of a 30B-Class Teacher into a 4B Studentmake-seed-prompts.pyused in Lab: Sequence-Level Distillation of a 30B-Class Teacher into a 4B Studentpipeline.pyused in Project: The Distillation Pipelinerejection-sample.pyused in Reasoning Distillation: Teacher Traces as Training Datareport-template.mdused in Project: The Distillation Pipelinetrain-logit-distil.pyused in Lab: Logit Distillation with TRL's Distillation Trainerstrain-student.pyused in Lab: Sequence-Level Distillation of a 30B-Class Teacher into a 4B Student, Lab: Sequence-Level Distillation of a 30B-Class Teacher into a 4B Student, Lab: Sequence-Level Distillation of a 30B-Class Teacher into a 4B Student
Part 16 — Quantisation and Evaluation, Properly
diff-eval-runs.pyused in Challenge: The Benchmark That Liedkl-divergence.pyused in Lab: Quantise Your Fine-Tune Five Ways and Measure Eachmake-imatrix.shused in Lab: Quantise Your Fine-Tune Five Ways and Measure Eachmeasure-quants.pyused in Lab: Quantise Your Fine-Tune Five Ways and Measure Eachmeasure-quants.shused in Lab: Quantise Your Fine-Tune Five Ways and Measure Eachquantise-awq.pyused in Lab: Quantise Your Fine-Tune Five Ways and Measure Eachquantise-five-ways.shused in Lab: Quantise Your Fine-Tune Five Ways and Measure Eachrun-suite.shused in Lab: Run a Standard Benchmark Suite on Your Modelsummarise-results.pyused in Lab: Run a Standard Benchmark Suite on Your Model
Part 17 — Faster Inference: Speculative Decoding, Caching and Draft Models
draftlog.pyused in Lab: Train and Deploy a Draft for Your Modelmake-draft-data.pyused in Lab: Train and Deploy a Draft for Your Modelmeasure-prefix-cache.pyused in Prefix Caching and KV Reusemeasure-speculative.pyused in Lab: Train and Deploy a Draft for Your Model, Speculative Decoding Revisited: Acceptance Rates and When It Paysserve-with-draft.shused in Lab: Train and Deploy a Draft for Your Modeltrain-draft.shused in Lab: Train and Deploy a Draft for Your Model
Part 18 — Beyond One Machine: Parallelism and Networks
compose.yamlused in Lab: Build and Measure Your Cluster Networkenv-example.txtused in Lab: Build and Measure Your Cluster Networkiperf3.Dockerfileused in Lab: Build and Measure Your Cluster Networkmeasure-links.shused in Lab: Build and Measure Your Cluster Networkmount-models.shused in Lab: Build and Measure Your Cluster Networkrecord-topology.pyused in Lab: Build and Measure Your Cluster Networksetup-nfs-server.shused in Lab: Build and Measure Your Cluster Network
Part 19 — Clustering with llama.cpp RPC
diagnose-rpc-cluster.shused in Challenge: The Cluster That Is Slower Than One Machineenv-example.txtused in Lab: Run a Model Bigger Than Any One Machinemeasure-split.pyused in Lab: Run a Model Bigger Than Any One Machineplan-tensor-split.pyused in Lab: Run a Model Bigger Than Any One Machineprobe-rpc-devices.shused in Lab: A Mixed-Platform Cluster, Lab: Run a Model Bigger Than Any One Machinerun-split.shused in Lab: Run a Model Bigger Than Any One Machinestart-rpc-server.shused in Lab: Run a Model Bigger Than Any One Machine
Part 20 — NVIDIA Clusters: DGX Spark Pairs, vLLM Multi-Node and Multi-GPU Desktops
env-example.txtused in Lab: Serve a 400B-Class Model on Two DGX Sparksload-test-pair.shused in Lab: Serve a 400B-Class Model on Two DGX Sparksprepare-spark-pair.shused in Lab: Serve a 400B-Class Model on Two DGX Sparksserve-across-pair.shused in Lab: Serve a 400B-Class Model on Two DGX Sparksserve-single-spark.shused in Lab: Serve a 400B-Class Model on Two DGX Sparksserve-two-cards.shused in Lab: Serve a 400B-Class Model on Two DGX Sparksstart-ray-head.shused in Lab: Serve a 400B-Class Model on Two DGX Sparksstart-ray-worker.shused in Lab: Serve a 400B-Class Model on Two DGX Sparks
Part 21 — Apple Clusters: MLX Distributed and exo over Thunderbolt 5
check-group.pyused in Lab: A Two-Mac Cluster over Thunderbolt 5compare-endpoints.shused in Reality Check: 'Four Mac Studios Replace a GPU Server'cost-inputs-example.jsonused in Reality Check: 'Four Mac Studios Replace a GPU Server'cost-per-million-tokens.pyused in Reality Check: 'Four Mac Studios Replace a GPU Server'env-example.txtused in Lab: A Two-Mac Cluster over Thunderbolt 5exo-placement.pyused in Lab: A Two-Mac Cluster over Thunderbolt 5hosts-example.jsonused in Lab: A Two-Mac Cluster over Thunderbolt 5measure-pair.pyused in Lab: A Two-Mac Cluster over Thunderbolt 5run-distributed.shused in Lab: A Two-Mac Cluster over Thunderbolt 5run-exo.shused in Lab: A Two-Mac Cluster over Thunderbolt 5setup-thunderbolt-bridge.shused in Lab: A Two-Mac Cluster over Thunderbolt 5sharded-generate.pyused in Lab: A Two-Mac Cluster over Thunderbolt 5
Part 22 — Disaggregated Serving: Prefill Machines and Decode Machines
architecture-template.mdused in Project: A Tiered Inference Architecturecompare-disagg.pyused in Lab: Two-Machine Prefill and Decode with vLLMenv-example.txtused in Lab: KV Cache Offload and Sharing, Lab: Two-Machine Prefill and Decode with vLLMllama-cache-tiers.shused in Lab: KV Cache Offload and Sharingmeasure-reuse.pyused in Lab: KV Cache Offload and Sharingmeasurements-example.jsonused in Project: A Tiered Inference Architecturerun-load.shused in Lab: Two-Machine Prefill and Decode with vLLMrun-proxy.shused in Lab: Two-Machine Prefill and Decode with vLLMserve-decode.shused in Lab: Two-Machine Prefill and Decode with vLLMserve-offload.shused in Lab: KV Cache Offload and Sharingserve-prefill.shused in Lab: Two-Machine Prefill and Decode with vLLMserve-shared.shused in Lab: KV Cache Offload and Sharingsummarise-architecture.pyused in Project: A Tiered Inference Architecture
Part 23 — Operating a Local AI Service
alert-rules.yamlused in Lab: Dashboards for Your Clusterbackup-estate.shused in Backup, Upgrades and Reproducibility of a Model Estatecheck-monitoring.shused in Lab: Dashboards for Your Clustercompose-monitoring.yamlused in Lab: Dashboards for Your Clustercost-inputs-example.jsonused in Capacity Planning and Cost per Million Tokens at Homecost-model.pyused in Capacity Planning and Cost per Million Tokens at Homediagnose-oom.pyused in Challenge: The 3 a.m. Out-of-Memoryenv-example.txtused in Lab: Dashboards for Your Clusterestate-manifest.pyused in Backup, Upgrades and Reproducibility of a Model Estategateway-front.confused in Routing and Model Management: llama-swap, LiteLLM, NGINX and Health Checksgrafana-dashboard.jsonused in Lab: Dashboards for Your Clustergrafana-dashboards.yamlused in Lab: Dashboards for Your Clustergrafana-datasource.yamlused in Lab: Dashboards for Your Clustermac-exporter.pyused in Lab: Dashboards for Your Clusterprometheus-config.yamlused in Lab: Dashboards for Your Clusterrocm-exporter.pyused in Lab: Dashboards for Your Clusterupgrade-engine.shused in Backup, Upgrades and Reproducibility of a Model Estate
Part 24 — Tool Calling, MCP and the Agent Loop
agent-tasks.jsonused in Lab: A Minimal Agent from Scratchinjection-test.pyused in Lab: Write and Connect an MCP Server, Safety: Prompt Injection, Tool Permissions and Human-in-the-Loopmcp-client-check.pyused in Lab: Write and Connect an MCP Servermcp-server-readme.mdused in Lab: Write and Connect an MCP Servermcp-server.pyused in Lab: Write and Connect an MCP Servermcpbridge.pyused in Lab: Write and Connect an MCP Serverminimal-agent.pyused in Lab: A Minimal Agent from Scratchtool-call-reliability.pyused in Function Calling End to End on Local Enginestool-prompts.jsonused in Function Calling End to End on Local Enginestoolbox.pyused in Lab: A Minimal Agent from Scratch
Part 25 — Coding Agents on Local Models
agent-sandbox.Dockerfileused in Lab: Sandbox Your Agent: Containers, Permissions and Secretsaider-model-settings.ymlused in Aider with Local Modelsaudit-sandbox.shused in Challenge: The Agent That Escaped the Sandboxboundary-test.shused in Lab: Sandbox Your Agent: Containers, Permissions and Secretscheck-workstation.shused in Project: A Local Agentic Coding Workstationclaude-code-local-settings.jsonused in Claude Code with a Local Endpointcodex-config.tomlused in OpenAI Codex CLI and OpenCode with Local Modelscompose-sandbox.yamlused in Lab: Sandbox Your Agent: Containers, Permissions and Secretscontinue-agent-config.yamlused in Editor Agents: Cline, Kilo Code, Continue and the Proprietary Editorsenv-example.txtused in Lab: Sandbox Your Agent: Containers, Permissions and Secretsgoose-local-env.txtused in Goose and OpenHands: Autonomous Agents and Sandboxinggoose-recipe.yamlused in Goose and OpenHands: Autonomous Agents and Sandboxingopencode.jsonused in OpenAI Codex CLI and OpenCode with Local Modelsrun-agent-task.shused in Lab: One Task, Six Agentssetup-workstation.shused in Project: A Local Agentic Coding Workstationstart-anthropic-server.shused in Claude Code with a Local Endpointsummarise-agent-runs.pyused in Lab: One Task, Six Agentstask-app.pyused in Lab: One Task, Six Agentstask-readme.mdused in Lab: One Task, Six Agentstask-tests.pyused in Lab: One Task, Six Agentsworkstation-aliases.yamlused in Project: A Local Agentic Coding Workstationworkstation-runbook.mdused in Project: A Local Agentic Coding Workstationzed-local-settings.jsonused in Editor Agents: Cline, Kilo Code, Continue and the Proprietary Editors
Part 26 — Building Agent Systems
agent-eval.pyused in Evaluating Agents: Trajectories, Success Rates and Costagent-tasks.jsonused in Evaluating Agents: Trajectories, Success Rates and Costarchitecture-note-template.mdused in Project: A Multi-Agent System on Your Clustermulti-agent-system.pyused in Project: A Multi-Agent System on Your Clusterscaffold-comparison.pyused in Reality Check: 'Agents Are Just Loops'scaffold-minimal.pyused in Reality Check: 'Agents Are Just Loops'scaffold-smolagents.pyused in Reality Check: 'Agents Are Just Loops'
Part 27 — Improving a Model for Your Agents
agent-rewards.pyused in Reinforcement Learning on Agent Tasks: Tests as Rewardsagentlog.pyused in Lab: Fine-Tune a Small Model on Your Own Agent Trajectories and Measure the Gaincollect-trajectories.pyused in Collecting Trajectories from Your Agentscollection-tasks.jsonused in Lab: Fine-Tune a Small Model on Your Own Agent Trajectories and Measure the Gaincompare-agent-models.pyused in Lab: Fine-Tune a Small Model on Your Own Agent Trajectories and Measure the Gainexport-and-alias.shused in Lab: Fine-Tune a Small Model on Your Own Agent Trajectories and Measure the Gainreport-template.mdused in Lab: Fine-Tune a Small Model on Your Own Agent Trajectories and Measure the Gainscrub-trajectories.pyused in Collecting Trajectories from Your Agentstrain-agent-sft.pyused in Fine-Tuning for Tool Use and Your Codebasetrajectories-to-sft.pyused in Collecting Trajectories from Your Agents
Capstone: Build and Defend Your Own Local AI Platform
capstone-rubric.mdused in Capstone Overview and Assessment Criteriacollect-capstone-evidence.pyused in Capstone 6: The Reportdeployment-measurement-template.mdused in Capstone 3: Cluster or Tiered Deploymenthardware-and-model-plan-template.mdused in Capstone 1: Hardware and Model Planinference-service-checklist.mdused in Capstone 2: The Inference Servicemodel-improvement-template.mdused in Capstone 4: Improve a Small Modelreport-template.mdused in Capstone 6: The Reportworkstation-checklist.mdused in Capstone 5: The Agentic Workstation