timothybrooks / instruct-pix2pix

Other
6.1k stars 527 forks source link

ImportError: cannot import name 'autocast' from 'torch' #105

Open kotran88 opened 1 year ago

kotran88 commented 1 year ago

when I command python edit_cli.py --steps 100 --resolution 512 --seed 1371 --cfg-text 7.5 --cfg-image 1.2 --input imgs/example.jpg --output imgs/output.jpg --edit "turn him into a cyborg"

ImportError: cannot import name 'autocast' from 'torch'

this error happend.

and I searched someone says I should change it to from torch.cuda.amp import autocast

then it cause other error saying

C:\Users\pedro\instruct-pix2pix-main\edit_cli.py:128 in │ │ │ │ 125 │ │ 126 │ │ 127 if name == "main": │ │ ❱ 128 │ main() │ │ 129 │ │ │ │ C:\Users\pedro\instruct-pix2pix-main\edit_cli.py:98 in main │ │ │ │ 95 │ │ input_image.save(args.output) │ │ 96 │ │ return │ │ 97 │ │ │ ❱ 98 │ with torch.no_grad(), autocast("cuda"), model.ema_scope(): │ │ 99 │ │ cond = {} │ │ 100 │ │ cond["c_crossattn"] = [model.get_learned_conditioning([args.edit])] │ │ 101 │ │ input_image = 2 torch.tensor(np.array(input_image)).float() / 255 - 1 │ │ │ │ C:\Users\pedro\anaconda3\envs\aip\lib\site-packages\torch\cuda\amp\autocast_mode.py:127 in │ │ enter │ │ │ │ 124 │ │ │ 125 │ def enter(self): │ │ 126 │ │ self.prev = torch.is_autocast_enabled() │ │ ❱ 127 │ │ torch.set_autocast_enabled(self._enabled) │ │ 128 │ │ torch.autocast_increment_nesting() │ │ 129 │ │ │ 130 │ def exit(self, args): │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ TypeError: enabled must be a bool (got str)

torch version is '1.9.0+cu111' python version : 3.7.9

tgyuan21 commented 7 months ago

change autocast("cuda") to autocast(True)

nyukers commented 3 months ago

change autocast("cuda") to autocast(True)

Where this change?