Compute the common GRPO/PPO reference KL approximation.
(
current_logps: torch.Tensor,
ref_logps: torch.Tensor,
mask: torch.Tensor | None = None,
)
| 93 | |
| 94 | |
| 95 | def compute_reference_kl( |
| 96 | current_logps: torch.Tensor, |
| 97 | ref_logps: torch.Tensor, |
| 98 | mask: torch.Tensor | None = None, |
| 99 | ) -> torch.Tensor: |
| 100 | """Compute the common GRPO/PPO reference KL approximation.""" |
| 101 | |
| 102 | diff = ref_logps.float() - current_logps.float() |
| 103 | kl = torch.exp(diff) - diff - 1.0 |
| 104 | if mask is not None: |
| 105 | kl = kl.masked_fill(~_bool_mask(mask, device=kl.device), 0.0) |
| 106 | return kl |
| 107 | |
| 108 | |
| 109 | def summarize_kernel_drift( |