-
Notifications
You must be signed in to change notification settings - Fork 519
CrossEntropyLoss fail to detect the negative index #4552
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
Comments
I was trying to look into this issue myself. This cross_entropy_loss op defined in the torch |
I think cross_entroy_loss was dispatch to |
Thanks Jack. Seems
How could I find this mapping relationship from code? |
I think it is |
Could you elaborate more about that dispatcher logic lives upstream? I was reading this op-lowering-guide and my impression was that ops defined in native_functions.yaml will be mapped to |
@YangFei1990 It's related to how this op is lowered and I'm not sure xla can provide similar assertion at runtime. In this case, the label will be converted to one hot vector and the label with invalid index will become vector of all 0s. xla/torch_xla/csrc/nll_loss.cpp Lines 43 to 50 in e0eb2a7
|
I was able to reproduce this on: c4b45a9 (Apr 28, 2025) |
🐛 Bug
The
torch.nn.CrossEntropyLoss
should only takes target that has each value with[0,num_class)
. However on XLA device it could take negative values and output results.To Reproduce
Check the below script
On CPU it will throw error
IndexError: Target -1 is out of bounds.
, however on XLA device it will output some tensorExpected behavior
Same error on XLA device
Environment
The text was updated successfully, but these errors were encountered: