Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match the default ignore index to PyTorch's #1076

Merged
merged 1 commit into from
Mar 9, 2024

Conversation

carmocca
Copy link
Contributor

@carmocca carmocca commented Mar 9, 2024

PyTorch's default ignore_index value is -100: https://pytorch.org/docs/stable/generated/torch.nn.functional.cross_entropy.html

I don't know if there's a reason for having a different default. Maybe we just copied this from https://github.com/karpathy/nanoGPT/blob/325be85d9be8c81b436728a420e85796c57dba7e/model.py#L187

But matching the default value can enable lowering to faster kernels that don't implement support for values different than -100. For example https://github.com/unslothai/unsloth/blob/a0cc0d163843a403a23e5cd94d20121690bd6830/unsloth/kernels/cross_entropy_loss.py#L65 or https://github.com/NVIDIA/apex/blob/b496d85fb88a801d8e680872a12822de310951fd/apex/contrib/csrc/xentropy/xentropy_kernel.cu#L703

@carmocca carmocca self-assigned this Mar 9, 2024
@carmocca carmocca merged commit 09142e5 into wip Mar 9, 2024
7 of 8 checks passed
@carmocca carmocca deleted the carmocca/default-100-ignore-idx branch March 9, 2024 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants