← UiPath Interview Insights

UiPath·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

Technical interview at UiPath for an ML Engineer role, focused almost entirely on Transformer internals. One long question that kept branching into sub-questions. Felt like a grad school oral exam more than a standard interview.

Questions Asked (6)

Q1

Walk through the Transformer architecture in full detail, covering both encoder and decoder layers, including multi-head attention, residual connections, layer normalization, and the feed-forward network. How do Pre-LN and Post-LN differ?

System DesignTechnical Trade-offs
Author's notes

This is where the interview started and basically never left.

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 dive into the encoder and decoder components, explaining multi-head attention, residual connections, layer normalization, and the feed-forward network. Clearly contrast Pre-LN and Post-LN, highlighting their structural differences and implications for training stability and performance. Conclude by relating these concepts to practical considerations in ML engineering, such as model optimization and deployment.

Pro tip: Emphasize that Pre-LN is generally more stable for training deep Transformers and is the de facto choice in modern architectures, but note that Post-LN can still be effective with careful learning rate warmup. This shows awareness of real-world trade-offs beyond textbook definitions.

1. High-Level Architecture Overview

Briefly describe the Transformer as an encoder-decoder model that relies solely on attention mechanisms, dispensing with recurrence and convolutions. Mention its key components: stacked layers of multi-head attention, feed-forward networks, residual connections, and layer normalization.

2. Encoder and Decoder Layers

Explain that the encoder consists of a stack of identical layers, each with two sub-layers: multi-head self-attention and a position-wise feed-forward network. The decoder has three sub-layers: masked multi-head self-attention, multi-head attention over the encoder output, and a feed-forward network. Note that each sub-layer is wrapped with a residual connection followed by layer normalization.

3. Multi-Head Attention Mechanism

Detail how multi-head attention projects queries, keys, and values into multiple subspaces, applies scaled dot-product attention in parallel, and concatenates the results. Explain that this allows the model to jointly attend to information from different representation subspaces.

4. Residual Connections and Layer Normalization

Describe how residual connections help mitigate vanishing gradients and enable deep networks, while layer normalization stabilizes training by normalizing activations across features. Clarify the order of operations in Post-LN (original Transformer) versus Pre-LN (modern variants).

5. Pre-LN vs. Post-LN

Contrast Pre-LN and Post-LN: In Post-LN, layer normalization is applied after the residual addition (x + Sublayer(x)), whereas in Pre-LN, it is applied before the sublayer (x + Sublayer(LayerNorm(x))). Discuss how Pre-LN improves training stability and allows for higher learning rates without warmup, while Post-LN may require careful warmup but can yield slightly better performance in some cases.

Key Points to Mention

  • Scaled dot-product attention and the role of the scaling factor
  • Multi-head attention: parallel attention heads and concatenation
  • Positional encoding: how sequence order is injected
  • Residual connections: enabling gradient flow and deep stacking
  • Layer normalization: stabilizing activations and training
  • Pre-LN vs. Post-LN: structural differences and training implications

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

Q2

Why does a Transformer need a position-wise feed-forward network after the attention layer? What can the FFN do that attention alone cannot?

Technical Trade-offsSystem Design
Author's notes

Blanked for a second on this one.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining the fundamental limitation of self-attention: it is a weighted sum of value vectors, which is a linear operation. Then describe how the position-wise feed-forward network (FFN) introduces non-linearity and enables per-position transformations, allowing the model to learn complex functions. Finally, discuss the complementary roles: attention mixes information across positions, while the FFN processes each position independently to add depth and capacity.

Pro tip: Emphasize that without the FFN, the Transformer would be a shallow linear model over token embeddings, severely limiting its expressiveness. Mention that the FFN acts as a key-value memory or pattern detector, which is crucial for tasks like machine translation and language modeling.

1. Identify the limitation of attention

Explain that self-attention computes a weighted average of value vectors, which is a linear operation. Even with multiple heads, it remains linear in the values, so it cannot model complex non-linear interactions.

2. Describe the FFN's role

Introduce the position-wise FFN as a two-layer MLP with a non-linear activation (e.g., ReLU) applied independently to each position. It transforms each token's representation, adding non-linearity and increasing model capacity.

3. Contrast mixing vs. processing

Highlight that attention mixes information across positions (token mixing), while the FFN processes each position separately (channel mixing). Together, they enable both cross-token and per-token transformations.

4. Discuss expressiveness and depth

Explain that stacking attention and FFN layers allows the model to learn hierarchical and abstract features. The FFN acts as a key-value memory, storing patterns learned during training.

5. Connect to practical implications

Mention that removing the FFN drastically reduces performance, as shown in ablations. The FFN is essential for achieving state-of-the-art results in NLP and beyond.

Key Points to Mention

  • Self-attention is a linear operation (weighted sum of values).
  • FFN introduces non-linearity via activation functions (e.g., ReLU, GELU).
  • Attention mixes information across positions; FFN processes each position independently.
  • FFN increases model capacity and depth, enabling complex function approximation.
  • FFN can be interpreted as a key-value memory or pattern detector.
  • Ablation studies show that removing FFN significantly degrades performance.

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

Q3

Using a concrete configuration like d_model=512 and 8 heads, trace the exact matrix shapes through a full attention block: Q/K/V projections, attention scores, softmax, weighted sum, head concatenation, output projection, residual addition, layer norm, and both FFN linear layers.

System DesignAlgorithms & Data Structures
Author's notes

This was the part I actually felt decent about.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by stating the input shape and the key dimensions (d_model=512, h=8, d_k=d_v=64). Then walk through each operation in order, computing shapes step by step, and explain why each shape makes sense (e.g., why d_k=64, why concatenation restores d_model). Finally, mention the residual and layer norm shapes and the FFN expansion/contraction.

Pro tip: Emphasize that the head dimension d_k = d_model / h = 64, and that the output projection after concatenation mixes information across heads. Also note that layer norm is applied per token (over the last dimension) and that the FFN typically expands to 4*d_model = 2048.

1. Input and Q/K/V Projections

Assume input X has shape (batch_size, seq_len, d_model=512). Compute Q = X W_Q, K = X W_K, V = X W_V, each with shape (batch_size, seq_len, 512). Then split into 8 heads: reshape to (batch_size, seq_len, 8, 64) and transpose to (batch_size, 8, seq_len, 64).

2. Attention Scores and Softmax

Compute scores = Q K^T / sqrt(d_k) with shape (batch_size, 8, seq_len, seq_len). Apply softmax over the last dimension to get attention weights of the same shape.

3. Weighted Sum and Head Concatenation

Compute attention output = weights V, shape (batch_size, 8, seq_len, 64). Transpose to (batch_size, seq_len, 8, 64) and reshape to (batch_size, seq_len, 512) by concatenating heads.

4. Output Projection, Residual, and Layer Norm

Apply output projection W_O: (batch_size, seq_len, 512) -> (batch_size, seq_len, 512). Add residual connection (X + output) and apply layer norm over the last dimension, resulting in the same shape.

5. FFN Layers

First linear layer expands to 4*d_model = 2048: shape (batch_size, seq_len, 2048). Apply activation (e.g., ReLU). Second linear layer contracts back to 512: shape (batch_size, seq_len, 512). Add residual and layer norm again.

Key Points to Mention

  • d_k = d_v = d_model / h = 64
  • Scaling factor 1/sqrt(d_k) in attention scores
  • Softmax applied over the last dimension (key dimension)
  • Concatenation of heads restores d_model=512
  • Residual connections and layer norm preserve shape
  • FFN intermediate dimension typically 4*d_model = 2048

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

Q4

Derive the computational complexity of self-attention with respect to sequence length n and model dimension d. Where does memory become the bottleneck?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Got the O(n^2 * d) time complexity right away.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Break down self-attention into its core operations: Q, K, V projections, attention score computation, softmax, and weighted sum. Derive time and memory complexity for each, then aggregate to get overall O(n^2 d) time and O(n^2 + n d) memory. Conclude that memory bottleneck arises from the n x n attention matrix when n is large.

Pro tip: Mention that while time complexity is O(n^2 d), memory is often the practical bottleneck because the n x n attention matrix must be stored for backpropagation, and this scales quadratically with sequence length. Also note that techniques like FlashAttention reduce memory by recomputation, but the underlying complexity remains.

1. Identify operations in self-attention

List the key operations: linear projections to Q, K, V; computing attention scores QK^T; applying softmax; and computing weighted sum with V. Each operation involves matrix multiplications or element-wise operations.

2. Derive time complexity per operation

For each operation, determine the dimensions of matrices involved and count floating-point operations. For example, QK^T involves multiplying n x d and d x n matrices, resulting in O(n^2 d) time.

3. Derive memory complexity per operation

Determine the memory required to store intermediate results. The attention score matrix is n x n, so it requires O(n^2) memory. Other matrices like Q, K, V are n x d, requiring O(n d) memory.

4. Aggregate complexities and identify bottleneck

Sum time complexities to get O(n^2 d + n d^2). Sum memory to get O(n^2 + n d). Compare the terms: for large n, the n^2 term dominates memory, making the attention matrix the bottleneck.

5. Discuss implications and trade-offs

Explain that memory bottleneck limits sequence length in practice. Mention techniques like sparse attention, low-rank approximations, or FlashAttention that reduce memory footprint, but note that they often trade off compute or model quality.

Key Points to Mention

  • Time complexity: O(n^2 d) for attention scores and weighted sum, O(n d^2) for projections, overall O(n^2 d + n d^2).
  • Memory complexity: O(n^2) for attention matrix, O(n d) for Q, K, V, overall O(n^2 + n d).
  • The n x n attention matrix is the memory bottleneck for long sequences.
  • Backpropagation requires storing the attention matrix, increasing memory usage.
  • Techniques like FlashAttention reduce memory by recomputation but do not change asymptotic complexity.
  • Practical implications: sequence length limited by GPU memory, quadratic scaling motivates efficient attention variants.

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

Q5

What are the trade-offs between different implementation choices in Transformers: fused vs. separate Q/K/V projections, multi-query and grouped-query attention, positional encoding schemes like RoPE or ALiBi, and FFN variants like SwiGLU or RMSNorm?

Technical Trade-offsSystem Design
Author's notes

This one sprawled.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by framing the trade-offs along key dimensions: compute/memory efficiency, training stability, inference speed, and model quality. Then systematically compare each design choice, highlighting when one option is preferable over another. Finally, tie your answer to practical considerations like hardware constraints and deployment scenarios, especially relevant to UiPath's automation context.

Pro tip: Emphasize that these choices are not independent—they interact. For example, GQA reduces KV cache memory, which is crucial for long-context inference, but may slightly hurt quality; combining it with RoPE can mitigate positional issues. Showing awareness of such interactions demonstrates deep understanding.

1. Define evaluation criteria

Outline the dimensions for comparison: computational cost, memory footprint, training stability, inference latency, and model accuracy. This sets a structured basis for analysis.

2. Analyze Q/K/V projections

Compare fused vs. separate projections: fused reduces memory overhead and improves GPU utilization but limits flexibility; separate allows independent tuning but increases memory and kernel launches.

3. Evaluate attention variants

Discuss multi-query (MQA) and grouped-query attention (GQA): MQA drastically reduces KV cache but may degrade quality; GQA balances quality and efficiency by sharing keys/values across groups.

4. Compare positional encodings

Contrast RoPE and ALiBi: RoPE provides relative position via rotation and extrapolates well to longer sequences; ALiBi adds linear biases to attention scores, offering simplicity and strong extrapolation but may underperform on some tasks.

5. Assess FFN and normalization variants

Examine SwiGLU vs. standard FFN: SwiGLU often improves quality but adds parameters and compute; RMSNorm is simpler and faster than LayerNorm, with comparable performance in many cases.

Key Points to Mention

  • Fused Q/K/V projections reduce memory bandwidth and kernel launch overhead, beneficial for large-scale training.
  • GQA offers a sweet spot between MQA's efficiency and multi-head attention's quality, widely adopted in models like Llama 2.
  • RoPE's relative nature and compatibility with linear attention make it popular for long-context models; ALiBi is simpler and has shown strong extrapolation in some benchmarks.
  • SwiGLU's gating mechanism enhances representational capacity but increases parameter count; RMSNorm avoids mean centering, reducing compute.
  • Trade-offs depend on hardware: e.g., fused kernels may not be supported on all accelerators, and ALiBi may be more efficient on TPUs.
  • Consider the impact on fine-tuning and inference: e.g., GQA reduces KV cache memory, enabling larger batch sizes or longer contexts.

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

Q6

How do encoder and decoder layers structurally differ, and how do token representations change as they pass through successive layers in the stack?

System DesignTechnical Trade-offs
Author's notes

Covered the cross-attention block in the decoder and the causal masking.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by contrasting the structural differences between encoder and decoder layers, focusing on self-attention masking and cross-attention. Then, describe how token representations evolve through successive layers, emphasizing increasing abstraction and contextualization. Finally, connect this to practical implications in model design and trade-offs.

Pro tip: Relate the architectural differences to real-world use cases like machine translation or document understanding, and mention how UiPath might leverage these in automation workflows. This shows you understand both theory and application.

1. Define Encoder and Decoder Layers

Briefly define what encoder and decoder layers are in transformer architectures, highlighting their roles in sequence-to-sequence tasks.

2. Contrast Structural Differences

Explain key structural differences: encoder uses bidirectional self-attention, while decoder uses masked self-attention and cross-attention over encoder outputs.

3. Trace Token Representation Evolution

Describe how token representations become more contextually rich and abstract as they pass through layers, with lower layers capturing syntax and higher layers capturing semantics.

4. Discuss Implications and Trade-offs

Connect these differences to design choices, such as computational cost, parallelization, and suitability for tasks like classification vs. generation.

5. Summarize with Practical Relevance

Tie back to the role at UiPath, mentioning how understanding these layers aids in building efficient and accurate ML models for automation.

Key Points to Mention

  • Encoder layers use bidirectional self-attention, allowing each token to attend to all tokens in the input sequence.
  • Decoder layers use masked self-attention to prevent attending to future tokens, and cross-attention to incorporate encoder outputs.
  • Token representations become increasingly abstract and context-dependent in higher layers, with lower layers capturing local syntax and higher layers capturing global semantics.
  • Encoder-only models (e.g., BERT) are good for understanding tasks, while decoder-only models (e.g., GPT) are good for generation tasks.
  • The number of layers and attention heads affects model capacity and computational complexity.
  • Cross-attention in decoder layers enables the model to align source and target sequences in tasks like translation.

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