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
Update cross_entropy_loss.py
Daniel Han006bafb437a0
diff --git a/unsloth/kernels/cross_entropy_loss.py b/unsloth/kernels/cross_entropy_loss.pyindex 11e582711d5..91b57fe85d9 100644--- a/unsloth/kernels/cross_entropy_loss.py+++ b/unsloth/kernels/cross_entropy_loss.py@@ -38,10 +38,10 @@ def _cross_entropy_forward(labels_ptr ,VOCAB_SIZE : tl.constexpr,BLOCK_SIZE : tl.constexpr,- DO_SOFTCAPPING ,- SOFTCAP ,- DO_LOGIT_SCALING ,- LOGIT_SCALE ,+ DO_SOFTCAPPING : tl.constexpr,+ SOFTCAP : tl.constexpr,+ DO_LOGIT_SCALING : tl.constexpr,+ LOGIT_SCALE : tl.constexpr,):"""Cross Entropy Loss = 1/n sum [ -yi log(Pi) ]@@ -64,7 +64,7 @@ def _cross_entropy_forward(This ensures exp(x - max(x))'s maximum is 1 as exp(0) = 1."""row_idx = tl.program_id(0)- logits_ptr += row_idx * logits_row_stride.to(tl.int64)+ logits_ptr += row_idx * tl.cast(logits_row_stride, tl.int64)loss_ptr += row_idxlogsumexp_ptr += row_idxlabels_ptr += row_idx@@ -112,10 +112,10 @@ def _chunked_cross_entropy_forward(VOCAB_SIZE : tl.constexpr,N_CHUNKS : tl.constexpr,BLOCK_SIZE : tl.constexpr,- DO_SOFTCAPPING ,- SOFTCAP ,- DO_LOGIT_SCALING ,- LOGIT_SCALE ,+ DO_SOFTCAPPING : tl.constexpr,+ SOFTCAP : tl.constexpr,+ DO_LOGIT_SCALING : tl.constexpr,+ LOGIT_SCALE : tl.constexpr,):"""256K vocab divided in 4 chunks@@ -143,7 +143,7 @@ def _chunked_cross_entropy_forward("""row_idx = tl.program_id(0)chunk_idx = tl.program_id(1)- logits_ptr += row_idx * logits_row_stride.to(tl.int64)+ logits_ptr += row_idx * tl.cast(logits_row_stride, tl.int64)loss_ptr += row_idxlogsumexp_ptr += row_idx * N_CHUNKS + chunk_idxlabels_ptr += row_idx@@ -195,10 +195,10 @@ def _cross_entropy_backward(labels_ptr ,VOCAB_SIZE : tl.constexpr,BLOCK_SIZE : tl.constexpr,- DO_SOFTCAPPING ,- SOFTCAP ,- DO_LOGIT_SCALING ,- LOGIT_SCALE ,+ DO_SOFTCAPPING : tl.constexpr,+ SOFTCAP : tl.constexpr,+ DO_LOGIT_SCALING : tl.constexpr,+ LOGIT_SCALE : tl.constexpr,):"""CE_i = -y log(P) = y * (log[sum(exp(x))] - x)@@ -218,7 +218,7 @@ def _cross_entropy_backward(row_idx = tl.program_id(0)block_idx = tl.program_id(1)- logits_ptr += row_idx * logits_row_stride.to(tl.int64)+ logits_ptr += row_idx * tl.cast(logits_row_stride, tl.int64)dloss_ptr += row_idx * dloss_row_stridecol_offsets = block_idx*BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)mask = col_offsets < VOCAB_SIZE