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

LigerFusedLinearCrossEntropyFunction does not support reduction=None #488

Open
Xiang-cd opened this issue Dec 18, 2024 · 1 comment · May be fixed by #496
Open

LigerFusedLinearCrossEntropyFunction does not support reduction=None #488

Xiang-cd opened this issue Dec 18, 2024 · 1 comment · May be fixed by #496
Labels
good first issue Good for newcomers

Comments

@Xiang-cd
Copy link

🐛 Describe the bug

loss = LigerFusedLinearCrossEntropyLoss(reduction='none')(model.lm_head.weight, flattened_hidden_states, flattened_target)

returns loss with shape []:
tensor(209594.4062, device='cuda:7',
grad_fn=)

reduction is actually perfromed

Reproduce

from liger_kernel.transformers import LigerCrossEntropyLoss, LigerFusedLinearCrossEntropyLoss
device3 = 'cuda'
weight = torch.randn((180000, 4096), device=device3, dtype=torch.float32)
fhidden_states = torch.randn((20, 4096), device=device3, dtype=torch.float32)
ftarget = torch.ones((20,), device=device3, dtype=torch.long)
loss = LigerFusedLinearCrossEntropyLoss(reduction='none')(weight, fhidden_states, ftarget)
print(loss)

Versions

Environment Report:

Operating System: Linux-5.4.0-135-generic-x86_64-with-glibc2.31
Python version: 3.10.14
Liger Kernel version: 0.5.2
PyTorch version: 2.5.1+cu124
CUDA version: 12.4
HIP(ROCm) version: Not available
Triton version: 3.1.0
Transformers version: 4.44.0
XPU version: XPU Not Available

@Tcc0403
Copy link
Collaborator

Tcc0403 commented Dec 21, 2024

It should be easily fixed by removing torch.sum() if reduction is "none". Similar to what LigerCrossEntropy does.

@Tcc0403 Tcc0403 added the good first issue Good for newcomers label Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
2 participants