AI Engineering Interview Questions: LLM Foundations Quiz

Reviewed by Mark Dickie · Last updated

6 questions on this page you can answer and see marked on the spot. Go to the first one

AI engineering is the work of building products on large language models, from how they tokenize text to how you measure whether their output is good. For LLM foundations, interviewers mostly check whether you can explain tokens, context windows, and sampling parameters from first principles. They also want you to choose between prompting, retrieval, and fine-tuning for a specific failure, and to say how you would know the change worked.

Which LLM foundations does an AI engineering interview cover?

TopicWhat interviewers probeConcrete example to be ready for
TokenizationHow text becomes token IDs, and why token counts set cost and latencyWhy the same sentence costs different amounts in different languages
Context windowWhat happens when input exceeds the model's limitTruncating old turns versus summarizing them before the next call
Sampling parametersWhat temperature, top_p, and max_tokens changeWhy temperature 0 still does not guarantee identical output across runs
Transformer basicsWhy attention cost grows with sequence lengthWhy the KV cache uses memory that grows during generation
Prompting vs RAG vs fine-tuningWhich failure each approach fixesStale facts point to retrieval; a stubborn output format may point to fine-tuning
EvaluationHow you score output without a human reading every answerA fixed regression set that runs before you ship a prompt change

How should you practice before the quiz?

  1. Explain tokenization and context limits out loud, then check your answer against the provider's documentation.
  2. Build a small chat loop that sets temperature and max tokens, and log the token usage returned on each call.
  3. Take one prompt that fails and fix it three ways: a prompt edit, a retrieval step, then a small fine-tuning set. Note which fix held up.
  4. Write a fixed set of test cases and score two prompt versions against it before you pick one.

Key facts

  • Tarmac has 80 AI Engineering interview questions on this topic, 10 of them on this page, at difficulty 1–5 of 5.
  • Tarmac tracked 2,397 job postings asking for AI Engineering in November 2026.
  • Roles asking for AI Engineering advertise a median base salary of £80,000, across 622 job postings as of November 2026.
  • Tarmac last reviewed these AI Engineering interview questions on 3 November 2026.

At a glance

Questions10 shown · 80 in the bank
Difficulty1–5 of 5
FormatsMultiple choice, Fill in the blank, Code output, Multiple answer

What you'll review

  1. llm foundations
  2. model selection

Practice questions

Try one before you open the answer. Pick an option and press Check; it's marked on the spot.

During autoregressive text generation with a decoder-only LLM (e.g., GPT-style), what gets appended to the input context at each step and fed back to predict the next token?#

Options

Show answer

The single chosen token, appended to the context. In autoregressive generation, a decoder-only LLM computes a probability distribution over its vocabulary at each step, then a decoding rule (sampling, greedy argmax, or similar) selects one token. That token's ID is appended to the input and fed back for the next prediction; the distribution itself is an intermediate result.

Why:

At each step a decoder-only LLM computes logits over its vocabulary and applies a softmax to get a probability distribution. A decoding rule then selects one token from that distribution (by sampling, or by argmax under greedy decoding). That selected token's ID is appended to the context and fed back as input for the next step. The distribution is only an intermediate result consumed by the decoding rule, not the fed-back input. The model does not output a single prompt embedding, generate tokens in parallel from a sliding window, or emit a loss value during inference.

Modern Transformer-based language models such as GPT and Llama rely on a core mechanism that relates every token in a sequence to every other token by computing weighted relationships, without recurrence. This mechanism is called _____.#

Show answer

Modern Transformer-based language models such as GPT and Llama rely on a core mechanism that relates every token in a sequence to every other token by computing weighted relationships, without recurrence. This mechanism is called self-attention.

Why:

The mechanism is self-attention, the core operation of the Transformer. Each token forms query, key, and value vectors from the same sequence, and its output is a weighted sum of the value vectors, with weights from scaled dot products of queries and keys. In practice it is implemented as multi-head scaled dot-product attention. Because every position is computed in one pass rather than step by step as in RNNs or LSTMs, it removes sequential recurrence.

In an autoregressive LLM that samples tokens via softmax over logits, what is the effect of setting the temperature parameter to a value approaching 0 (e.g., 0.01)?#

Options

Show answer

Setting temperature near 0 makes the softmax distribution increasingly peaked on the highest-logit token, which is effectively greedy (argmax) decoding. The model still responds differently to different prompts, but the sampled token becomes almost entirely deterministic.

Why:

Temperature divides each logit by T before softmax. As T → 0, the largest logit dominates exponentially more strongly, so the distribution concentrates virtually all probability mass on the single highest-scoring token — behavior equivalent to greedy (argmax) decoding. The model's output still depends on the prompt (ruling out "The model always outputs the same response regardless of the input prompt"); temperature 1 means no scaling (ruling out "The softmax is computed over raw logits without any division, equivalent to temperature = 1"); and near-zero temperature makes output deterministic, not random (ruling out "All logits are zeroed out so every token becomes equally likely, producing random output").

In a decoder-only transformer (e.g., GPT-style architecture), what is the primary purpose of causal (masked) self-attention during training?#

Options

Show answer

Causal masking in decoder-only transformers ensures each token attends only to itself and earlier positions, preserving the autoregressive property so predictions never depend on future tokens. It prevents a train/inference mismatch but does not reduce O(n²) attention complexity, address gradient issues, or serve as regularization.

Why:

Causal masking sets the attention scores for all future positions to negative infinity (zero after softmax), so each token at position i can only attend to positions 0 through i. This preserves the autoregressive property: during training, the model never 'sees the future,' which matches the left-to-right generation used at inference time. Without causal masking, there would be a train/inference mismatch. Causal masking does not change the O(n²) complexity of attention, does not address vanishing gradients (that is the role of residual connections and layer norm), and is not a form of regularization like dropout.

During autoregressive inference in transformer-based LLMs, the _____ cache stores the projected key and value tensors from all previously processed token positions, so each newly generated token's query attends to cached keys and values instead of recomputing them. Per generated token, this reduces the attention cost from O(n²) per step (recomputing attention over the whole prefix) to O(n) per step, where n is the sequence length.#

Show answer

During autoregressive inference in transformer-based LLMs, the KV cache stores the projected key and value tensors from all previously processed token positions, so each newly generated token's query attends to cached keys and values instead of recomputing them. Per generated token, this reduces the attention cost from O(n²) per step (recomputing attention over the whole prefix) to O(n) per step, where n is the sequence length.

Why:

The KV (key-value) cache is the standard name for this optimization. After each token passes through an attention layer, its projected key and value vectors are stored. When the next token is generated, only that token's query, key, and value are computed, and its query attends to the n cached key/value pairs, which costs O(n) per step for attention. Without a cache, each step recomputes keys and values for the whole prefix and attends over all positions, which costs O(n²) per step for attention. The blank accepts every common spelling of this name (KV, key-value, key/value, K/V and variants), since they all denote the same cache. The trade-off is memory, because the cache grows linearly with sequence length and number of layers.

The code below counts the total trainable parameters in a small decoder-only transformer model. The model uses tied input/output embeddings (the output projection reuses the embedding weight matrix, so the embedding parameters are counted only once). Each transformer layer contains four attention projection matrices (Q, K, V, O) and a two-layer feed-forward network — no biases, no layer-norm parameters. Trace the code and determine the printed output.#

d_model = 512
d_ff = 2048
n_layers = 6
vocab_size = 10000

# Per-layer params (no biases, no layer-norm params)
# Attention: Q, K, V, O = 4 * d_model^2
# FFN: 2 * d_model * d_ff
per_layer = 4 * d_model * d_model + 2 * d_model * d_ff

# Embedding + output projection (tied weights -> counted once)
embedding = vocab_size * d_model

total = n_layers * per_layer + embedding
print(total)
Show answer
23994368
Why:

Tracing the code step by step: d_model = 512, d_ff = 2048, n_layers = 6, vocab_size = 10000. Per layer, attention contributes 4 × 512 × 512 = 1,048,576 parameters and the FFN contributes 2 × 512 × 2048 = 2,097,152, so per_layer = 3,145,728. Across 6 layers that is 6 × 3,145,728 = 18,874,368. The tied embedding matrix (counted once because weights are shared between input embeddings and output projection) adds 10,000 × 512 = 5,120,000. total = 18,874,368 + 5,120,000 = 23,994,368, which is what print(total) outputs.

Rotary Position Embeddings (RoPE) are used in many modern decoder-only LLMs (e.g., LLaMA, Mistral). Which of the following statements about RoPE are correct? Select all that apply.#

Options

Pick every one that applies.

Show answer

The correct statements are that RoPE encodes relative position through position-dependent rotations applied to both query and key vectors, and that the resulting query–key dot product depends only on the relative distance between tokens. RoPE uses no learnable parameters — the rotations are fixed functions of position and a base frequency — and it is applied to both queries and keys, not queries alone.

Why:

The statement that RoPE encodes relative position by applying position-dependent rotations to the query and key vectors before their dot product is computed is correct: RoPE multiplies each pair of dimensions in the query and key by a 2-D rotation whose angle is determined by the token's absolute position index, so the rotations themselves are position-dependent. The statement that the dot product between any RoPE-rotated query–key pair depends only on their relative position, not on their absolute positions is correct and is the defining property of RoPE — because the same rotation scheme is applied to both Q and K, the inner product <R_m·q, R_n·k> simplifies to a function of (m − n), the relative position, making the attention scores translation-invariant. The claim that RoPE introduces additional learnable parameters specifically for position encoding is wrong: RoPE uses fixed rotation matrices derived from a base frequency θ (e.g., 10 000) and the position index; there are no learnable position-embedding parameters. The claim that RoPE can only be applied to query vectors, not to key vectors is wrong: RoPE is applied to both queries and keys — rotating only one would not produce the relative-position property in the dot product.

In speculative decoding, a small draft model proposes a sequence of K tokens, which are then verified by the large target model in a single forward pass. An engineer claims the following:#

Options

Show answer

Speculative decoding is lossless with respect to the target model's output distribution. When a draft token is rejected, the algorithm samples a corrected token from a modified distribution that ensures the final sequence is distributed exactly as if the large target model had generated every token autoregressively. The real tradeoff is between wall-clock speedup (governed by how often draft tokens are accepted) and the computational overhead of running both models — not any degradation in output quality.

Why:

Speculative decoding uses a small, fast 'draft' model to propose multiple candidate tokens in parallel, then the large 'verifier' model checks them in a single forward pass. The acceptance criterion is designed so that the output distribution is identical to sampling from the verifier alone — this is the key correctness guarantee. The speedup comes from the fact that verifying K tokens costs only slightly more than verifying 1 (batch dimension), while the draft model is cheap. Critically, speculative decoding does NOT change the output distribution of the target model; it only accelerates sampling. The acceptance rate (α) depends on how well the draft model's distribution matches the verifier's. If the draft model is too mismatched (low α), the overhead of running both models exceeds the gain, negating the speedup. Self-speculative decoding (e.g., Medusa heads, EAGLE) avoids the need for a separate draft model by using auxiliary prediction heads on the base model itself.

Rotary Position Embeddings (RoPE) encode relative position by rotating query and key vectors in 2D subspaces at different frequencies θ_i, where the relative rotation between positions m and n in dimension i is (m−n)·θ_i. A well-known issue is that RoPE generally fails to extrapolate to sequence lengths beyond those seen during training. Techniques such as NTK-aware interpolation and YaRN aim to fix this.#

Options

Show answer

RoPE fails to extrapolate beyond training lengths because its lowest-frequency dimensions encounter relative rotation angles at long distances that were never seen during training, creating an out-of-distribution regime. High-frequency dimensions wrap periodically and stay in-distribution, but low-frequency ones grow monotonically with distance. NTK-aware scaling and YaRN address this by rescaling the frequency base to compress those low-frequency angles back into the trained range.

Why:

The correct answer is the statement about low-frequency dimensions exceeding maximum trained relative rotation angles. RoPE rotates each 2D subspace at frequency θ_i; the relative rotation between positions m and n is (m−n)·θ_i. For high-frequency dimensions (large θ_i), the angle wraps around periodically, so every possible relative angle was already encountered during training. For low-frequency dimensions (small θ_i), the relative angle grows monotonically with distance and does not wrap within the training range — so at distances beyond training, those dimensions see relative rotation angles never observed before, producing out-of-distribution attention patterns. NTK-aware scaling and YaRN mitigate this by rescaling the frequency base (or per-dimension frequencies) to compress low-frequency rotation angles back into the trained range. The claim that the failure is a floating-point precision issue is wrong because the failure is distributional, not a floating-point precision issue. The description of absolute additive position encodings (e.g., sinusoidal PE) incorrectly describes RoPE's rotary multiplication. The claim that each dimension's rotational contribution causes logits to grow polynomially with distance is wrong because each dimension's rotational contribution is bounded in [−1, 1] via cosine/sine; the logits do not grow polynomially with distance.

The code below implements a single head of causal (decoder-only) self-attention with numerical stability (max-subtraction before softmax). Trace the computation by hand and determine the exact value printed.#

import numpy as np

Q = np.array([[1, 0],
             [0, 1],
             [1, 1]])
K = np.array([[1, 0],
             [0, 1],
             [1, 1]])
V = np.array([[1, 2],
             [3, 4],
             [5, 6]])

d_k = 2
scores = Q @ K.T / np.sqrt(d_k)

# Causal mask: upper-triangular set to -1e9
mask = np.triu(np.ones((3, 3)), k=1) * -1e9
scores = scores + mask

# Numerically stable softmax
scores = scores - scores.max(axis=-1, keepdims=True)
exp_scores = np.exp(scores)
attn = exp_scores / exp_scores.sum(axis=-1, keepdims=True)

output = attn @ V
print(np.round(output[2].sum(), 4))
Show answer
8.0209
Why:

We need output[2], the attention output for the third token (index 2), which can attend to all three positions under causal masking. Row 2 of the scores is Q[2]·K[j]/√2 with Q[2] = [1, 1]: the raw dot products are [1, 1, 2], so the scaled scores are [0.70711, 0.70711, 1.41421]. The causal mask only touches j > i, so row 2 is unchanged. Subtracting the max (1.41421) gives [−0.70711, −0.70711, 0], and the exponentials are [0.493069, 0.493069, 1], summing to 1.986138. The attention weights are therefore [0.248255, 0.248255, 0.503490]. The output row sum equals the weighted sum of the V row sums (3, 7, 11): 0.248255·3 + 0.248255·7 + 0.503490·11 = 5 + 6·0.503490 = 8.02094, which rounds to 8.0209. Rounding the intermediate weights early (for example, to 0.24826 and 0.50347) shifts the result to 8.0208, so the full-precision value is the one printed.

Related interview questions

Job market

See ai-engineering salaries and hiring demand from live job postings.

The other 70 questions

This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 70 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.

Start with this topic

Free · the whole bank · 100 answers per 30 days, each marked with written feedback

Interview booked? Practise the job ad instead

What moved, monthly

One email a month when the bulletin comes out: what moved in the markets we track, and the new question topics we published. Confirm your address to join. Unsubscribe any time.