# Torch.cuda.amp blocks gradient computation

**URL:** <https://discuss.pytorch.org/t/torch-cuda-amp-blocks-gradient-computation/137039>\
**Category:** mixed-precision\
**Created:** [November 16, 2021, 1:31pm UTC](https://discuss.pytorch.org/t/torch-cuda-amp-blocks-gradient-computation/137039 "2021-11-16T13:31:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [November 16, 2021, 4:16pm UTC](https://discuss.pytorch.org/t/torch-cuda-amp-blocks-gradient-computation/137039/2 "2021-11-16T16:16:12Z")

</div>

You would have to exit the autocast context before running the second forward pass as described [here](https://discuss.pytorch.org/t/autocast-and-torch-no-grad-unexpected-behaviour/93475/3) due to the internal caching.

CC @vadimkantorov as we’ve discussed more general use cases and this one might be important for you.

---

_[View the full topic](https://discuss.pytorch.org/t/torch-cuda-amp-blocks-gradient-computation/137039)._
