KL divergence measures how different one probability distribution is from another :
It's everywhere in AI engineering: the KL penalty that keeps RLHF-tuned models close to the base model, distillation losses, and comparing a fine-tuned model's token distribution with the original's.
Implement kl_divergence(p, q) using the natural log.
Rules
float("inf").Note that KL is not symmetric: in general.