Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

[FIX] Move labels to logits device in cross-entropy loss for multi-GPU support (#4041) (#4059)

anonymous devba1688c609e7
diff --git a/unsloth/kernels/cross_entropy_loss.py b/unsloth/kernels/cross_entropy_loss.py
index fbb14013ff6..cdd5b1cf12c 100644
--- a/unsloth/kernels/cross_entropy_loss.py
+++ b/unsloth/kernels/cross_entropy_loss.py
@@ -301,6 +301,7 @@ class Fast_CrossEntropyLoss(torch.autograd.Function):
vocab_size: int
n_rows, vocab_size = logits.shape
device = logits.device
+ labels = labels.to(device)
div, mod = divmod(vocab_size, MAX_FUSED_SIZE)
n_chunks: int = div + (mod != 0)