← Snapchat Interview Insights

Snapchat·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Jul 2026

Summary

Snapchat ML engineer loop, heavy on fundamentals. Five questions and every single one was a proper deep-dive, no warmup fluff. Left feeling like I'd been wrung out.

Questions Asked (5)

Q1

What is the relationship between cross-entropy and KL divergence, and can you derive why cross-entropy equals entropy plus KL divergence?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

I knew the punchline but fumbled the derivation live.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining cross-entropy and KL divergence mathematically, then derive the relationship step-by-step. Emphasize that cross-entropy equals entropy plus KL divergence, and explain the implications for machine learning.

Pro tip: Connect the derivation to practical ML: since entropy is constant for a fixed true distribution, minimizing cross-entropy is equivalent to minimizing KL divergence, which is why cross-entropy is the standard loss for classification.

1. Define the quantities

Define entropy H(p), cross-entropy H(p,q), and KL divergence D_KL(p||q) for discrete distributions p (true) and q (predicted).

2. Write cross-entropy in terms of expectation

Express cross-entropy as H(p,q) = -∑ p(x) log q(x) and entropy as H(p) = -∑ p(x) log p(x).

3. Derive the relationship

Show that H(p,q) = H(p) + D_KL(p||q) by substituting the definition of KL divergence: D_KL(p||q) = ∑ p(x) log(p(x)/q(x)).

4. Explain the implications

Discuss that since H(p) is constant with respect to the model q, minimizing cross-entropy is equivalent to minimizing KL divergence.

5. Connect to ML practice

Mention that this justifies using cross-entropy loss in classification, where p is the true label distribution (often one-hot) and q is the model's predicted probabilities.

Key Points to Mention

  • Definition of entropy, cross-entropy, and KL divergence
  • Mathematical derivation: H(p,q) = H(p) + D_KL(p||q)
  • KL divergence is non-negative and zero if and only if p = q
  • Cross-entropy is not symmetric, while KL divergence is also not symmetric
  • In ML, minimizing cross-entropy is equivalent to minimizing KL divergence when p is fixed
  • For one-hot true labels, entropy is zero, so cross-entropy equals KL divergence

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

How does dropout create a mismatch between training and inference, and what are the practical ways to fix it? When would you use inverted dropout versus Monte Carlo dropout?

Technical Trade-offsSystem Design
Author's notes

Inverted dropout I could explain fine, scaling activations at train time so you don't touch anything at inference.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining the core mismatch: dropout randomly zeroes activations during training, but at inference all neurons are active, causing a scale shift. Then describe the two main fixes: scaling during training (inverted dropout) or scaling during inference (Monte Carlo dropout). Finally, discuss when each is appropriate, emphasizing that inverted dropout is the standard for deterministic inference, while MC dropout is used for uncertainty estimation.

Pro tip: Mention that inverted dropout is the default in frameworks like PyTorch and TensorFlow because it keeps inference efficient and deterministic, but MC dropout is valuable for Bayesian approximation and can be used in production for confidence scores—just be aware of the computational cost.

1. Explain the mismatch

Describe how dropout randomly deactivates neurons during training, but at inference all neurons are active, leading to a different expected output scale. This mismatch can cause degraded performance if not addressed.

2. Present the fixes

Introduce the two common solutions: (1) scaling activations during training by 1/(1-p) (inverted dropout), and (2) scaling during inference by (1-p) (classic dropout). Mention that inverted dropout is now standard.

3. Compare inverted vs. Monte Carlo dropout

Clarify that inverted dropout is used for standard training and deterministic inference, while Monte Carlo dropout keeps dropout active at inference and averages multiple stochastic forward passes to estimate uncertainty.

4. Discuss practical use cases

Explain when to use each: inverted dropout for typical supervised learning where speed and determinism matter; MC dropout for Bayesian deep learning, uncertainty quantification, or when you need confidence intervals.

5. Highlight trade-offs

Mention that MC dropout increases inference time and variance, but provides uncertainty estimates. Inverted dropout is computationally free at inference but doesn't provide uncertainty.

Key Points to Mention

  • Dropout randomly zeroes activations with probability p during training, but not during inference.
  • Without correction, the expected output at inference is larger by a factor of 1/(1-p).
  • Inverted dropout scales activations by 1/(1-p) during training, so no scaling is needed at inference.
  • Classic dropout scales by (1-p) at inference, but is less common now.
  • Monte Carlo dropout keeps dropout on at inference and averages multiple forward passes for uncertainty.
  • Inverted dropout is standard in frameworks; MC dropout is used for Bayesian approximation and uncertainty estimation.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Why do large language models use LayerNorm rather than BatchNorm? What are the implications for variable sequence lengths, micro-batching, and training stability?

Technical Trade-offsSystem Design
Author's notes

This one I felt pretty solid on.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by contrasting the core mechanics of LayerNorm and BatchNorm, emphasizing that LayerNorm normalizes across features per sample while BatchNorm normalizes across the batch. Then, explain how this difference makes LayerNorm inherently suited for sequence models with variable lengths and small batch sizes, and discuss the implications for training stability and distributed training.

Pro tip: Mention that LayerNorm's per-sample normalization avoids cross-sample dependencies, which is crucial for autoregressive generation and handling padding in variable-length sequences. Also, note that BatchNorm's running statistics can be problematic when batch statistics are noisy or when the model is used for inference with different batch sizes.

1. Define Normalization Techniques

Briefly define BatchNorm and LayerNorm, highlighting that BatchNorm computes statistics across the batch dimension for each feature, while LayerNorm computes statistics across the feature dimension for each sample.

2. Address Variable Sequence Lengths

Explain that in NLP, sequences have variable lengths and are often padded. BatchNorm would compute statistics including padding tokens, leading to biased estimates, whereas LayerNorm treats each sequence independently, ignoring padding.

3. Discuss Micro-batching and Small Batch Sizes

Note that training large language models often requires micro-batching due to memory constraints, resulting in small per-device batch sizes. BatchNorm's performance degrades with small batches because statistics are noisy, while LayerNorm is unaffected.

4. Explain Training Stability and Distributed Training

Highlight that LayerNorm provides consistent normalization across different batch sizes and devices, simplifying distributed training. BatchNorm requires synchronization of statistics across devices, which can be complex and unstable.

5. Conclude with Practical Implications

Summarize that LayerNorm is preferred for its robustness to variable lengths, small batches, and distributed settings, making it the standard choice for Transformers and large language models.

Key Points to Mention

  • BatchNorm normalizes across the batch dimension, while LayerNorm normalizes across the feature dimension per sample.
  • Variable sequence lengths and padding make BatchNorm statistics biased and unreliable.
  • Micro-batching leads to small batch sizes, causing high variance in BatchNorm statistics.
  • LayerNorm's per-sample normalization is independent of batch size, ensuring stable training.
  • Distributed training with BatchNorm requires cross-device synchronization, adding complexity and potential instability.
  • LayerNorm is standard in Transformer architectures (e.g., BERT, GPT) due to these advantages.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

Compare SGD, SGD with momentum, and Adam: walk through the update rules, convergence properties, generalization behavior, and how you decide which to use.

Technical Trade-offsAlgorithms & Data Structures
Author's notes

Went through the update rules fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Structure your answer by first defining each optimizer's update rule, then comparing their convergence and generalization properties, and finally explaining how you choose based on problem characteristics. Emphasize practical trade-offs and real-world experience.

Pro tip: Mention that Adam often requires less hyperparameter tuning but can generalize worse than SGD with momentum, so many practitioners use Adam for rapid prototyping and switch to SGD with momentum for final training when squeezing out performance.

1. Define Update Rules

Clearly state the update equations for SGD, SGD with momentum, and Adam, highlighting the key differences such as the use of momentum and adaptive learning rates.

2. Discuss Convergence Properties

Explain how each optimizer converges: SGD has slow convergence but good theoretical guarantees; momentum accelerates convergence; Adam converges quickly but may not always reach the best minimum.

3. Compare Generalization Behavior

Describe how SGD with momentum often generalizes better than Adam due to implicit regularization, while Adam may overfit or find sharper minima.

4. Explain Decision Criteria

Outline factors for choosing an optimizer: problem type, dataset size, computational budget, need for fast prototyping, and desired final performance.

5. Provide Practical Examples

Give examples from your experience where you chose one optimizer over another and the outcomes, demonstrating applied knowledge.

Key Points to Mention

  • SGD update: θ = θ - η∇θJ(θ)
  • Momentum update: v = βv + (1-β)∇θJ(θ); θ = θ - ηv
  • Adam update: m = β1m + (1-β1)∇θJ(θ); v = β2v + (1-β2)(∇θJ(θ))^2; m̂ = m/(1-β1^t); v̂ = v/(1-β2^t); θ = θ - η m̂/(√v̂ + ε)
  • Convergence: SGD slow but stable; momentum faster; Adam fast but may oscillate
  • Generalization: SGD with momentum often better; Adam may require regularization
  • Decision factors: dataset size, model complexity, time constraints, and final performance goals

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q5

Why does PPO use clipping or a KL penalty to constrain policy updates, and how does that stabilize training? What hyperparameters matter most and what are the common failure modes?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

Knew the clipping version better than the KL penalty version.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining the core problem PPO addresses: policy updates that are too large can cause performance collapse. Then describe how clipping and KL penalties constrain updates, and how this stabilizes training by keeping the new policy close to the old one. Finally, discuss key hyperparameters and common failure modes, tying them to practical tuning insights.

Pro tip: Emphasize that PPO's clipping is a first-order approximation of a trust region, and that the KL penalty is an alternative that can be more stable but requires careful tuning. Mention that in practice, clipping is often preferred for its simplicity and robustness.

1. Motivate the need for constrained updates

Explain that in policy gradient methods, large updates can lead to a bad policy that collects poor data, causing a vicious cycle. Constraining updates ensures monotonic improvement.

2. Describe clipping mechanism

Detail how PPO clips the probability ratio between new and old policies to a range [1-ε, 1+ε], removing incentive to move outside this range. This limits the update size.

3. Describe KL penalty alternative

Explain that instead of clipping, one can add a KL divergence penalty to the objective, with a coefficient β. This penalizes large deviations from the old policy.

4. Explain stabilization effect

Discuss how both methods prevent destructive updates, maintain a trust region, and lead to more stable and reliable learning curves.

5. Cover hyperparameters and failure modes

List key hyperparameters: clip range ε, KL coefficient β, learning rate, number of epochs per update, and batch size. Discuss failure modes: too large ε or small β leads to instability; too small ε or large β leads to slow learning; improper learning rate can cause divergence.

Key Points to Mention

  • Importance of trust region and monotonic improvement
  • Clipping objective: L^CLIP = min(r(θ)A, clip(r(θ), 1-ε, 1+ε)A)
  • KL penalty: L = E[L^PG - β * KL(π_old || π_θ)]
  • Hyperparameters: ε (typically 0.1-0.3), β (adaptive or fixed), learning rate, epochs per update (e.g., 10), batch size
  • Failure modes: performance collapse with large updates, slow convergence with overly conservative constraints, sensitivity to learning rate and batch size
  • Practical considerations: clipping is simpler and often default; KL penalty can be more stable but requires tuning β; adaptive KL scheduling

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.