# AttributeError: module 'torch.cuda' has no attribute 'amp'

**URL:** <https://discuss.pytorch.org/t/attributeerror-module-torch-cuda-has-no-attribute-amp/76610>\
**Category:** Uncategorized\
**Created:** [April 13, 2020, 5:32pm UTC](https://discuss.pytorch.org/t/attributeerror-module-torch-cuda-has-no-attribute-amp/76610 "2020-04-13T17:32:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![braindotai](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/braindotai/32/61373_2.png) [@braindotai](https://discuss.pytorch.org/u/braindotai)\
**Post date:** [April 13, 2020, 5:32pm UTC](https://discuss.pytorch.org/t/attributeerror-module-torch-cuda-has-no-attribute-amp/76610/1 "2020-04-13T17:32:01Z")

</div>

I’m running `from torch.cuda.amp import GradScaler, autocast` and got the error as in title.

Pytorch version: - 1.4.0

Thanks.

---

<div class="post-metadata">

**Author:** ![boto](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/boto/32/22512_2.png) [@boto](https://discuss.pytorch.org/u/boto)\
**Post date:** [April 13, 2020, 5:37pm UTC](https://discuss.pytorch.org/t/attributeerror-module-torch-cuda-has-no-attribute-amp/76610/2 "2020-04-13T17:37:12Z")

</div>

Hi!

Have you installed the CUDA version of pytorch? Does your environment recognize `torch.cuda`?

---

<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:** [April 14, 2020, 2:03am UTC](https://discuss.pytorch.org/t/attributeerror-module-torch-cuda-has-no-attribute-amp/76610/3 "2020-04-14T02:03:09Z")

</div>

`torch.cuda.amp` is available in the nightly binaries, so you would have to update.

---

<div class="post-metadata">

**Author:** ![JosueCom](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/josuecom/32/27043_2.png) [@JosueCom](https://discuss.pytorch.org/u/JosueCom)\
**Post date:** [July 23, 2020, 2:38pm UTC](https://discuss.pytorch.org/t/attributeerror-module-torch-cuda-has-no-attribute-amp/76610/4 "2020-07-23T14:38:25Z")

</div>

I just got the following error when attempting to use amp. Do you know how I can fix it?

```python
     84 if amp_enable:
---> 85 with th.cuda.amp.autocast():
     86 out1 = model(sub, inp)
     87 out2 = temp_ly(sub, out1)

AttributeError: module 'torch.cuda.amp' has no attribute 'autocast'

```

---

<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:** [July 24, 2020, 9:11am UTC](https://discuss.pytorch.org/t/attributeerror-module-torch-cuda-has-no-attribute-amp/76610/5 "2020-07-24T09:11:44Z")

</div>

You might need to install the nightly binary, since Autocasting wasn’t shipped in `1.5`.
