Skip to content
RED SAGSkills

Transformers interview questions and answers

Transformer questions go inside modern language models: attention, tokens and how models generate text.

Below are 60 Transformers questions with the correct answer and a short explanation, grouped from fresher to experienced level. Try each one before you open the answer.

What Transformers interviews usually check

  • ✓Self-attention and multi-head attention
  • ✓Tokenisation and embeddings
  • ✓Positional encoding
  • ✓Encoder, decoder and decoder-only models
  • ✓KV cache and decoding strategies

Transformers interview questions for freshers easy

1. What sampling temperature does

When generating text from a language model, what happens as you lower the sampling temperature towards 0?

  1. A.Output gets more random, spreading probability evenly
  2. B.Output gets more deterministic, favouring the top tokens
  3. C.The model writes longer replies on average
  4. D.The context window shrinks to save GPU memory
Show answer

Answer: B. Output gets more deterministic, favouring the top tokens

Temperature divides the logits before the softmax. A low temperature sharpens the distribution so the most likely tokens dominate, approaching greedy decoding at 0. A high temperature flattens it and makes output more varied.

2. Choosing the tokenizer

You fine-tune Llama-family weights but load a tokenizer from a different model family by mistake. What is the likely result?

  1. A.Training is slower but output is the same
  2. B.Token IDs map to the wrong embeddings and output is garbage
  3. C.The model auto-converts to the new tokenizer
  4. D.Only punctuation and spacing come out differently
Show answer

Answer: B. Token IDs map to the wrong embeddings and output is garbage

A model learns one embedding per token ID of its own vocabulary. A different tokenizer gives different IDs for the same text, so the model sees nonsense. Always load the tokenizer saved with the base checkpoint.

3. What the end-of-sequence token does

During generation, what is the job of the end-of-sequence (EOS) token?

  1. A.It marks where the system prompt ends and the user message starts
  2. B.It is added after every sentence so the model knows to start a new line
  3. C.It replaces unknown words that the tokenizer cannot encode
  4. D.When the model produces it, generation stops because the reply is complete
Show answer

Answer: D. When the model produces it, generation stops because the reply is complete

The model learns during training that a document or reply ends with EOS. At inference the decoding loop stops when the model samples EOS (or a configured stop token). If EOS is missing from fine-tuning data, the model may ramble on without stopping.

4. Query, key and value in attention

In self-attention, each token produces a query, a key and a value vector. Which description of their roles is right?

  1. A.Query stores the token itself, key stores its position, value stores its frequency
  2. B.Query and key are both copies of the input; value is the final output token
  3. C.Query asks what to look for, key is matched against it, value is what gets mixed in
  4. D.Query is used in training only, while key and value are used at inference only
Show answer

Answer: C. Query asks what to look for, key is matched against it, value is what gets mixed in

Attention scores come from the dot product of one token's query with every token's key. After softmax, those scores weight a sum of the value vectors. So keys decide how much each token is attended to, and values decide what information is passed along.

5. What a decoder-only model predicts

GPT, Llama and most chat LLMs are decoder-only transformers. What are they trained to do?

  1. A.Fill in randomly masked words using both left and right context
  2. B.Translate an input sentence produced by a separate encoder
  3. C.Classify a whole document into one of a fixed set of labels
  4. D.Predict the next token from all the tokens before it
Show answer

Answer: D. Predict the next token from all the tokens before it

Decoder-only models use causal attention, so each position sees only earlier tokens, and they are trained on next-token prediction. Generating text is just repeating that prediction one token at a time. Masked-word filling is the BERT (encoder-only) objective.

6. What fills the context window

A model has a 128K-token context window. What has to fit inside that limit for a single request?

  1. A.Only the user message; the system prompt is stored separately
  2. B.The prompt tokens plus the tokens the model generates
  3. C.Only the generated answer; the prompt has its own limit
  4. D.The number of characters, not tokens, across the whole chat
Show answer

Answer: B. The prompt tokens plus the tokens the model generates

The context window is the total number of tokens the model can attend over in one pass: system prompt, chat history, retrieved documents and the output it writes. If the prompt is 120K tokens, at most about 8K tokens remain for the answer.

7. What the final layer outputs

What does the last layer (the LM head) of a language model output at each position?

  1. A.One score (logit) per vocabulary token, turned into probabilities with softmax
  2. B.A single number between 0 and 1 saying how confident the model is
  3. C.The id of the next token, chosen directly without any scores
  4. D.A copy of the input embedding shifted by one position
Show answer

Answer: A. One score (logit) per vocabulary token, turned into probabilities with softmax

The LM head projects the final hidden vector to a vector the size of the vocabulary. These raw scores are logits; softmax turns them into a probability distribution. Decoding methods like greedy, top-p or temperature sampling then pick the next token from that distribution.

8. Base model versus instruct model

You give the prompt "What is the capital of the UAE?" to a base (pretrained only) model. It replies with three more quiz questions. Why?

  1. A.A base model continues text; it was never tuned to answer as an assistant
  2. B.The base model does not know the answer, but the instruct one does
  3. C.Base models refuse questions about countries for safety reasons
  4. D.The prompt was too short to fill the context window
Show answer

Answer: A. A base model continues text; it was never tuned to answer as an assistant

Pretraining teaches a model to continue documents, and a quiz question is often followed by more quiz questions. Instruction tuning and preference training teach the model to respond to requests. The base model may know that the answer is Abu Dhabi, but it is not trained to give it as a reply.

9. What SFT data looks like

What kind of data is used for supervised fine-tuning (SFT) of a chat model?

  1. A.Pairs of answers with a human vote on which one is better
  2. B.Raw web pages with no labels, the same as pretraining
  3. C.Prompts paired with good example responses written or checked by people
  4. D.Lists of words with their dictionary definitions only
Show answer

Answer: C. Prompts paired with good example responses written or checked by people

SFT trains the model on demonstrations: a prompt and the response you want, using the usual next-token loss. Preference pairs (which answer is better) are used later, in RLHF or DPO. SFT data is much smaller than pretraining data but has to be high quality.

10. How a mixture-of-experts layer works

In a mixture-of-experts (MoE) transformer, what happens to each token in an MoE layer?

  1. A.Every expert processes it and the results are averaged
  2. B.It is sent to a separate model trained for its language
  3. C.A router picks a few expert feed-forward networks to process it
  4. D.It skips the layer unless it is a rare token
Show answer

Answer: C. A router picks a few expert feed-forward networks to process it

An MoE layer replaces one feed-forward network with many experts plus a small router. For each token the router selects the top-k experts (often 1 or 2) and combines their outputs. The model can hold many parameters while each token uses only a fraction of them.

11. What 7B in a model name means

What does "7B" mean in a name like "Mistral 7B"?

  1. A.It was trained on 7 billion documents
  2. B.The model has about 7 billion learned parameters
  3. C.It supports a context window of 7 billion tokens
  4. D.It has 7 billion words in its vocabulary
Show answer

Answer: B. The model has about 7 billion learned parameters

The number is the parameter count: the weights in all its matrices. It drives memory needs (about 2 bytes per parameter in fp16) and compute per token. Training data size and context length are separate numbers.

12. Sampling from the top 40 tokens

With top-k sampling and k = 40, how is the next token chosen?

  1. A.Generate 40 tokens and keep the one with the highest score
  2. B.Keep the 40 most likely tokens, renormalise, then sample from them
  3. C.Sample from the whole vocabulary 40 times and take a vote
  4. D.Pick the 40th most likely token every time
Show answer

Answer: B. Keep the 40 most likely tokens, renormalise, then sample from them

Top-k cuts the distribution to the k highest-probability tokens, rescales those probabilities to sum to 1, and samples. This removes the long tail of unlikely tokens. Its weakness is that a fixed k is too many when the model is sure and too few when it is unsure.

13. What top-p sampling does

With top-p (nucleus) sampling and p = 0.9, which tokens can be sampled?

  1. A.Only the tokens that each have a probability of 0.9 or more
  2. B.The top 90% of all the tokens in the vocabulary, by rank
  3. C.Any token, but with 90% of its probability removed
  4. D.The fewest top tokens whose probabilities sum to 0.9 or more
Show answer

Answer: D. The fewest top tokens whose probabilities sum to 0.9 or more

Top-p sorts tokens by probability and keeps adding them until the total reaches p, then samples from that set after renormalising. When the model is confident, the set may be one or two tokens; when it is unsure, the set grows. That adaptiveness is why top-p is a common default.

14. Reply that ends mid-sentence

Your API response ends mid-sentence and the finish reason says "length". What happened?

  1. A.Generation hit the max output tokens limit you set
  2. B.The model detected unsafe content and stopped
  3. C.The network dropped the last part of the reply
  4. D.The model chose to end because the answer was complete
Show answer

Answer: A. Generation hit the max output tokens limit you set

A "length" (or "max_tokens") finish reason means the output limit was reached before the model emitted its end token. Raise the limit, ask for a shorter answer, or continue the generation. A normal end shows a "stop" or "end_turn" reason instead.

15. Why chat replies arrive word by word

Why do LLM chat apps show the reply appearing a few characters at a time?

  1. A.The model generates one token at a time, each based on the ones before
  2. B.The server types the reply slowly to look more human
  3. C.The full reply is ready at once but the network is slow
  4. D.Each word is generated by a different model in turn
Show answer

Answer: A. The model generates one token at a time, each based on the ones before

Decoder LLMs are autoregressive: each new token depends on all previous tokens, so tokens are produced in sequence. Streaming sends each token as it is ready, so users can start reading long before the full answer is finished.

16. Why LLMs state false facts

An LLM confidently invents a court case that does not exist. What is the basic reason this can happen?

  1. A.It generates likely-sounding text and has no built-in check against a source
  2. B.It copies text from a database that contains fake court cases
  3. C.It was told by the system prompt to invent examples
  4. D.Its tokenizer could not encode the real case names
Show answer

Answer: A. It generates likely-sounding text and has no built-in check against a source

Language models learn to produce plausible continuations. When they lack the fact, the most plausible text can still be a made-up but realistic name and citation. Grounding answers in retrieved documents, asking for citations you can verify, and allowing "I don't know" all reduce this.

17. What logprobs tell you

An API can return logprobs for each output token. What are they useful for?

  1. A.Counting how many words the user typed
  2. B.Finding which GPU produced each token
  3. C.Seeing how likely the model thought each chosen token was
  4. D.Measuring how long each token took to generate
Show answer

Answer: C. Seeing how likely the model thought each chosen token was

A logprob is the log of the probability the model gave a token. Low values flag uncertain parts of an answer, and comparing logprobs of options such as "Yes" and "No" gives a rough classification score. Remember that RLHF models can be overconfident.

18. How a vision transformer reads an image

A vision transformer (ViT) has no words to tokenise. How does it turn an image into a sequence it can attend over?

  1. A.It cuts the image into small square patches and embeds each patch as a token
  2. B.It converts the image to a text caption and tokenises the caption
  3. C.It treats each pixel's RGB value as one word in the vocabulary
  4. D.It reads the image file's bytes in the order they are stored
Show answer

Answer: A. It cuts the image into small square patches and embeds each patch as a token

A ViT splits the image into fixed-size patches, such as 16 × 16 pixels, flattens each one and projects it to a vector. Position embeddings are added and the patch vectors go through ordinary transformer layers. Multimodal LLMs use a similar vision encoder to produce image tokens.

19. What CLIP learns

CLIP was trained on a huge set of images paired with their captions. What does it learn?

  1. A.Image and text encoders that map matching pairs to nearby vectors
  2. B.A model that draws a new image from any caption
  3. C.A tokenizer that turns images into words
  4. D.A classifier for a fixed list of 1,000 object labels
Show answer

Answer: A. Image and text encoders that map matching pairs to nearby vectors

CLIP trains an image encoder and a text encoder together so that an image and its own caption get similar embeddings, and mismatched pairs get dissimilar ones. You can then search images with text or classify zero-shot by comparing an image with captions like "a photo of a camel".

20. Where the system prompt lives

How does a chat model "receive" its system prompt?

  1. A.As a separate set of weights loaded before each chat
  2. B.As tokens at the start of the context, marked with a system role
  3. C.As a config file that the model reads from disk
  4. D.As a rule list enforced outside the model by the server
Show answer

Answer: B. As tokens at the start of the context, marked with a system role

The system prompt is just text in the context window, wrapped in role markers by the chat template. The model was trained to give it priority, but it is processed by the same attention as everything else. It also uses context tokens and is billed as input.

Transformers intermediate interview questions medium

21. Softmax by hand

Logits are [2, 1, 0]. Using e ≈ 2.718, what is the softmax probability of the first class, to two decimals?

  1. A.0.50
  2. B.0.73
  3. C.0.33
  4. D.0.67
Show answer

Answer: D. 0.67

Exponentials are e² ≈ 7.39, e¹ ≈ 2.72 and e⁰ = 1, summing to 11.11. The first probability is 7.39 / 11.11 ≈ 0.665, about 0.67. Softmax depends only on differences between logits.

22. Attention without position information

If you remove positional encodings from a transformer encoder, what can it no longer tell apart?

  1. A.Upper and lower case letters
  2. B.Words from two different languages
  3. C.Long and short words
  4. D."dog bites man" and "man bites dog"
Show answer

Answer: D. "dog bites man" and "man bites dog"

Self-attention treats its input as a set, so without position information, permuting tokens just permutes outputs. Learned, sinusoidal or rotary (RoPE) position encodings inject order so word order matters.

23. Adding tokens for an Indic script

Your base model splits Tamil text into many byte-level pieces. You add 10,000 Tamil tokens to the tokenizer. What must follow for these to help?

  1. A.Continued pretraining on Tamil text so the new embeddings learn
  2. B.Nothing, new tokens work as soon as they are added
  3. C.Deleting 10,000 English tokens to keep the size fixed
  4. D.A short DPO run with Tamil preference pairs only
Show answer

Answer: A. Continued pretraining on Tamil text so the new embeddings learn

New tokens get new embedding rows that start with no meaning. A good amount of Tamil text in continued pretraining, often with embeddings initialised from the mean of their old sub-pieces, is needed before they are useful. Fewer tokens per word then cut cost.

24. LoRA cannot learn new tokens

You added new special tokens and trained only LoRA on attention layers. The model never emits the new tokens. What is the fix?

  1. A.Raise the LoRA rank on attention to 256
  2. B.Lower the learning rate on the attention layers
  3. C.Remove the tokens from the training data
  4. D.Also train the embedding and output layers (modules_to_save)
Show answer

Answer: D. Also train the embedding and output layers (modules_to_save)

The new rows in the embedding and lm_head matrices stay at their initial values if those layers are frozen, so the model cannot read or produce them well. Making those layers trainable, or adding LoRA to them, lets the new tokens be learned.

25. Parameters in the embedding matrix

A model has a vocabulary of 50,000 tokens and a hidden size of 4,096. How many parameters are in its token embedding matrix?

  1. A.20.48 million
  2. B.2.048 billion
  3. C.54.1 thousand
  4. D.204.8 million
Show answer

Answer: D. 204.8 million

The embedding matrix has one row of size d_model per token: 50,000 × 4,096 = 204,800,000 parameters. In fp16 that is about 410 MB on its own. If the output LM head is a separate matrix of the same shape, it adds the same again.

26. Doubling context length

You double the input length from 8K to 16K tokens. Ignoring the feed-forward layers, roughly how does the compute for the attention score step change?

  1. A.About 2 times more, because it grows linearly with length
  2. B.About the same, because heads run in parallel
  3. C.About 4 times more, because it grows with the square of length
  4. D.About 8 times more, because it grows with the cube of length
Show answer

Answer: C. About 4 times more, because it grows with the square of length

Computing QKᵀ compares every token with every other token, so the work scales with n². Going from n to 2n gives (2n)² = 4n². The feed-forward layers scale linearly, so the total model cost grows by less than 4× at moderate lengths, but attention dominates at very long contexts.

27. Where cross-attention gets its inputs

In an encoder-decoder transformer such as T5, the decoder has a cross-attention layer. Where do its queries and its keys/values come from?

  1. A.Queries from the encoder output; keys and values from the decoder
  2. B.Queries from the decoder; keys and values from the encoder output
  3. C.Queries, keys and values all from the decoder's previous layer
  4. D.Queries, keys and values all from the raw input embeddings
Show answer

Answer: B. Queries from the decoder; keys and values from the encoder output

Cross-attention lets each decoder position look up relevant parts of the source. The decoder supplies the question (queries), and the encoder's final hidden states supply what can be found (keys) and what is returned (values). Self-attention layers, by contrast, take all three from the same sequence.

28. Multi-query versus grouped-query attention

Multi-query attention (MQA) uses a single key/value head shared by all query heads. Why did many newer models choose grouped-query attention (GQA) instead?

  1. A.GQA needs no KV cache at all during generation
  2. B.MQA cannot be used with a causal mask in decoder models
  3. C.GQA keeps most of MQA's memory saving with less loss in quality
  4. D.GQA lets each query head see a different context length
Show answer

Answer: C. GQA keeps most of MQA's memory saving with less loss in quality

MQA gives the biggest KV-cache and bandwidth saving but can hurt quality and training stability. GQA is the middle ground: a few KV heads, each shared by a group of query heads. Llama 2 70B, Llama 3 and many others use GQA for this reason.

29. Why LLMs stumble on arithmetic

A tokenizer encodes "1234567" as the pieces "123", "45", "67", but "1234568" as "123", "456", "8". How does this help explain weak arithmetic in some LLMs?

  1. A.Numbers are always mapped to the UNK token and lost
  2. B.The model sees each number as a single token with no internal digits
  3. C.Digits are grouped unevenly, so place value is not lined up across numbers
  4. D.Digit tokens are removed before the text reaches the model
Show answer

Answer: C. Digits are grouped unevenly, so place value is not lined up across numbers

Merges are learned from frequency, so the same digit position can land in different tokens for different numbers. The model must learn arithmetic over inconsistent chunks, which is hard. Some tokenizers split numbers into single digits or fixed groups of three for this reason, and tool calls are safer for exact maths.

30. The space before a word

In GPT-style tokenizers, "hello" at the start of a string and " hello" after a space often get different token ids. Why?

  1. A.The tokenizer lowercases words only when they follow a space
  2. B.The leading space is merged into the token, so the two are different strings
  3. C.Words after a space are always split into single characters
  4. D.Token ids depend on the word's position in the sentence
Show answer

Answer: B. The leading space is merged into the token, so the two are different strings

Byte-level BPE treats the space as part of the following word, so " hello" is a common merged token while "hello" without a space is a different entry. This matters for prompt endings, few-shot formats and logit-bias tricks, where you must target the exact token the model would produce.

31. Choosing a vocabulary size

You are training a tokenizer for an English-Arabic-Hindi model. What is the main trade-off when raising vocabulary size from 32K to 256K?

  1. A.Longer sequences, but a smaller embedding layer and faster softmax
  2. B.Shorter sequences, but a bigger embedding and output layer and rarer tokens
  3. C.No change in sequence length, but the model loses multilingual ability
  4. D.Better arithmetic, but the model can no longer handle code
Show answer

Answer: B. Shorter sequences, but a bigger embedding and output layer and rarer tokens

A bigger vocabulary packs more text into each token, which shortens sequences and saves context, especially for non-English scripts. The cost is a larger V × d embedding and LM head, a bigger softmax, and many tokens that appear rarely and stay under-trained. Multilingual models often use 100K to 256K tokens for this reason.

32. Parameters in one transformer block

For a standard block with d_model = 4,096, a 4× feed-forward expansion and no biases, the rule of thumb is about 12·d² parameters per layer. Roughly how many is that?

  1. A.About 50 million
  2. B.About 16.8 million
  3. C.About 805 million
  4. D.About 201 million
Show answer

Answer: D. About 201 million

Attention has four d × d projections (Q, K, V, output), which is 4d². The feed-forward has two d × 4d matrices, which is 8d². Total 12d² = 12 × 4,096² = 12 × 16,777,216 ≈ 201 million. A 32-layer stack is then about 6.4 billion, plus embeddings.

33. Which tokens get loss in SFT

In chat SFT, many recipes set the label to −100 for system and user tokens. What does this achieve?

  1. A.The user's words are deleted from the input so the context is shorter
  2. B.The model gets a bonus for copying the user's words exactly
  3. C.Loss is computed only on the assistant reply, so the model learns to answer
  4. D.Training runs faster because attention skips those positions
Show answer

Answer: C. Loss is computed only on the assistant reply, so the model learns to answer

In PyTorch's cross-entropy, label −100 is ignored. The model still reads the prompt tokens as context, but it is not trained to predict them. This focuses learning on producing good replies instead of imitating user messages.

34. Reusing a long shared system prompt

Every request to your bot starts with the same 6,000-token system prompt. Which feature cuts both latency and cost most directly?

  1. A.Raising the temperature so the model reads faster
  2. B.Switching from top-p sampling to greedy decoding
  3. C.Prefix caching, so the shared prompt's KV cache is reused
  4. D.Increasing max output tokens to 8,000
Show answer

Answer: C. Prefix caching, so the shared prompt's KV cache is reused

With prefix caching, the server keeps the KV cache for a prompt prefix it has seen and skips recomputing it on later requests. TTFT drops, and many providers bill cached input tokens at a large discount. The prefix must match exactly, token for token.

35. Memory for a 70B model at 4-bit

Roughly how much memory do the weights of a 70B-parameter model need at 4-bit quantisation, ignoring small overheads for scales?

  1. A.About 70 GB
  2. B.About 35 GB
  3. C.About 140 GB
  4. D.About 17.5 GB
Show answer

Answer: B. About 35 GB

4 bits is half a byte, so 70 × 10⁹ × 0.5 = 35 × 10⁹ bytes, about 35 GB. In fp16 the same model needs about 140 GB. Group-wise scales add a few percent, and the KV cache comes on top.

36. Guaranteeing valid JSON output

Structured-output features can guarantee the reply matches a JSON schema. How does constrained decoding achieve this?

  1. A.It asks the model to try again until the JSON parses
  2. B.It writes the JSON with a template and lets the model fill one field
  3. C.At each step it masks tokens that would break the schema before sampling
  4. D.It fine-tunes the model on JSON before each request
Show answer

Answer: C. At each step it masks tokens that would break the schema before sampling

The schema is compiled into a grammar or state machine. At every step, tokens that cannot lead to valid output get their probability set to zero, so the model can only pick allowed tokens. The output is valid by construction, though the content can still be wrong.

37. Different answers at temperature 0

You call a hosted model with temperature 0 and the same prompt ten times. Two of the replies differ slightly. What is the most likely reason?

  1. A.Temperature 0 means maximum randomness in most hosted APIs
  2. B.Server batching changes float maths, flipping near-tied tokens
  3. C.The model is retrained between your calls
  4. D.The tokenizer picks a random encoding of the prompt each time
Show answer

Answer: B. Server batching changes float maths, flipping near-tied tokens

Temperature 0 means greedy decoding, but GPU kernels may sum numbers in different orders depending on batch size and load. Tiny numeric differences can flip the top token when two are nearly tied, and the outputs then diverge. Do not rely on perfect determinism from shared hosted endpoints.

38. Bigger batches on an LLM server

You raise the maximum batch size on your inference server from 8 to 64 concurrent sequences. What usually happens?

  1. A.Each user's reply gets faster and total throughput drops
  2. B.Nothing changes, because GPUs process one sequence at a time
  3. C.Total tokens per second rises, but each user's tokens come a bit slower
  4. D.The model's answers become more accurate
Show answer

Answer: C. Total tokens per second rises, but each user's tokens come a bit slower

Decode is memory-bound, so one weight read can serve many sequences, and throughput grows a lot with batch size. Each step does more work, though, so per-request inter-token latency rises, and the KV cache limits how far you can go. Pick the batch size from your latency target.

39. Why step-by-step reasoning helps

Why does letting a model write intermediate reasoning steps before its answer often improve accuracy on multi-step problems?

  1. A.It makes the model switch to a larger set of weights
  2. B.Each token adds compute, and earlier steps become context
  3. C.It reduces the number of tokens the model must generate
  4. D.It disables sampling so the model becomes deterministic
Show answer

Answer: B. Each token adds compute, and earlier steps become context

A transformer does a fixed amount of computation per token. Writing out steps gives it more computation and lets each later step attend to earlier results, like scratch work on paper. Reasoning models are trained to use this test-time compute well.

40. Patch tokens in a 224 × 224 image

A ViT uses 16 × 16 patches on a 224 × 224 image. How many patch tokens does it produce, not counting any class token?

  1. A.224
  2. B.256
  3. C.196
  4. D.14
Show answer

Answer: C. 196

Each side has 224 / 16 = 14 patches, so there are 14 × 14 = 196 patch tokens. Adding a [CLS] token gives 197. The count, and so the attention cost, grows with the square of the image side.

Transformers interview questions for experienced candidates hard

41. Parameters in a multi-head attention block

A multi-head attention block has d_model = 512 and 8 heads, with Q, K, V and output projections and no biases. How many parameters does it have?

  1. A.262,144
  2. B.1,048,576
  3. C.2,097,152
  4. D.8,388,608
Show answer

Answer: B. 1,048,576

Each of the four projections is a 512 x 512 matrix, so 4 * 262,144 = 1,048,576. Splitting into 8 heads of size 64 only reshapes these projections; it does not add parameters. Distractors come from counting one projection or multiplying by the head count.

42. Fine-tuned model forgets general skills

After full fine-tuning on a narrow support dataset, your LLM handles support tickets well but has lost general reasoning and formatting skills. What is the best response?

  1. A.Train for more epochs on the same narrow data
  2. B.Raise the learning rate tenfold and retrain
  3. C.Re-initialise the pre-trained weights and start over
  4. D.Mix in general data, lower the LR or use adapters, and track general evals
Show answer

Answer: D. Mix in general data, lower the LR or use adapters, and track general evals

This is catastrophic forgetting: large updates on narrow data overwrite general abilities. Replaying some general data, using smaller learning rates or fewer epochs, and parameter-efficient methods like LoRA limit how far weights move. A regression suite of general tasks catches it before release.

43. Why long contexts eat GPU memory

When serving a self-hosted LLM, GPU memory runs out as users send longer prompts and you increase concurrency. What mainly grows with sequence length and batch size?

  1. A.The model weights
  2. B.The KV cache: stored key and value tensors for every token, layer and request
  3. C.The tokenizer vocabulary
  4. D.The embedding table
Show answer

Answer: B. The KV cache: stored key and value tensors for every token, layer and request

Model weights are fixed in size, but the KV cache stores attention keys and values for each token in each layer for every active request, so it grows roughly with sequence length times batch size. Techniques like paged attention, KV cache quantisation and grouped-query attention reduce this cost.

44. Extending RoPE by position interpolation

A model was trained with RoPE at 4K context. To use it at 16K, a team applies position interpolation before a short fine-tune. What does position interpolation do?

  1. A.Scales positions down by 4 so 16K positions map into the trained 0–4K range
  2. B.Repeats the 4K position pattern four times across the 16K sequence
  3. C.Replaces RoPE with learned absolute embeddings for positions over 4K
  4. D.Drops every fourth token so the sequence fits in 4K positions
Show answer

Answer: A. Scales positions down by 4 so 16K positions map into the trained 0–4K range

Rotation angles past 4K were never seen in training, so extrapolating to them breaks attention. Interpolation multiplies each position by 4K/16K, keeping all angles inside the trained range, and a short fine-tune adapts the model to the finer spacing. Methods like NTK-aware scaling and YaRN refine this idea.

45. Decoder with no positional encoding

Research shows a decoder-only transformer trained with no positional encoding at all (NoPE) can still learn word order. How is that possible?

  1. A.The tokenizer secretly adds a position number to each token id
  2. B.The feed-forward layers sort the tokens back into order
  3. C.Under the causal mask each position sees a different count of tokens
  4. D.It cannot; such models produce identical outputs for shuffled text
Show answer

Answer: C. Under the causal mask each position sees a different count of tokens

With a causal mask, position 1 attends to one token, position 100 to a hundred, so attention averages differ systematically with position. The model can learn to read this signal and recover order. An encoder with full bidirectional attention has no such asymmetry and really is order-blind without positions.

46. Sliding cache that drops the first tokens

To stream very long chats, you keep only the latest 4,000 tokens in the KV cache. As soon as the earliest tokens are evicted, output quality collapses. What is a known fix?

  1. A.Always keep the first few tokens, which act as attention sinks
  2. B.Lower the temperature so the model depends less on old tokens
  3. C.Evict the most recent tokens instead of the oldest ones
  4. D.Double the number of attention heads at inference time
Show answer

Answer: A. Always keep the first few tokens, which act as attention sinks

Many heads park excess attention weight on the first tokens, which act as "attention sinks" because softmax weights must sum to 1. Evicting them shifts that weight onto random tokens and breaks the model. StreamingLLM showed that keeping a handful of initial tokens plus a recent window restores stable quality.

47. Subtracting the max in softmax

Production softmax kernels compute exp(x − max(x)) instead of exp(x). Why is this safe and why is it done?

  1. A.Softmax is unchanged by subtracting a constant, and it stops exp() from overflowing
  2. B.It makes the largest probability exactly 1 so decoding is greedy
  3. C.It changes the distribution slightly but makes training faster
  4. D.It is only needed when the vocabulary has more than 65,536 tokens
Show answer

Answer: A. Softmax is unchanged by subtracting a constant, and it stops exp() from overflowing

Softmax(x) = softmax(x − c) for any constant c, because exp(−c) cancels in the numerator and denominator. Using c = max(x) makes every exponent ≤ 0, so no value overflows to infinity, which matters a lot in fp16 and bf16. The output is mathematically the same.

48. NaNs from a fully masked row

Training is fine until a batch contains an example that is entirely padding. The loss becomes NaN. Your mask fills masked scores with −inf. What is the likely cause?

  1. A.−inf is converted to +inf in bf16, so pad tokens get all the weight
  2. B.Padding tokens have no embeddings, so the lookup returns NaN
  3. C.The learning rate is too high only for padded examples
  4. D.A row where every score is −inf gives softmax 0/0, which is NaN
Show answer

Answer: D. A row where every score is −inf gives softmax 0/0, which is NaN

If every key in a row is masked, softmax computes exp(−inf)/Σexp(−inf) = 0/0 = NaN, and the NaN spreads through the network. Fixes include using a large finite negative number like the dtype minimum, skipping fully masked rows, or making sure every query can attend to at least one token.

49. Prompt that ends with a space

A few-shot prompt ends with "Answer: " (with a trailing space). Completions are worse than when the prompt ends with "Answer:". Why?

  1. A.Trailing spaces are stripped by the API, so the prompt is cut short
  2. B.The space is read as an end-of-sequence marker and stops generation
  3. C.Spaces count double against the context window, so examples are dropped
  4. D.Words are tokens with a leading space, so the model must now emit a rare space-less token
Show answer

Answer: D. Words are tokens with a leading space, so the model must now emit a rare space-less token

In GPT-style tokenizers the space usually belongs to the next word, as in " Paris". If the prompt already ends with a space token, the model must continue with "Paris" without a leading space, which is a much rarer token in that spot. This boundary effect is why some libraries do "token healing".

50. Merge or keep LoRA adapters separate

You have one base model and 40 customer-specific LoRA adapters. Traffic mixes all customers in each batch. What serving approach fits best?

  1. A.Merge all 40 adapters into the base weights by adding them together
  2. B.Keep adapters unmerged and use a server that applies the right one per request
  3. C.Deploy 40 full merged copies of the model on separate GPUs
  4. D.Retrain one adapter on all customers' data and drop the rest
Show answer

Answer: B. Keep adapters unmerged and use a server that applies the right one per request

Merging (W + BA) removes adapter latency but only works for one adapter per copy of the model. Multi-LoRA servers such as vLLM or LoRAX keep one base in memory and apply each request's small adapter in batched kernels. Summing 40 adapters would blend customers' behaviour together.

51. Teaching new facts by fine-tuning

A bank wants its chatbot to know this month's changing interest rates. A teammate proposes monthly LoRA fine-tunes on the rate sheet. What is the main concern?

  1. A.LoRA cannot be used on any model larger than 1B parameters
  2. B.Fine-tuning injects facts poorly; retrieving the sheet fits better
  3. C.Fine-tuning always erases the model's ability to speak English
  4. D.Rates are numbers, and transformers cannot store numbers at all
Show answer

Answer: B. Fine-tuning injects facts poorly; retrieving the sheet fits better

Fine-tuning is good at teaching format, style and behaviour, but models absorb new facts slowly and may blend old and new values. Studies also link training on unfamiliar facts to more hallucination. For facts that change often, retrieving the current rate sheet at query time is more accurate and auditable.

52. Token probabilities after RLHF

You use a chat model's token probabilities as confidence scores for multiple-choice answers. They were well calibrated on the base model but are overconfident on the RLHF-tuned model. Why?

  1. A.RLHF changes the tokenizer, so the probabilities refer to new tokens
  2. B.Preference tuning pushes outputs towards confident answers, hurting calibration
  3. C.Base models are never calibrated, so the earlier result was luck
  4. D.The KL penalty forces all probabilities to equal 0.5
Show answer

Answer: B. Preference tuning pushes outputs towards confident answers, hurting calibration

Pretraining with cross-entropy tends to produce calibrated next-token probabilities. RLHF optimises for rewarded answers rather than likelihood, and the distribution often becomes sharper, so 90% stated confidence may be right far less often. Recalibrate on held-out data, for example with temperature scaling.

53. Fine-tuned model never stops talking

After SFT, your model keeps generating past the answer until max_tokens. The training code sets pad_token = eos_token and masks all pad positions out of the loss. What is the bug?

  1. A.The real EOS was masked too, so the model never learned to emit it
  2. B.max_tokens is ignored whenever pad and EOS share an id
  3. C.The learning rate was too low to learn short answers
  4. D.Masking pad tokens makes the model forget the chat template
Show answer

Answer: A. The real EOS was masked too, so the model never learned to emit it

If PAD and EOS share an id and every pad-id position is masked, the true end-of-reply EOS gets masked as well. The model never sees a loss for stopping, so it learns to keep going. Use a separate pad token or mask by attention mask so the first EOS keeps its label.

54. Sizing GPUs for an MoE model

A teammate says: "This MoE model has 47B total but only 13B active parameters, so it fits on the same GPU as a 13B dense model." What is wrong with this?

  1. A.Nothing; only active parameters ever need to be loaded
  2. B.MoE models need more memory than their total parameter count
  3. C.All 47B must be resident, since any token may route to any expert
  4. D.Active parameters are always larger than the total in practice
Show answer

Answer: C. All 47B must be resident, since any token may route to any expert

Active parameters set the compute per token, but routing changes from token to token, so every expert's weights must be available. In fp16 the 47B model needs about 94 GB just for weights versus about 26 GB for 13B dense. Offloading experts is possible but slows decoding a lot.

55. Greedy decoding stuck in a loop

A small model with greedy decoding writes "The product is great. The product is great. The product is great..." Why does greedy decoding fall into such loops?

  1. A.Greedy decoding has a bug that copies the previous sentence
  2. B.The model ran out of vocabulary and reused old tokens
  3. C.The stop sequence was too long for the model to produce
  4. D.Each repeat makes repeating again the most likely next step
Show answer

Answer: D. Each repeat makes repeating again the most likely next step

Attention can copy patterns from context, so each repetition makes the next repetition more probable, a self-reinforcing loop. Greedy decoding never takes a lower-probability exit. Sampling with top-p, repetition or frequency penalties, or n-gram blocking breaks the cycle.

56. Long prompts slowing other users

On a shared server, whenever someone sends a 100K-token prompt, every other user's streaming output pauses for a few seconds. Which technique targets this?

  1. A.Raising the temperature for the long-prompt request only
  2. B.Turning off the KV cache for every request on the server
  3. C.Chunked prefill, mixing prompt chunks with decode steps
  4. D.Using beam search for the shorter requests
Show answer

Answer: C. Chunked prefill, mixing prompt chunks with decode steps

A huge prefill can fill the GPU for seconds, and decode steps for other requests wait behind it. Chunked prefill processes the long prompt in pieces mixed with ongoing decode work, smoothing inter-token latency. Some systems go further and run prefill and decode on separate GPU pools.

57. JSON parse errors on long outputs

About 3% of your JSON responses fail to parse, all of them for the longest documents. The model otherwise follows the schema well. What should you check first?

  1. A.Whether the finish reason is "length", meaning the output was cut off
  2. B.Whether the temperature is above 0.2 for those requests
  3. C.Whether the model was updated by the provider that week
  4. D.Whether the JSON keys use camelCase or snake_case
Show answer

Answer: A. Whether the finish reason is "length", meaning the output was cut off

Long inputs often need long outputs, and hitting max_tokens truncates the JSON mid-object even under schema constraints. Always check the finish reason before parsing. Raise the limit, shorten fields, or split the task when outputs are long.

58. Ordering prompts for cache hits

Your prompt is: current date and user name, then a 5,000-token policy manual, then the question. Prompt caching is on, but cache hits are almost zero. What fix gives the most benefit?

  1. A.Shorten the manual to under 1,000 tokens so it fits the cache
  2. B.Move the fixed manual to the very start and put the date and name after it
  3. C.Turn off streaming so the cache can store the full output
  4. D.Send the manual as a separate request before every question
Show answer

Answer: B. Move the fixed manual to the very start and put the date and name after it

Prefix caching only reuses an exact token prefix. With the changing date and name at the top, every prompt differs from the first token, so nothing matches. Putting stable content first and variable content last lets every request reuse the manual's cached KV.

59. GPU at low utilisation during decoding

During single-user decoding, GPU compute utilisation is about 5%, yet tokens/s will not go higher. Adding more concurrent users barely slows each one at first. What explains this?

  1. A.The GPU is throttling its clock because it is too hot
  2. B.The tokenizer runs on the GPU and blocks the model
  3. C.Decode waits on weight reads, which extra sequences share
  4. D.Each user is served by a separate idle GPU core
Show answer

Answer: C. Decode waits on weight reads, which extra sequences share

At batch size 1, each step reads all weights for one matrix-vector product, so arithmetic intensity is tiny and the GPU waits on memory. Adding sequences turns it into a matrix-matrix product that reuses the same bytes, so throughput rises almost for free until compute or KV-cache memory becomes the limit.

60. State-space models versus attention

Mamba-style state-space models keep a fixed-size state instead of a growing KV cache. What is the main trade-off compared with attention?

  1. A.Better exact recall, but memory that grows faster than attention's
  2. B.Constant memory per token, but weaker exact recall of details far back
  3. C.No training needed, but they only work on short inputs
  4. D.Faster prefill, but they cannot generate text at all
Show answer

Answer: B. Constant memory per token, but weaker exact recall of details far back

A fixed state means generation costs the same per token regardless of length, which suits very long inputs. But everything must be compressed into that state, so copying an exact phone number from 50K tokens ago is harder than for attention, which can look it up directly. Hybrid models mix both layer types.

Ready to test yourself?

Take a 15-question Transformers MCQ test with a score at the end, or practise the full Transformers question bank and earn points on the leaderboard.