mlx.core.fast.cross_entropy#
- cross_entropy(logits: array, targets: array, *, stream: StreamOrDevice = None) array#
Cross entropy loss with class indices as targets.
Computes
logsumexp(logits, axis=-1) - logits[..., target]in a fused kernel with accumulation in float32.Note: The fused kernel is available on Metal and CUDA. The CPU falls back to the unfused version, which reduces in the dtype of the logits.
- 參數:
- 回傳值:
The per-element loss in float32, with the shape of
targets.- 回傳值型別: