Masked cross-entropy over an SFT batch (B>=1).
Returns a scalar MlxArray (caller owns).
Every row is padded to the batch length L. The forward runs over
ids[:, :-1] (a single [B, L-1] pass) with a padding-aware attention mask;
the loss mask then keeps only (response AND non-padding) target positions.
Loss = sum(ce·mask) / sum(mask) — a token-mean over the whole batch, the
same reduction as mlx-lm default_loss.
Masked cross-entropy over an SFT batch (B>=1). Returns a scalar MlxArray (caller owns).
Every row is padded to the batch length L. The forward runs over ids[:, :-1] (a single [B, L-1] pass) with a padding-aware attention mask; the loss mask then keeps only (response AND non-padding) target positions. Loss = sum(ce·mask) / sum(mask) — a token-mean over the whole batch, the same reduction as mlx-lm default_loss.