Lesson 4.12core2 h 30 min⚡ live demo

Compute, hardware and scale basics

Bytes, FLOPs and bandwidth: the arithmetic behind every training decision

Deep learning is bounded by arithmetic you can do on a napkin: how many bytes a model needs, how many floating-point operations a training run costs, how fast memory can feed the compute. Those three numbers decide whether your project fits on a free Colab GPU, what fine-tuning method you can afford (8.2 Fine-tuning and PEFT), why decoding an LLM is slow (7.10 Efficient inference: KV cache, GQA, FlashAttention, speculative decoding, quantization) and how scaling laws are even possible (7.9 Scaling laws and compute-optimal training). This lesson gives you the formulas and the habit of estimating before launching.

You'll be able to

  • Describe the GPU memory hierarchy and why data movement, not arithmetic, is usually the bottleneck
  • Compute training and inference memory for a model from its parameter count and precision
  • Estimate FLOPs (≈ 6ND for training), wall-clock time and cost from hardware peak throughput and MFU
  • Explain data, tensor, pipeline, expert and ZeRO/FSDP parallelism and when each is used
  • Choose hardware for your own learning projects sensibly

Key ideas

  1. GPUs win because matmul is embarrassingly parallel; the binding constraint today is memory capacity and bandwidth, not arithmetic.
  2. Bytes per value: fp32 4, bf16/fp16 2, fp8/int8 1, int4 0.5; bf16 keeps fp32's range and is the training default.
  3. Mixed-precision training with Adam needs ≈16 bytes per parameter (2 weights + 2 grads + 4 master + 8 Adam) plus activations; a 7B model needs ~112 GB of state.
Show 4 more key ideas
  1. Inference needs 2N bytes in bf16 (14 GB for 7B), N in int8, N/2 in int4, plus the KV cache.
  2. Forward ≈ 2N FLOPs/token, training ≈ 6N FLOPs/token, so C ≈ 6ND; divide by peak × MFU (30–50%) to get wall-clock time.
  3. Arithmetic intensity vs the ridge point (~300 FLOP/byte on H100) decides memory- vs compute-bound; single-stream decoding is memory-bound at ~bandwidth / model bytes tokens per second.
  4. Parallelism ladder: data parallel → ZeRO/FSDP sharding → tensor → pipeline → expert/sequence; learners mostly need one GPU, accumulation, DDP, FSDP.

Suggested path through this lesson