LLM Fundamentals interview question

Generative AILLM FundamentalsTransformerseasy

The flow shows one generation step of a decoder-only LLM (GPT- or Llama-style). What happens at the highlighted step?

1Tokenize the prompt
→
2Token embeddings+ position information
→
3Stack of decoder blocksmasked self-attention + MLP
→
4Final normalisationLayerNorm / RMSNorm
→
5?
→
6Pick the next tokengreedy, top-p, …
→
7Append the token to the sequence
↺ Loops back from step 7 (Append the token to the sequence) to step 2 (Token embeddings): repeat until an end token or the length limit
  1. ACross-attention over the encoder's output vectors, which injects the meaning of the full prompt into the decoder's state before the next token is chosen.
  2. BA softmax over the sequence positions, which selects the earlier position in the prompt whose token should be copied into the output as the next token.
  3. CDetokenization of all hidden states, which turns each position's vector back into text so the sampler can choose among complete candidate words.
  4. DThe LM head: a linear layer that maps the last position's hidden state to one logit per vocabulary token, which softmax turns into probabilities.
Show the answer and explanation

Correct answer: D, The LM head: a linear layer that maps the last position's hidden state to one logit per vocabulary token, which softmax turns into probabilities.

Explanation LLM Fundamentals

A decoder-only LLM generates text one token at a time:

  1. Tokenize the text into token IDs.
  2. Look up an embedding vector per ID; position information is added (learned positions) or applied inside attention (RoPE).
  3. Run the vectors through N decoder blocks, each with causal (masked) self-attention and an MLP, plus residual connections and normalisation.
  4. Apply a final normalisation.
  5. LM head: multiply the last position's hidden vector (size d_model) by a d_model × vocab matrix to get one logit per vocabulary token. Many models tie this matrix to the input embedding matrix.
  6. Softmax turns the logits into probabilities and a decoding rule (temperature, top-p) picks the next token; greedy decoding can simply take the argmax.
  7. Append it and repeat. With a KV cache, later steps push only the new token through the blocks and reuse the cached keys and values of earlier tokens.

Only the last position's logits are needed to generate the next token. In training, the logits at every position are used, so one forward pass yields a next-token loss for every position.

Why the other steps are wrong: cross-attention to an encoder exists in encoder-decoder models such as T5, not in decoder-only models. Choosing a position to copy from describes pointer networks, not a standard LM. Detokenization happens only after a token ID has been chosen, to show text to the user.

Interview tip: be ready to size the LM head: with d_model = 4,096 and a 128k vocabulary it holds 4,096 × 128,000 ≈ 0.5B parameters. In small models this matrix is a large share of all weights, which is why they often tie it to the input embeddings.

Practice it as a quiz

Answer this and the other free questions with instant grading, streaks and weak-topic tracking, or unlock all 4,000 questions.

More Generative AI questions

  1. From the same logits, a teacher LLM gives these next-token probabilities after "I want to ___ my subscription" (restricted to five candidate tokens): cancel…
  2. A retail client wants a customer-facing assistant over ~5,000 public help-center pages and product PDFs, live in six weeks, with a team of two engineers.…
  3. To save tokens, a bank adds an LLM extractor after retrieval that keeps only the sentences relevant to the question from each of the top 8 chunks. Context…
  4. A telecom's support assistant has no reference answers for live traffic, so the team wants implicit signals as quality proxies: the user rephrases the…
  5. A retailer trained a LoRA adapter on acme-8b (the base model). The serving team loads it onto acme-8b-instruct, which has the same architecture. It loads…