# How could you manually stop backpropagation?

**URL:** <https://discuss.pytorch.org/t/how-could-you-manually-stop-backpropagation/115985>\
**Category:** autograd\
**Created:** [March 25, 2021, 4:59pm UTC](https://discuss.pytorch.org/t/how-could-you-manually-stop-backpropagation/115985 "2021-03-25T16:59:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![111491](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/111491/32/36273_2.png) [@111491](https://discuss.pytorch.org/u/111491)\
**Post date:** [March 25, 2021, 4:59pm UTC](https://discuss.pytorch.org/t/how-could-you-manually-stop-backpropagation/115985/1 "2021-03-25T16:59:07Z")

</div>

For some reason I need to call loss.backward() to tarin a special parameter in the middle layer of my model, but for the sake of saving calculation expenses I don’t want the backpropagation to continue once I get the gradient for my parameter, otherwise I’ll run out of my kaggle-GPU free usage 😥. So is there any way to **manually stop backpropagation** after It was done for a specific parameter or a module?

---

<div class="post-metadata">

**Author:** ![albanD](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/alband/32/215_2.png) [@albanD](https://discuss.pytorch.org/u/albanD)\
**Post date:** [March 25, 2021, 10:13pm UTC](https://discuss.pytorch.org/t/how-could-you-manually-stop-backpropagation/115985/2 "2021-03-25T22:13:05Z")

</div>

Hi,

You can use `autograd.grad(loss, input)` and it will return gradients for that input and only perform the necessary computations to get that value.  
If you prefer for the `.grad` fields to be populated, you can use `loss.backward(inputs=input)`.

---

<div class="post-metadata">

**Author:** ![111491](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/111491/32/36273_2.png) [@111491](https://discuss.pytorch.org/u/111491)\
**Post date:** [March 26, 2021, 2:16am UTC](https://discuss.pytorch.org/t/how-could-you-manually-stop-backpropagation/115985/3 "2021-03-26T02:16:02Z")

</div>

> [@albanD](#):
>
> `autograd.grad(loss, input)`

Helped me out！Thanks alt
