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: Currently is implemented only on CUDA, fallback to unfused version with manual casting on Metal and CPU.
- Parameters:
- Returns:
The per-element loss in float32, with the shape of
targets.- Return type: