nerdyrodent / VQGAN-CLIP

Just playing with getting VQGAN+CLIP running locally, rather than having to use colab.
Other
2.59k stars 427 forks source link

requires_grad_ is not supported on ScriptModules #65

Closed julianallchin closed 2 years ago

julianallchin commented 2 years ago

using cuda 11.2, built torch from source

Traceback (most recent call last):
  File "/home/julianallchin/github/VQGAN-CLIP/generate.py", line 548, in <module>
    perceptor = clip.load(args.clip_model, jit=jit)[0].eval().requires_grad_(False).to(device)
  File "/home/julianallchin/anaconda3/envs/vqgan/lib/python3.9/site-packages/torch/jit/_script.py", line 915, in fail
    raise RuntimeError(name + " is not supported on ScriptModules")
RuntimeError: requires_grad_ is not supported on ScriptModules
utkusen commented 2 years ago

I had the same problem. Just use pytorch 1.8.x

SirWaffle commented 2 years ago

I am also seeing the same issue with pytorch 1.10.0, any suggestions that dont involve reverting to an older version?

edit: it appears several issues are fixed by setting jit to false when loading the clip model:

loading clip with jit set to false, then the requiresgrad error goes away

the error " 'RecursiveScriptModule' object has no attribute 'input_resolution' on line cut_size = perceptor.visual.input_resolution

is also resolved.

however, i had issues with 'backwards being called twice on released data', that i fixed with adding retain_graph to the backwads calls: backward(retain_graph=True)

I am not sure this retain_graph change is needed, however, as i have other modifications that may be causing this issue.

nerdyrodent commented 2 years ago

While it does work with Pytorch > 1.9.1, the line for detecting the Pytorch does not. Jit should only really be true when using 1.7.1