Numerical Stability

Floating point is a leaky abstraction. It will bite you during training, and you will not see it coming.

Build 2 hr Python

Prerequisites: Phase 1, Lessons 01-04

#Learning Objectives

  • Implement numerically stable softmax and log-sum-exp using the max-subtraction trick
  • Identify overflow, underflow, and catastrophic cancellation in floating-point computations
  • Verify analytical gradients against numerical gradients using centered finite differences
  • Explain why bfloat16 is preferred over float16 for training and how loss scaling prevents gradient underflow
Full Access lesson

Keep going. The rest of this lesson is one step away.

Unlock all 503 lessons, video, code, quizzes and every future update. Pay in your own currency with Paystack.

The text and code of this lesson are based on AI Engineering from Scratch by Rohit Ghumare, MIT licensed.