Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:OpenRLHF OpenRLHF KD Loss Computation

From Leeroopedia


Knowledge Sources
Domains Model_Compression, Loss_Functions
Last Updated 2026-02-07 00:00 GMT

Overview

A loss function that measures the divergence between student and teacher model output distributions for knowledge transfer.

Description

KD Loss computes the forward KL divergence between teacher and student probability distributions at the token level. It uses teacher softmax probabilities and student log-softmax probabilities, masking out padding and prompt tokens via an ignore index. This encourages the student to match the teacher's full output distribution, not just the argmax prediction.

Usage

Used internally by KDTrainer. Combined with GPTLMLoss via a weighting coefficient (kd_coef).

Theoretical Basis

Forward KL Divergence (token-level): LKD=1|M|tMvPT(v|x<t)logPS(v|x<t)

where M is the set of non-masked positions, PT is the teacher distribution, and PS is the student distribution.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment