← Meta Interview Insights

Meta·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Apr 2026

Summary

Verbal technical screen for an ML Engineer role at Meta, focused entirely on transformer fundamentals. Three main topics came up in sequence and the interviewer seemed to want derivations, not just high-level answers.

Questions Asked (5)

Q1

Derive the scaled dot-product attention formula and explain why we divide by the square root of the key dimension.

Technical Trade-offsAlgorithms & Data Structures
Author's notes

I could write out softmax(QK^T / sqrt(d_k))V fine but stumbled explaining the scaling part.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the attention mechanism and its components (queries, keys, values), then derive the scaled dot-product attention formula step by step. Explain the variance argument for scaling by 1/√d_k, and discuss the practical implications for training stability and performance.

Pro tip: Mention that while scaling is crucial for large d_k, some modern architectures use alternative scaling or normalization techniques; showing awareness of these variations demonstrates depth.

1. Define Attention and Components

Introduce queries (Q), keys (K), and values (V) as learned linear projections of input representations. Explain that attention computes a weighted sum of values based on compatibility between queries and keys.

2. Derive Unscaled Attention

Compute compatibility scores as dot products between queries and keys: S = QK^T. Apply softmax to get attention weights: A = softmax(S). The output is A V.

3. Identify the Scaling Issue

Show that if Q and K have independent components with zero mean and unit variance, the dot product q·k has variance d_k. For large d_k, the scores become large in magnitude, pushing softmax into saturated regions with tiny gradients.

4. Introduce Scaling Factor

Divide the dot products by √d_k to normalize the variance to 1. This keeps the softmax inputs in a reasonable range, preventing vanishing gradients and stabilizing training.

5. Discuss Practical Implications

Explain that scaling allows for stable training with larger d_k, which is common in Transformer models. Mention that without scaling, models may fail to converge or require careful initialization and learning rate tuning.

Key Points to Mention

  • Attention as a soft dictionary lookup: queries match keys to retrieve values.
  • Dot product as a similarity measure; softmax converts scores to probabilities.
  • Variance of dot product scales with d_k, leading to large logits and softmax saturation.
  • Scaling by 1/√d_k normalizes variance to 1, maintaining gradients.
  • Empirical evidence: without scaling, training becomes unstable or fails.
  • Alternative approaches: temperature scaling, cosine similarity, or layer normalization.

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

Q2

Walk through every component inside a single transformer block, and explain the difference between pre-norm and post-norm placement.

System DesignTechnical Trade-offs
Author's notes

Covered multi-head attention, residual connections, LayerNorm, and the FFN without issue.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by walking through the transformer block components in order: multi-head self-attention, feed-forward network, residual connections, and layer normalization. Then explain pre-norm vs post-norm by contrasting where layer normalization is placed relative to the sublayers, and discuss the implications for training stability and performance.

Pro tip: Mention that pre-norm is standard in modern large language models like GPT because it enables stable training without warmup, while post-norm, though original, often requires careful learning rate warmup and can be less stable.

1. Describe the core sublayers

Explain that a transformer block contains a multi-head self-attention mechanism and a position-wise feed-forward network, each followed by residual connections and layer normalization.

2. Detail the attention mechanism

Break down multi-head self-attention: linear projections to queries, keys, values; scaled dot-product attention; concatenation of heads; and output projection.

3. Detail the feed-forward network

Describe the FFN as two linear transformations with a ReLU activation in between, typically expanding and then projecting back to the model dimension.

4. Explain residual connections and layer normalization

Discuss how residual connections add the input to the sublayer output, and how layer normalization normalizes activations across the feature dimension.

5. Contrast pre-norm and post-norm

Explain that in pre-norm, layer normalization is applied before each sublayer (LN -> Sublayer -> Residual), while in post-norm, it is applied after the residual addition (Sublayer -> Residual -> LN). Discuss trade-offs: pre-norm improves gradient flow and training stability, especially for deep models, while post-norm can yield better performance in some settings but requires careful initialization and warmup.

Key Points to Mention

  • Multi-head self-attention: parallel attention heads capture different relationships.
  • Feed-forward network: typically expands to 4x model dimension, uses ReLU/GELU.
  • Residual connections: mitigate vanishing gradients and enable deep networks.
  • Layer normalization: stabilizes training by normalizing activations.
  • Pre-norm: LN before sublayer, residual after; better gradient flow, no warmup needed.
  • Post-norm: LN after residual; original transformer, but can be unstable without warmup.

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

Q3

Compare causal and bidirectional attention masking. Where is each actually used?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

Easy one.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining causal and bidirectional attention masking, then compare their computational and representational trade-offs. Finally, map each to its primary use cases, emphasizing why the choice matters for different tasks and architectures.

Pro tip: Mention that causal masking is essential for autoregressive generation to prevent information leakage, while bidirectional masking is used for understanding tasks where full context is available. Also note that some models like T5 use a mix (e.g., encoder bidirectional, decoder causal).

1. Define the two masking types

Explain that causal masking allows each position to attend only to previous positions, while bidirectional masking allows attention to all positions.

2. Compare computational and representational aspects

Discuss how causal masking enforces a triangular attention matrix, which is efficient for sequential generation, while bidirectional masking uses a full matrix, capturing richer context but requiring full sequence input.

3. Identify primary use cases

State that causal masking is used in autoregressive language models (e.g., GPT) for text generation, while bidirectional masking is used in masked language models (e.g., BERT) for understanding tasks like classification.

4. Discuss hybrid architectures

Mention that encoder-decoder models (e.g., T5) use bidirectional masking in the encoder and causal masking in the decoder, combining both for sequence-to-sequence tasks.

5. Highlight trade-offs and implications

Summarize that causal masking enables efficient generation but limits context, while bidirectional masking provides full context but cannot be used for autoregressive generation.

Key Points to Mention

  • Causal masking prevents attending to future tokens, crucial for autoregressive generation.
  • Bidirectional masking allows full attention, beneficial for tasks requiring global context.
  • Computational efficiency: causal masking uses triangular matrices, reducing computation.
  • Use cases: GPT for causal, BERT for bidirectional, T5 for hybrid.
  • Trade-off: causal models are generative but less context-aware; bidirectional models are context-rich but not generative.
  • Implementation: causal masking often via upper triangular mask, bidirectional via no mask or all-ones mask.

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

Q4

Compare different positional encoding schemes, including sinusoidal, learned absolute, relative bias approaches, and rotary encodings. What are the tradeoffs around extrapolating to longer sequences?

Technical Trade-offsSystem Design
Author's notes

This one went longer than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by categorizing positional encoding schemes into absolute (sinusoidal, learned) and relative (bias, rotary), then compare their mechanisms and tradeoffs. Focus on extrapolation to longer sequences, discussing how each scheme generalizes beyond training length and the implications for model performance.

Pro tip: Emphasize that rotary encodings (RoPE) have become the de facto standard for long-context LLMs due to their relative nature and efficient extrapolation, but mention that techniques like YaRN or linear scaling can further enhance them. This shows awareness of current industry practices.

1. Categorize encoding schemes

Briefly classify positional encodings into absolute (sinusoidal, learned) and relative (relative bias, rotary). This sets a clear structure for comparison.

2. Explain each scheme's mechanism

For each type, describe how it encodes position: sinusoidal uses fixed sinusoids, learned uses trainable embeddings, relative bias adds learned biases based on distance, and rotary applies rotation to query/key vectors.

3. Compare tradeoffs in training and inference

Discuss computational cost, parameter efficiency, and compatibility with attention mechanisms. For example, learned absolute requires fixed max length, while relative methods handle variable lengths better.

4. Analyze extrapolation to longer sequences

Evaluate how each scheme performs when sequence length exceeds training length. Sinusoidal can extrapolate but may degrade; learned absolute fails; relative bias and rotary extrapolate better, with rotary showing strong performance.

5. Conclude with practical recommendations

Summarize which schemes are best for long-context applications, mentioning that rotary is widely adopted but may need scaling techniques for extreme lengths.

Key Points to Mention

  • Sinusoidal encodings are parameter-free and allow some extrapolation, but performance drops for very long sequences due to limited frequency resolution.
  • Learned absolute encodings are simple but cannot extrapolate beyond the maximum length seen during training, as they rely on fixed position embeddings.
  • Relative bias approaches (e.g., T5 bias) introduce learned biases based on relative distance, enabling better generalization to longer sequences but adding parameters.
  • Rotary encodings (RoPE) apply rotation matrices to query and key vectors, inherently encoding relative position and showing strong extrapolation, especially with scaling techniques like YaRN.
  • Extrapolation is crucial for deploying models on longer contexts than seen in training; relative methods generally outperform absolute ones.
  • Tradeoffs include computational overhead, memory usage, and ease of implementation; rotary is efficient but may require tuning for very long sequences.

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

Q5

How does dropout behave differently during training versus inference, and why do we scale activations the way we do?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

Inverted dropout scales survivors by 1/(1-p) during training so you don't have to do anything special at inference time.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by contrasting dropout's stochastic behavior during training with its deterministic identity mapping at inference. Then explain the scaling factor (1/(1-p)) as a way to keep expected activations consistent between the two phases, avoiding a train-test mismatch.

Pro tip: Mention that some frameworks use inverted dropout (scaling during training) while others scale at inference; knowing this distinction shows practical experience and awareness of implementation details.

1. Describe dropout during training

Explain that during training, each neuron is independently dropped with probability p, and surviving activations are scaled by 1/(1-p) to maintain the expected sum.

2. Describe dropout during inference

State that at inference, dropout is turned off: all neurons are active and no random dropping occurs, effectively using the full network.

3. Explain the scaling rationale

Justify the scaling: without it, the expected output at inference would be larger by a factor of 1/(1-p) compared to training, causing a shift in activation distributions.

4. Connect to inverted dropout

Note that the common implementation scales during training (inverted dropout), so inference requires no modification, simplifying deployment.

5. Summarize the trade-off

Conclude that this design ensures consistent expected activations, reduces overfitting, and maintains a single inference path without stochasticity.

Key Points to Mention

  • Dropout is a regularization technique that prevents co-adaptation of neurons.
  • During training, activations are scaled by 1/(1-p) to preserve expected magnitude.
  • At inference, dropout is disabled and no scaling is applied (or scaling is already baked in).
  • The scaling ensures that the expected output of a neuron is the same during training and inference.
  • Inverted dropout (scaling during training) is the standard implementation in frameworks like PyTorch and TensorFlow.
  • Without scaling, there would be a train-test discrepancy leading to degraded performance.

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