LLM Learning Roadmap
✨ Awesome-Anything
🖼️ Digital Image Processing
🍃 LLM Components
🌱 LLM Pre-training
☘️ LLM Post-Training
🍀 LLM Popular Models
🪴 LLM Applications
🌿 LLM Optimization
🌾 LLM Compression
🌵 LLM Hands-on Practice
🌴 LLM Must-read Papers
🌳 LLM Q&A
🐝 VLM Image Encoders
📝 MISC.
10.3 KL(P||Q) or KL(Q||P)?
ㅤ | Format | Penalty | Usage |
Forward KL | The true distribution is P, and we use Q to approximate it. It penalizes places where P has probability but Q does not. | Variational Inference, mass-covering, etc. | |
Reverse KL | The true distribution is Q, and we use P to approximate it. It penalizes places where Q has probability but P does not. | GANs, mode-seeking, etc. |
We talked about the mass-covering in 3.5.7 TDPO Algorithm as well.
In the case of training a machine learning model (e.g., DL, LLM, etc.), let’s say we have as the real distribution and as the distribution that approximates the real one, where the is parameterized by the model parameters and we have as .
- Forward KL (mass-covering):
This KL encourages to cover all possible regions of . would rather be too broad than miss any part of . Therefore, this KL is adopted by TDPO to improve the diversity of generated responses. It is also suitable for variational inference because we prefer to cover rather than miss key areas.
- Reverse KL (mode-seeking):
This KL encourages to focus on the most probable regions, ignoring uncommon areas. This is commonly used in maximum likelihood estimation (MLE) or generative adversarial networks (GANs), as it tends to find the most likely explanation. It is also why GANs tend to mode collapse, which occurs when the generator produces a limited set of outputs, lacking the diversity expected from the training data distribution.
Example Code


WHY Forward KL usually has a larger loss than Reverse KL?
- Forward KL is mass-covering, penalizing regions where Q fails to cover P
Mathematically:
When but :
So the KL value becomes very large. In other words, Forward KL is very sensitive to missing probability mass, especially when Q fails to cover the tail or modes of P, resulting in very large penalties.
- Reverse KL is mode-seeking, more likely to "avoid" difficult regions
Mathematically:
When but : There’s a large penalty, but during optimization, Q can actively avoid such regions (because it decides where to place its mass).
So during optimization, Reverse KL tends to greedily choose one mode, ignoring the full support of P, which can make the loss appear small.
Prev
10.2 VLM-R1 Reproduction Results
Next
10.4 Left Padding or Right Padding?
Loading...