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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
[FIX] Move loss and n_items to logits device in fast_cross_entropy_loss loss for multi-GPU support (#4063)
nole69e3c9482cfb6d
diff --git a/unsloth/kernels/cross_entropy_loss.py b/unsloth/kernels/cross_entropy_loss.pyindex cdd5b1cf12c..d92229314fa 100644--- a/unsloth/kernels/cross_entropy_loss.py+++ b/unsloth/kernels/cross_entropy_loss.py@@ -438,6 +438,7 @@ def fast_cross_entropy_loss(batch, seq_len, d = logits.shapeassert labels.shape == (batch, seq_len)+ device = logits.deviceloss = Fast_CrossEntropyLoss.apply(logits.view(batch * seq_len, d),labels.view(-1),@@ -446,6 +447,8 @@ def fast_cross_entropy_loss()if n_items is None:n_items = torch.count_nonzero(labels != -100)+ if torch.is_tensor(n_items):+ n_items = n_items.to(device)return loss.sum() / n_items