Realm

oa::ml::loss::kl_div

Compute the KL divergence loss mean(target * (log target - input)). input holds log-probabilities and target holds probabilities, matching torch.nn.functional.kl_div with log-target input. The target == 0 contribution is exact zero; targets below 1e-12 clamp before the log so the product stays finite. Errors Returns an error for mismatched, empty, or non-FP32 inputs, or when runtime recording fails.

FnRust public API

Function Documentation

pub fn kl_div( input: &Matrix, target: &Matrix ) -> Result<Matrix>
Compute the KL divergence loss mean(target * (log target - input)). input holds log-probabilities and target holds probabilities, matching torch.nn.functional.kl_div with log-target input. The target == 0 contribution is exact zero; targets below 1e-12 clamp before the log so the product stays finite. Errors Returns an error for mismatched, empty, or non-FP32 inputs, or when runtime recording fails.