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

Gradient unable to backprop if we use argmax or torch.where #6

Open
anhquan0412 opened this issue Jan 10, 2023 · 3 comments
Open

Gradient unable to backprop if we use argmax or torch.where #6

anhquan0412 opened this issue Jan 10, 2023 · 3 comments

Comments

@anhquan0412
Copy link

Hi,
Correct me if I am wrong but in the code snippet to calculate D_l for the dependency loss
(

current_lvl_pred = torch.argmax(nn.Softmax(dim=1)(predictions[l]), dim=1)
), argmax is non-differentiable, thus the gradient wrt to dloss won't be propagated back to predictions variables, and subsequently to the parameters in the neural net, that means the model won't be able to learn from the dloss penalty. I have run this loss on my NLP project and the way the parameters updated are the same without any value of beta, which led me to this theory. Can you help me check this one out?

@anhquan0412
Copy link
Author

Also in check_hierarchy function, a new Float Tensor is defined, thus I don't think it will be registered in the computational graph for backprop

@VipanchiRKatthula
Copy link

+1 Even I am facing the same issue! I tried to figure out what was happening but clearly we're getting wrong argmax predictictions for prev_lvl_pred

@Ugenteraan
Copy link
Owner

Hey @anhquan0412 and @VipanchiRKatthula, apologies for the late response. After having another look, I think you are right. Thanks for pointing it out. I can't work on fixing it as of now however as I'm swamped with other works. Perhaps sometime soon. In the meantime, maybe you could look into this.

https://discuss.pytorch.org/t/differentiable-argmax/33020

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

No branches or pull requests

3 participants