Update cross_entropy_loss.py
This commit is contained in:
parent
4cedfeae87
commit
c5b142e7b5
1 changed files with 13 additions and 13 deletions
|
|
@ -32,16 +32,16 @@ from unsloth_zoo.loss_utils import (
|
|||
@triton.jit
|
||||
def _cross_entropy_forward(
|
||||
logits_ptr ,
|
||||
logits_row_stride ,
|
||||
logits_row_stride : tl.constexpr(tl.int64),
|
||||
loss_ptr ,
|
||||
logsumexp_ptr ,
|
||||
labels_ptr ,
|
||||
VOCAB_SIZE ,
|
||||
VOCAB_SIZE : tl.constexpr(tl.int32),
|
||||
BLOCK_SIZE : tl.constexpr(tl.int32),
|
||||
DO_SOFTCAPPING : tl.constexpr(tl.int1),
|
||||
SOFTCAP ,
|
||||
SOFTCAP : tl.constexpr(tl.float32),
|
||||
DO_LOGIT_SCALING : tl.constexpr(tl.int1),
|
||||
LOGIT_SCALE ,
|
||||
LOGIT_SCALE : tl.constexpr(tl.float32),
|
||||
):
|
||||
"""
|
||||
Cross Entropy Loss = 1/n sum [ -yi log(Pi) ]
|
||||
|
|
@ -105,17 +105,17 @@ pass
|
|||
@triton.jit
|
||||
def _chunked_cross_entropy_forward(
|
||||
logits_ptr ,
|
||||
logits_row_stride ,
|
||||
logits_row_stride : tl.constexpr(tl.int64),
|
||||
loss_ptr ,
|
||||
logsumexp_ptr ,
|
||||
labels_ptr ,
|
||||
VOCAB_SIZE ,
|
||||
N_CHUNKS ,
|
||||
VOCAB_SIZE : tl.constexpr(tl.int32),
|
||||
N_CHUNKS : tl.constexpr(tl.int32),
|
||||
BLOCK_SIZE : tl.constexpr(tl.int32),
|
||||
DO_SOFTCAPPING : tl.constexpr(tl.int1),
|
||||
SOFTCAP ,
|
||||
SOFTCAP : tl.constexpr(tl.float32),
|
||||
DO_LOGIT_SCALING : tl.constexpr(tl.int1),
|
||||
LOGIT_SCALE ,
|
||||
LOGIT_SCALE : tl.constexpr(tl.float32),
|
||||
):
|
||||
"""
|
||||
256K vocab divided in 4 chunks
|
||||
|
|
@ -188,17 +188,17 @@ pass
|
|||
@triton.jit
|
||||
def _cross_entropy_backward(
|
||||
logits_ptr ,
|
||||
logits_row_stride ,
|
||||
logits_row_stride : tl.constexpr(tl.int64),
|
||||
dloss_ptr ,
|
||||
dloss_row_stride ,
|
||||
logsumexp_ptr ,
|
||||
labels_ptr ,
|
||||
VOCAB_SIZE ,
|
||||
VOCAB_SIZE : tl.constexpr(tl.int32),
|
||||
BLOCK_SIZE : tl.constexpr(tl.int32),
|
||||
DO_SOFTCAPPING : tl.constexpr(tl.int1),
|
||||
SOFTCAP ,
|
||||
SOFTCAP : tl.constexpr(tl.float32),
|
||||
DO_LOGIT_SCALING : tl.constexpr(tl.int1),
|
||||
LOGIT_SCALE ,
|
||||
LOGIT_SCALE : tl.constexpr(tl.float32),
|
||||
):
|
||||
"""
|
||||
CE_i = -y log(P) = y * (log[sum(exp(x))] - x)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue