stable-diffusion icon indicating copy to clipboard operation
stable-diffusion copied to clipboard

cannot import name 'autocast' from 'torch'

Open TheOneTrueGuy opened this issue 2 years ago • 3 comments

Got the conda env, installs, downloads and everything all working smoothly now, no error messages but upon running this pops up:

Traceback (most recent call last): File "stable-diffusion/scripts/txt2img.py", line 12, in from torch import autocast ImportError: cannot import name 'autocast' from 'torch' (/usr/local/envs/ldm/lib/python3.8/site-packages/torch/init.py)

TheOneTrueGuy avatar Aug 10 '22 01:08 TheOneTrueGuy

Having the same issue currently unfortunately

KobeAmerijckxPT avatar Aug 15 '22 20:08 KobeAmerijckxPT

yes, I have the same issue for this problem.

Sample-design-alt avatar Aug 22 '22 02:08 Sample-design-alt

For me, the issue was resolved by updating txt2img.py line 12 from from torch import autocast to from torch.cuda.amp import autocast.

I also needed to modify line 225 from with precision_scope("cuda"): to with precision_scope(True):. I am calling the CLI and passing --precision=autocast.

synaestheory avatar Aug 22 '22 03:08 synaestheory