Week 24 • Day 4Week 24

Day 4:Mock Interview #2 — ML, Deep Learning & Fine-Tuning Math

Battle-tested daily lesson note • 100% runnable code, interview Q&A, test suite & interactive quiz

Day 4: Mock Interview #2 — ML, Deep Learning & Fine-Tuning Math

1. Overview: First-Principles Mathematical Grill

Principal AI Engineers understand the exact calculus, linear algebra, and probability distributions that govern foundation models:

  1. Scaled Dot-Product Attention: Attention⁡(Q,K,V)=softmax⁡(QKTdk)V\operatorname{Attention}(Q, K, V) = \operatorname{softmax}\left( \frac{Q K^T}{\sqrt{d_k}} \right) V Why divide by dk\sqrt{d_k}? Preventing dot products from growing large in magnitude, which pushes the softmax function into regions with near-zero gradients (vanishing gradient problem).
  2. FlashAttention Math:
    • Tiling and online softmax computation: mnew=max⁡(mprev,x),dnew=dprevemprev−mnew+ex−mnewm_{\text{new}} = \max(m_{\text{prev}}, x), \quad d_{\text{new}} = d_{\text{prev}} e^{m_{\text{prev}} - m_{\text{new}}} + e^{x - m_{\text{new}}}
    • Fuses memory transfers from high-latency HBM into fast on-chip SRAM cache.
  3. LoRA Matrix Factorization: W=W0+αrBAW = W_0 + \frac{\alpha}{r} B A
  4. Direct Preference Optimization (DPO):
    • Closed-form analytical substitution of the Bradley-Terry preference objective: LDPO(θ;πref)=−log⁡σ(βlog⁡πθ(yw∣x)πref(yw∣x)−βlog⁡πθ(yl∣x)πref(yl∣x))\mathcal{L}_{\text{DPO}}(\theta; \pi_{\text{ref}}) = -\log \sigma \left( \beta \log \frac{\pi_\theta(y_w \mid x)}{\pi_{\text{ref}}(y_w \mid x)} - \beta \log \frac{\pi_\theta(y_l \mid x)}{\pi_{\text{ref}}(y_l \mid x)} \right)

In Simple English: Crushing Interview Round 2 (Attention, LoRA, NF4 & DPO Explained Out Loud)

When an interviewer asks you to write or explain AI math on the whiteboard, always follow the 2-Part Golden Pattern:

  1. Start with a 1-sentence Plain-English Intuition: "Scaling Attention by $1/\sqrt{d_k}$ stops dot-product scores from exploding in high dimensions, which would freeze Softmax gradients at zero."
  2. Prove it with tiny clean numbers or 5 lines of code: Explain Softmax Saturation, LoRA's W0+αrBAW_0 + \frac{\alpha}{r}BA rank decomposition, Online Softmax (FlashAttention streaming max and sum), and DPO winner-vs-loser margin loss!

Live Math-in-Code Drill: Run mock_interview_2_ml_math.py and its unit tests in Tab 2 (Codes) & Tab 4 (Test & Troubleshooting) directly in your browser!