← Microsoft Interview Insights
The derivation itself wasn't too bad once I wrote it out.
Start by deriving the gradient using the chain rule, emphasizing the additive identity term. Then explain how this additive term mitigates vanishing gradients by providing a direct path for gradient flow. Finally, compare pre-norm and post-norm LayerNorm placements, discussing their impact on gradient propagation and training stability.
Pro tip: Connect the mathematical derivation to practical implications: mention that pre-norm often allows training deeper networks without warmup, while post-norm may require careful initialization and learning rate tuning.
Apply the chain rule to y = x + F(x) to get ∂L/∂x = ∂L/∂y · (1 + ∂F/∂x). Clearly state the assumption that F is differentiable.
Highlight that the '1' term ensures a direct gradient path even if ∂F/∂x is small, preventing gradients from vanishing in deep networks.
Define pre-norm (LayerNorm before sublayer) and post-norm (after residual addition). Explain how pre-norm keeps the identity path clean, while post-norm can attenuate gradients due to normalization on the residual sum.
Mention that pre-norm often enables training deeper models without learning rate warmup, whereas post-norm may require warmup and careful initialization.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
Start by comparing the IEEE-754 layouts of FP32, FP16, and BF16 to highlight the range vs precision trade-off, then walk through where overflow/underflow occur in practice (softmax, gradient accumulation, loss), and finally explain mixed-precision training with master weights and dynamic loss scaling, emphasizing how BF16 simplifies the process. Be ready to compute representable ranges and specify which operations stay in FP32.
Pro tip: Mention that BF16 has the same exponent range as FP32, so it rarely needs loss scaling, but its lower precision can hurt convergence for some models—this shows you understand the nuanced trade-offs beyond just 'BF16 is better'.
Explain the bit allocation: FP32 (1 sign, 8 exponent, 23 mantissa), FP16 (1, 5, 10), BF16 (1, 8, 7). Emphasize that FP16 sacrifices range for precision, while BF16 sacrifices precision for range.
Calculate approximate ranges: FP16 max ~65504, min normal ~6.1e-5; BF16 max ~3.4e38, min normal ~1.2e-38. Note that FP16 underflows to zero below ~6e-8 (subnormals) and overflows to inf above 65504.
Discuss operations prone to issues: softmax (large exponentials overflow FP16), gradient accumulation (small gradients underflow), and loss computation (large losses overflow). Mention that these often require FP32.
Describe keeping a master FP32 copy of weights for accurate updates, casting to FP16/BF16 for forward/backward, and using FP32 for reductions and sensitive ops. Highlight that master weights prevent precision loss in updates.
Explain dynamic loss scaling: multiply loss by a scale factor to shift gradients into FP16 range, check for inf/NaN, and adjust scale. Then contrast BF16: no loss scaling needed due to FP32-like range, but lower precision may require other mitigations.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.