# Exact meaning of grad\_input and grad\_output

**URL:** <https://discuss.pytorch.org/t/exact-meaning-of-grad-input-and-grad-output/14186>\
**Category:** autograd\
**Created:** [March 1, 2018, 8:21am UTC](https://discuss.pytorch.org/t/exact-meaning-of-grad-input-and-grad-output/14186 "2018-03-01T08:21:02Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![kindlychung](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/kindlychung/32/3679_2.png) [@kindlychung](https://discuss.pytorch.org/u/kindlychung)\
**Post date:** [March 1, 2018, 9:04am UTC](https://discuss.pytorch.org/t/exact-meaning-of-grad-input-and-grad-output/14186/3 "2018-03-01T09:04:06Z")

</div>

Ok, let’s get a bit more specific:

```auto
>>> print(grad_dict["fc2"]["grad_input"][0][0].size())
torch.Size([4, 30])
>>> print(grad_dict["fc2"]["grad_input"][0][1].size())
torch.Size([4, 20])
>>> print(grad_dict["fc2"]["grad_input"][0][2].size())
torch.Size([20, 30])
>>> print(grad_dict["fc2"]["grad_output"][0][0].size())
torch.Size([4, 30])

```

`grad_input` is a 3-tuple, my guess:

- [0] is the derivative of loss wrt layer input
- [1] is the derivative of loss wrt layer output (before activation)
- [2] is the derivative of loss wrt layer weights

`grad_output` is a 1-tuple, perhaps it’s the derivative of loss wrt layer output after activation?

Please correct me if I am wrong.

---

_[View the full topic](https://discuss.pytorch.org/t/exact-meaning-of-grad-input-and-grad-output/14186)._
