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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that outputs and grad_outputs have same shape in torch.autograd.grad() #17893

zplizzi opened this issue Mar 11, 2019 · 2 comments


Copy link

commented Mar 11, 2019

馃殌 Feature

If I'm understanding things right, for every item in outputs, the corresponding item in grad_outputs should have the same shape in the function torch.autograd.grad(). If this is the case, there should be a check that the shapes are identical.


I accidentally passed a tensor (of ones) with the wrong shape as grad_outputs, and silently got really weird results. Took a while debugging to figure out what the cause was.


This comment has been minimized.

Copy link

commented Mar 12, 2019

This looks like a good idea, as it will help narrow down the problem in the case of unmatched shapes. The documentation for torch.autograd.grad says,

grad_outputs should be a sequence of length matching output containing the pre-computed gradients w.r.t. each of the outputs.

So, you're right, they should be the same shape (Except when grad_outputs = None). I'd be happy to work on implementing this feature.


This comment has been minimized.

Copy link

commented Mar 12, 2019

seems reasonable. thanks for working on it @jalenmorgan !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
4 participants
You can鈥檛 perform that action at this time.