KatInterview

KL Divergence: From Definition to LLM Training

Machine LearningModel answer
HardModel answerMachine Learningkl-divergencelanguage-modelsrlhf

Last updated

Define KL divergence, explain its asymmetry and support requirements, and walk through how it appears in language model training and alignment.

KL Divergence in Language Model Training

Information-theoretic quantities show up throughout modern ML, and KL divergence is one of the most frequently misunderstood. This question tests whether you can move from the mathematical definition all the way to practical consequences in large language model (LLM) training pipelines.

Your Task

Answer the following, in order:

  1. Definition — Write out the formula for KL divergence between two distributions P and Q over the same discrete random variable. State what the quantity measures, when it equals zero, and whether it can be negative.

  2. Asymmetry — KL(P ∥ Q) ≠ KL(Q ∥ P) in general. Give an intuitive explanation of the difference, and describe what each direction penalizes in practice.

  3. Support mismatch — What happens when Q assigns zero probability to an event that P considers possible? What about the reverse? How does this affect which distribution you choose as the reference?

  4. Token-level vs. sequence-level — In practice, KL is computed token-by-token rather than over entire sequences. Explain why, and describe any gap this introduces relative to the true objective.

  5. LLM use cases — Describe at least two concrete places where KL divergence appears during LLM training or post-training fine-tuning (for example, alignment or distillation), including what the two distributions are in each case and what the KL term is meant to accomplish.

Constraints and Framing

  • Both distributions are over the same vocabulary of tokens.
  • KL divergence is not symmetric and is not a distance metric.
  • When discussing estimation, assume the expectation is approximated with samples rather than computed exactly.
  • Be precise about which distribution is the reference and which is being optimized.

Hints

Hint 1

Start from the raw formula: KL(P ∥ Q) = Σ P(x) log(P(x)/Q(x)). Ask yourself: whose expectation is this taken under, and what does that mean when Q is nearly zero somewhere?

Hint 2

For asymmetry, think about what 'mean-seeking' versus 'mode-seeking' behavior looks like when you fit a unimodal Q to a multimodal P, and vice versa. One direction forces Q to cover everything P puts mass on; the other lets Q ignore some modes.

Hint 3

In RLHF and related alignment methods, the policy being trained is one distribution and the original frozen model is another. Think about which one you want as the reference and why — then consider what would go wrong if you swapped them.