Deep Learning for Production: Transformers, Fine-Tuning and Serving
Who it is for
What you will achieve
Prerequisites
Curriculum
- Step 1: Dropout, Early Stopping and Batch Norm: Judge Each One by the Validation Curve
Three tools that keep a network honest on unseen data, each judged by its validation curve on 150 digit images: early stopping with patience 5, nn.Dropout(0.5), nn.BatchNorm1d, and the batch norm trap that drops a frozen model from 95.8% to 33.6%.
- Step 2: Transfer Learning on Images: A Frozen ResNet-18, a Small Head and an Honest Baseline
Freeze a pretrained ResNet-18 (11,176,512 parameters, 0 trainable) and train a 5,130-weight head on digit images, then compare it with from-scratch models. On this data the borrowed model loses twice, and the baseline is what tells you.
- Step 3: Attention Explained Without the Maths: Query, Key, Value and the Word "it"
Attention without matrices: query, key and value as what a word looks for, offers and passes on, a 10-line NumPy toy where "it" gives 0.62 of its attention to "animal", and why many heads and all-at-once reading made attention win.
- Step 4: Transformer Building Blocks in PyTorch: Follow the Shapes Through Attention and a Block
Build the parts of a transformer in PyTorch and print the shape at every step: one self-attention head, the word-order problem and learned positions, two heads with nn.MultiheadAttention, and a block of 872 numbers that keeps the shape [1, 4, 8] so blocks stack.
- Step 5: Pretrained Models from Hugging Face: A Sentiment Pipeline and Sentence Embeddings on a CPU
Run two pretrained Hugging Face models on six support messages with no training: a sentiment pipeline that calls a polite password question NEGATIVE at 0.9996, and an embedding model that ranks messages by meaning with 384-number vectors.
- Step 6: Loading a Language Model and Running Inference: Download, Load, Tokenize, Generate
Follow SmolLM2-135M from files on disk to words on screen: a 269.1 MB weights file, 134,515,008 parameters in memory, text turned into token ids, the top-5 next tokens after "The capital of France is", and generate with greedy and temperature settings.
- Step 7: Model Size and Memory: Parameters x Bytes, Quantization, and Where to Run a Model
Will this model fit on my machine? One rule, parameters x bytes per number, gives a 7B model 14 GB at 16-bit and 3.5 GB at 4-bit. Then a real measurement of SmolLM2-135M (538 MB vs 269 MB) and the three ways to run a model: hosted API, local, or an inference server.
- Step 8: Training on a GPU: Mixed Precision, Gradient Accumulation and Checkpoints That Really Resume
Make long training runs faster and safer: measured CPU vs GPU vs 16-bit step times on an RTX 4070 Laptop GPU, gradient accumulation that trades time for memory, and a checkpoint that resumes a crashed run to a max weight difference of zero, plus the silent resume that doesn't.
- Step 9: When NOT to Fine-Tune: A Decision Tree of Prompt, RAG, Tools, Then Fine-Tuning
Most teams who ask for fine-tuning need something simpler first. A four-step decision tree (prompt, RAG, tools, then fine-tuning), what fine-tuning really changes, and what it costs, shown on a product assistant that doesn't know its own plans.
- Step 10: Full Fine-Tuning vs LoRA vs QLoRA: What Each One Changes and What It Costs
Three ways to fine-tune a model for a ticket-tagging job on one GPU: full fine-tuning rebuilds every weight, LoRA trains a small add-on A x B next to frozen weights, and QLoRA does LoRA on a 4-bit base. What each changes, what each costs, and which to pick.
- Step 11: LoRA Fine-Tune of a Tiny Model: Teach SmolLM2-135M Your House Style on a CPU
Fine-tune SmolLM2-135M-Instruct with LoRA on 50 support replies, on a laptop CPU: 921,600 trainable parameters (0.68%), loss 4.510 to 1.010 in 80 steps, a 3.7 MB adapter, and replies that pick up the house style but not the facts.
- Step 12: Knowledge Distillation: Teach a Model 100 Times Smaller From a Teacher's Soft Labels
A teacher network with 72,196 numbers teaches a student with 676 through soft labels. On synthetic data over five seeds the student scores 73.8% against the teacher's 76.1%, and 1.2 points above a student that learned alone.
- Step 13: Serving Open Models: Continuous Batching, vLLM and Cold Starts
Why continuous batching cuts the wait (a simulation: 26.6 s mean wait down to 4.2 s), a real vLLM run on a laptop GPU (27 tokens/s one at a time, 429 all at once, a 96-second cold start), and the scale-to-zero vs warm-pool trade.