# Save initial gradient for all upstream layers

**URL:** <https://discuss.pytorch.org/t/save-initial-gradient-for-all-upstream-layers/99359>\
**Category:** autograd\
**Created:** [October 14, 2020, 12:31pm UTC](https://discuss.pytorch.org/t/save-initial-gradient-for-all-upstream-layers/99359 "2020-10-14T12:31:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![francescocarzaniga](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/f/b3f665/32.png) [@francescocarzaniga](https://discuss.pytorch.org/u/francescocarzaniga)\
**Post date:** [October 14, 2020, 12:31pm UTC](https://discuss.pytorch.org/t/save-initial-gradient-for-all-upstream-layers/99359/1 "2020-10-14T12:31:15Z")

</div>

I have a model that implements a layer with a custom forwards and backwards function following the extension [guide](https://pytorch.org/docs/master/notes/extending.html). However the backwards function is not computed using the gradient of the downstream layer, but the gradient of the output layer.

What’s the cleanest way to pass it to the backwards function of upstream layers?
