internalsGet Pro

Module 09 · Lesson 10 of 11Pro

Training on GPUs: memory, precision and speed

Level
Intermediate
Topic
Neural networks
Reading time
18 min

When you finish this page you can

  1. Estimate the GPU memory a training run needs from its parameter count, optimizer and batch size, and say which part limits the batch.
  2. Train with mixed precision using torch.autocast, choosing bf16, or fp16 with a gradient scaler, for the GPU you have.
  3. Tell whether the data loader or the GPU limits a training step, and fix a waiting GPU with loader workers and pinned memory.
  4. Reach a batch size that doesn’t fit in memory by accumulating gradients, and say what that does and doesn’t change.

Builds on 3 lessons

Start with lesson 414 min
  1. Building a neural network in PyTorch14 min
  2. PyTorch tensors: shapes, axes and operations14 min
  3. Momentum, Adam and modern optimizers17 min

The 45 MB model that filled 16 GB

is our example online store. Sellers choose each product’s category themselves, and some choose wrong. Farah, an ML engineer, is training a network that suggests the category from the product photo. Joseph’s growth team wants it: a coat filed as a pullover never shows up in “similar coats”.

Our biggest sale ever · Black Friday

Flat 50% Off

Pro

Continue reading

Unlock every course, now and later

  • System Design, live
  • AI Engineering, live
  • Data Engineering, live
  • Machine Learning Engineering, live
  • Inference Engineering, coming soon
  • AI Research, coming soon
  • Performance Engineering, coming soon
  • Agent & Harness Engineering, coming soon
  • LLM Fine-tuning, coming soon
  • LLM Pre-training & Post-training, coming soon
  • Reinforcement Learning, coming soon
  • AI Infrastructure & Platform Engineering, coming soon
  • AI Evaluation & Safety, coming soon
  • Forward Deployed Engineering, coming soon
  • Cloud Computing, coming soon
  • DevOps, coming soon

50% off · Annual and Lifetime

BLACKFRIDAY50Applied at checkout

Choose a plan