Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion unsloth/kernels/cross_entropy_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
triton_tanh,
triton_cast,
torch_gpu_device,
is_cdna,
)
from transformers.models.llama.modeling_llama import logger
from packaging.version import Version
Expand Down Expand Up @@ -332,7 +333,7 @@ def forward(ctx, logits, labels, logit_softcapping : float = 0, logit_scaling :
SOFTCAP = logit_softcapping,
DO_LOGIT_SCALING = DO_LOGIT_SCALING,
LOGIT_SCALE = logit_scaling,
num_warps = 32,
num_warps = 32 if not is_cdna() else 16,
)
# logsumexp(chunked_logsumexp) - x
# Do the -x separately
Expand Down
8 changes: 8 additions & 0 deletions unsloth/kernels/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ def triton_cast(x, dtype):
pass


def is_hip():
return triton.runtime.driver.active.get_current_target().backend == "hip"


def is_cdna():
return is_hip() and triton.runtime.driver.active.get_current_target().arch in ('gfx940', 'gfx941', 'gfx942')


def calculate_settings(n : int) -> (int, int,):
BLOCK_SIZE : int = next_power_of_2(n)
if BLOCK_SIZE > MAX_FUSED_SIZE:
Expand Down