KL(reference || current) averaged across batch/seq (port of _kl_from_ref): log_cur = cur - logsumexp(cur); log_ref = ref - logsumexp(ref) ref_probs = softmax(ref) mean( sum( ref_probs * (log_ref - log_cur), axis=-1 ) ) Returns the scalar KL as a JS number. Casts to f32 for stability.
_kl_from_ref
KL(reference || current) averaged across batch/seq (port of
_kl_from_ref): log_cur = cur - logsumexp(cur); log_ref = ref - logsumexp(ref) ref_probs = softmax(ref) mean( sum( ref_probs * (log_ref - log_cur), axis=-1 ) ) Returns the scalar KL as a JS number. Casts to f32 for stability.