Skip to main content
Image
Go to StableDiffusion

"cannot import name 'autocast' from 'torch'"

I've gone though the instructions listed here: https://www.assemblyai.com/blog/how-to-run-stable-diffusion-locally-to-generate-images/

...and the environment creation seemed to go all right, but I am getting the above error when I try to create an image. A Google search of this traceback didn't yield much; it looks like an obscure error. Please assist. I am running Linux Mint 20.3 x64, Conda version 4.12.0, Python 3.9.12. Nvidia-smi is as follows:

+-----------------------------------------------------------------------------+

| NVIDIA-SMI 515.43.04 Driver Version: 515.43.04 CUDA Version: 11.7 |

|-------------------------------+----------------------+----------------------+

| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |

| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |

| | | MIG M. |

|===============================+======================+======================|

| 0 NVIDIA GeForce ... On | 00000000:01:00.0 Off | N/A |

| N/A 52C P0 41W / N/A | 1269MiB / 8192MiB | 37% Default |

| | | N/A |

+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+

| Processes: |

| GPU GI CI PID Type Process name GPU Memory |

| ID ID Usage |

|=============================================================================|

| 0 N/A N/A 1806 G /usr/lib/xorg/Xorg 502MiB |

| 0 N/A N/A 2248 G xfwm4 3MiB |

| 0 N/A N/A 3442 G /usr/lib/firefox/firefox 95MiB |

| 0 N/A N/A 8311 G /usr/lib/firefox/firefox-bin 109MiB |

| 0 N/A N/A 20820 G /usr/lib/firefox/firefox-bin 151MiB |

| 0 N/A N/A 57679 G ...RendererForSitePerProcess 9MiB |

| 0 N/A N/A 73889 G /usr/lib/firefox/firefox-bin 137MiB |

| 0 N/A N/A 91556 G ...AAAAAAAAA= --shared-files 34MiB |

| 0 N/A N/A 94103 G ...AAAAAAAAA= --shared-files 33MiB |

| 0 N/A N/A 99522 G /opt/calibre/bin/calibre 3MiB |

| 0 N/A N/A 111111 G /usr/lib/firefox/firefox-bin 181MiB |

+-----------------------------------------------------------------------------+

The complete traceback is:

Traceback (most recent call last):

File "scripts/txt2img.py", line 12, in <module>

from torch import autocast

ImportError: cannot import name 'autocast' from 'torch' (/home/krovas/.local/lib/python3.8/site-packages/torch/__init__.py)