← Google Interview Insights

Google·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

Deep technical screen for an ML Engineer role at Google. The whole thing was basically one massive question about Transformers from first principles all the way through to molecular applications. Left feeling like I'd just taken an oral exam on a graduate ML course.

Questions Asked (7)

Q1

Walk through the Transformer architecture in detail, covering the encoder and decoder stack structure, self-attention, cross-attention, and position-wise feed-forward networks.

System DesignTechnical Trade-offs
Author's notes

I started with the encoder side and worked my way through, but I fumbled when they pushed on cross-attention specifically.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start with a high-level overview of the Transformer architecture, then systematically explain the encoder and decoder stacks, self-attention, cross-attention, and feed-forward networks. Use clear analogies and emphasize how each component contributes to the model's ability to handle sequence-to-sequence tasks.

Pro tip: Connect each component to its practical benefits, such as parallelization and handling long-range dependencies, and mention trade-offs like quadratic complexity of self-attention. This shows you understand both theory and real-world implications.

1. High-Level Overview

Introduce the Transformer as a sequence-to-sequence model that relies entirely on attention mechanisms, eliminating recurrence and convolutions. Mention its key advantages: parallelization and capturing long-range dependencies.

2. Encoder Stack

Describe the encoder as a stack of identical layers, each with two sub-layers: multi-head self-attention and position-wise feed-forward network. Explain that each sub-layer has residual connections and layer normalization.

3. Decoder Stack

Explain the decoder stack, also composed of identical layers, but with three sub-layers: masked multi-head self-attention, multi-head cross-attention over encoder outputs, and feed-forward network. Emphasize masking to prevent attending to future tokens.

4. Self-Attention and Cross-Attention

Detail how self-attention computes queries, keys, and values from the same input, while cross-attention uses queries from the decoder and keys/values from the encoder. Explain scaled dot-product attention and multi-head attention.

5. Feed-Forward Networks and Positional Encoding

Describe the position-wise feed-forward network as two linear transformations with a ReLU activation in between, applied identically to each position. Mention positional encodings added to input embeddings to inject sequence order.

Key Points to Mention

  • Scaled dot-product attention formula and why scaling is needed
  • Multi-head attention: multiple representation subspaces
  • Residual connections and layer normalization for training stability
  • Masked self-attention in decoder to prevent information leakage
  • Positional encodings: sinusoidal or learned
  • Complexity: O(n^2) for self-attention, trade-offs with sequence length

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

Q2

Derive the scaled dot-product attention equation and explain the shapes of the key, query, and value matrices. Then explain how multi-head attention extends this.

Technical Trade-offsAlgorithms & Data Structures
Author's notes

Wrote out softmax(QK^T / sqrt(d_k))V and got the shapes right for the most part.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by deriving scaled dot-product attention from first principles, clearly defining the query, key, and value matrices and their shapes. Then explain how multi-head attention extends this by projecting the inputs into multiple subspaces and concatenating the results. Use a concrete example with dimensions to illustrate the shapes and computations.

Pro tip: Emphasize the scaling factor 1/sqrt(d_k) as a variance control mechanism to prevent softmax saturation, and relate multi-head attention to ensemble learning for richer representations.

1. Define Inputs and Shapes

State that for a sequence of length n and model dimension d, the input X has shape (n, d). The query, key, and value matrices are obtained via learned linear projections: Q = X W_Q, K = X W_K, V = X W_V, where W_Q, W_K, W_V have shapes (d, d_k), (d, d_k), and (d, d_v) respectively, yielding Q: (n, d_k), K: (n, d_k), V: (n, d_v).

2. Derive Scaled Dot-Product Attention

Compute attention scores as the dot product of Q and K^T, giving a matrix of shape (n, n). Scale by 1/sqrt(d_k) to stabilize gradients. Apply softmax row-wise to obtain attention weights, then multiply by V to get the output of shape (n, d_v).

3. Explain Multi-Head Attention

Describe how multi-head attention runs h parallel attention heads, each with its own learned projections W_Q^i, W_K^i, W_V^i of shapes (d, d_k), (d, d_k), (d, d_v) where typically d_k = d_v = d/h. Each head produces an output of shape (n, d_v).

4. Combine Heads and Project

Concatenate the outputs of all heads along the feature dimension to get a matrix of shape (n, h * d_v) = (n, d). Apply a final linear projection W_O of shape (d, d) to produce the final output of shape (n, d).

5. Discuss Benefits and Trade-offs

Highlight that multi-head attention allows the model to jointly attend to information from different representation subspaces, improving expressiveness. Mention computational cost: total complexity is O(n^2 d) for both single and multi-head, but multi-head enables parallelization and diverse attention patterns.

Key Points to Mention

  • The scaling factor 1/sqrt(d_k) prevents the dot products from growing too large, which would push the softmax into regions with tiny gradients.
  • Shapes: Q and K have shape (n, d_k), V has shape (n, d_v), attention scores are (n, n), and output is (n, d_v).
  • Multi-head attention uses h independent heads with reduced dimensions d_k = d_v = d/h, allowing each head to focus on different aspects.
  • The outputs of all heads are concatenated and linearly projected to combine information.
  • Computational complexity is O(n^2 d) for both single and multi-head attention, but multi-head adds parallelism and representational diversity.
  • Multi-head attention can be seen as an ensemble of attention mechanisms, similar to multiple filters in CNNs.

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

Q3

Compare sinusoidal and learned positional encodings. How do relative position schemes differ, and what does any of this mean for how the model understands sequence order?

Technical Trade-offsSystem Design
Author's notes

Sinusoidal I know cold.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining sinusoidal and learned positional encodings, highlighting their absolute nature and trade-offs. Then explain relative position schemes, contrasting them with absolute methods. Finally, connect these to how models understand sequence order, emphasizing implications for generalization and efficiency.

Pro tip: Mention that relative schemes like Shaw et al. and T5 are crucial for long sequences and extrapolation, and that modern models like Transformer-XL and DeBERTa use them to achieve state-of-the-art results.

1. Define Sinusoidal and Learned Encodings

Explain that sinusoidal encodings use fixed sine/cosine functions of different frequencies, while learned encodings are trainable embeddings added to inputs. Both are absolute, encoding position independently.

2. Compare Trade-offs

Discuss how sinusoidal encodings generalize to unseen lengths and require no parameters, while learned encodings can adapt to data but may overfit and struggle with longer sequences.

3. Introduce Relative Position Schemes

Describe relative schemes that encode pairwise distances between tokens, such as Shaw et al., Transformer-XL, and T5. Highlight their ability to capture relative order and generalize better.

4. Explain Impact on Sequence Understanding

Connect these encodings to how models process order: absolute encodings provide a global reference, while relative encodings focus on local relationships, affecting tasks like language modeling and translation.

5. Summarize Practical Implications

Conclude with when to use each: sinusoidal for simplicity and extrapolation, learned for flexibility with ample data, and relative for long sequences and tasks requiring relative order.

Key Points to Mention

  • Sinusoidal encodings are parameter-free and allow extrapolation to longer sequences.
  • Learned encodings are trainable but may not generalize beyond training lengths.
  • Relative position schemes encode pairwise distances, improving generalization and efficiency.
  • Examples: Shaw et al. (2018), Transformer-XL, T5, and DeBERTa.
  • Absolute encodings provide a global position signal, while relative encodings emphasize local order.
  • Relative schemes are beneficial for long sequences and tasks like language modeling.

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

Q4

What are the differences between encoder-only, decoder-only, and encoder-decoder Transformer models? How does masking work in autoregressive decoding?

Technical Trade-offsSystem Design
Author's notes

This part actually went well.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining each architecture in terms of its attention pattern and training objective, then contrast their typical use cases and trade-offs. Explain masking as a causal constraint that prevents attending to future tokens, and connect it to autoregressive generation and training efficiency.

Pro tip: Emphasize that masking is not just about preventing information leakage during training but also enables parallel training of autoregressive models, a key insight for system design at scale.

1. Define the three architectures

Briefly describe encoder-only (bidirectional attention, e.g., BERT), decoder-only (causal attention, e.g., GPT), and encoder-decoder (bidirectional encoder + causal decoder, e.g., T5).

2. Compare attention patterns and training objectives

Explain how encoder-only uses full self-attention for masked language modeling, decoder-only uses causal masking for next-token prediction, and encoder-decoder combines both for sequence-to-sequence tasks.

3. Discuss use cases and trade-offs

Highlight that encoder-only excels at understanding tasks, decoder-only at generation, and encoder-decoder at conditional generation; mention computational and latency differences.

4. Explain masking in autoregressive decoding

Describe how a causal mask (upper triangular) ensures each position attends only to previous positions, preventing information leakage during training and enabling parallel training.

5. Connect to inference and system design

Note that during inference, masking is implicit via sequential generation, and discuss how this impacts caching, batching, and latency in production systems.

Key Points to Mention

  • Encoder-only models use bidirectional attention and are trained with masked language modeling (e.g., BERT).
  • Decoder-only models use causal (autoregressive) attention and are trained with next-token prediction (e.g., GPT).
  • Encoder-decoder models combine a bidirectional encoder with a causal decoder, suitable for sequence-to-sequence tasks (e.g., T5, BART).
  • Masking in autoregressive decoding is implemented via a causal mask that sets attention scores to -inf for future positions.
  • Masking enables parallel training of autoregressive models by preventing each position from seeing future tokens.
  • During inference, autoregressive generation is sequential, and masking is handled implicitly by only providing past tokens.

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

Q5

The standard Transformer has O(n²) complexity in sequence length. What approaches exist for scaling to longer sequences, and what trade-offs do they introduce?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

Talked through sparse attention patterns and linear attention approximations.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by acknowledging the quadratic bottleneck and its implications, then categorize approaches into sparse/approximate attention, recurrence/compression, and kernel/low-rank methods. For each category, explain the core idea and discuss trade-offs in terms of complexity, memory, accuracy, and hardware efficiency.

Pro tip: Emphasize that many efficient Transformers trade theoretical complexity for practical speed, and that hardware-aware implementations (e.g., FlashAttention) often matter more than asymptotic improvements. Mention that Google's own work (e.g., Performer, Reformer, BigBird) is highly relevant.

1. Restate the problem and its impact

Briefly explain why O(n²) is a bottleneck: memory and compute grow quadratically, limiting sequence length. Mention that this affects both training and inference.

2. Categorize approaches

Group methods into: (a) sparse/approximate attention (e.g., Longformer, BigBird, Reformer), (b) recurrent/compressive (e.g., Transformer-XL, Compressive Transformer), (c) kernel/low-rank (e.g., Performer, Linformer), and (d) hardware-optimized exact attention (e.g., FlashAttention).

3. Explain each category with examples

For each category, describe the key idea, complexity, and a representative model. For example, sparse attention reduces complexity to O(n) or O(n log n) by attending to a subset of tokens.

4. Discuss trade-offs

For each approach, highlight trade-offs: reduced expressiveness, approximation error, implementation complexity, memory vs. compute trade-offs, and hardware efficiency. Compare to full attention.

5. Conclude with practical recommendations

Summarize that the choice depends on the task, sequence length, and hardware. Mention that hybrid approaches and hardware-aware methods are often preferred in practice.

Key Points to Mention

  • Sparse attention patterns (local, global, random) and their complexity (e.g., O(n√n) or O(n log n))
  • Low-rank and kernel methods (Linformer, Performer) that approximate the attention matrix
  • Recurrence and memory compression (Transformer-XL, Compressive Transformer) to handle long contexts
  • Hardware-optimized exact attention (FlashAttention) that improves constant factors and memory usage
  • Trade-offs: accuracy vs. efficiency, theoretical vs. practical speed, and implementation complexity
  • Google's contributions: Performer, Reformer, BigBird, and their relevance to production systems

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

Q6

Discuss pre-LN versus post-LN placement of LayerNorm in Transformer blocks. How do residual connections, training stability, and initialization interact here?

Technical Trade-offsSystem Design
Author's notes

Pre-LN stabilizes training and is what most modern models use, post-LN is the original paper but can have gradient issues at depth.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining pre-LN and post-LN architectures, then compare their training dynamics, stability, and initialization requirements. Use the residual connection as the central mechanism to explain why pre-LN enables stable training without warmup, while post-LN often needs careful initialization and learning rate warmup. Conclude with practical trade-offs and when each is preferred.

Pro tip: Mention that pre-LN Transformers are easier to train but can underperform post-LN in final quality if not tuned, and that post-LN with proper initialization (e.g., Fixup or T-Fixup) can match pre-LN stability. This shows depth beyond textbook knowledge.

1. Define the architectures

Clearly describe pre-LN (LayerNorm before sublayer) and post-LN (LayerNorm after residual addition) placements, and note that original Transformer used post-LN.

2. Explain residual connection interaction

Discuss how in pre-LN, the residual path is clean and gradients flow directly, while in post-LN, LayerNorm is inside the residual branch, affecting gradient scale.

3. Analyze training stability and initialization

Explain that post-LN requires careful initialization (e.g., smaller weights) and learning rate warmup to avoid divergence, whereas pre-LN is more robust and often needs no warmup.

4. Compare performance and practical trade-offs

Note that pre-LN trains faster and more stably but may have slightly worse final performance; post-LN can achieve better results with more tuning. Mention that many modern models use pre-LN for ease.

5. Conclude with recommendations

Summarize when to choose each: pre-LN for large-scale, resource-constrained training; post-LN when maximum quality is needed and resources for tuning are available.

Key Points to Mention

  • Pre-LN places LayerNorm before the sublayer (attention/FFN), post-LN places it after the residual addition.
  • Residual connections in pre-LN provide an unimpeded gradient path, improving stability.
  • Post-LN requires learning rate warmup and careful initialization (e.g., Xavier, Fixup) to prevent gradient explosion/vanishing.
  • Pre-LN often eliminates the need for warmup and allows higher learning rates.
  • Post-LN can yield better final performance if trained successfully, but is more sensitive to hyperparameters.
  • Many recent large language models (e.g., GPT-3, PaLM) use pre-LN for training stability at scale.

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

Q7

How would you adapt a Transformer to work with molecular data like SMILES strings or molecular graphs? Cover tokenization, stereochemistry, data augmentation, and what training objectives make sense.

System DesignTechnical Trade-offsAdaptability & Ambiguity
Author's notes

This was the curveball I did not see coming.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the molecular representation (SMILES vs. graphs) and the task (property prediction, generation, etc.), then walk through the key adaptations: tokenization, handling stereochemistry, data augmentation, and training objectives. Emphasize trade-offs between sequence-based and graph-based approaches, and connect choices to real-world constraints like data scarcity and compute.

Pro tip: Mention that stereochemistry is often overlooked but critical—use specialized tokens or graph features to encode chirality, and consider 3D conformers when relevant. Also, highlight that augmentation must preserve chemical validity, not just string permutations.

1. Clarify the problem and representation

Ask about the specific task (e.g., property prediction, generation) and whether to use SMILES strings or molecular graphs. This determines the tokenization and model architecture.

2. Tokenization and encoding

For SMILES, use character-level or atom-level tokenization with special tokens for stereochemistry (e.g., @, /, \). For graphs, define node features (atom type, charge, chirality) and edge features (bond type, direction).

3. Handle stereochemistry explicitly

Incorporate stereochemical information via dedicated tokens (SMILES) or node/edge features (graphs). Consider 3D conformers if the task requires spatial awareness.

4. Data augmentation strategies

Use SMILES enumeration (randomized SMILES) and graph augmentation (node/edge dropout, subgraph sampling) that preserve chemical validity. Avoid augmentations that alter the molecule's identity.

5. Choose training objectives

For generation, use autoregressive language modeling or masked language modeling (like BERT) on SMILES. For property prediction, use supervised regression/classification. For graphs, consider contrastive learning or masked atom prediction.

Key Points to Mention

  • SMILES tokenization: character-level vs. atom-level, handling of multi-character atoms (e.g., Cl, Br) and stereochemistry tokens.
  • Graph neural networks as an alternative: message passing, node/edge features, and how to adapt Transformer (e.g., Graphormer) with positional encodings.
  • Stereochemistry: use of @, /, \ in SMILES; for graphs, include chirality as node features or use 3D coordinates.
  • Data augmentation: SMILES randomization, graph augmentation techniques, and ensuring validity (e.g., using RDKit to canonicalize).
  • Training objectives: masked language modeling (BERT-style), autoregressive (GPT-style), contrastive learning, and multi-task learning.
  • Trade-offs: sequence models are simpler but may miss graph structure; graph models capture topology but are more complex. Consider data efficiency and compute.

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