Search code examples
pythonpytorch

PyTorch RuntimeError: requires_grad_ is not supported on ScriptModules


I'm running Python code from an old repo that seems to no longer work but I can't figure out why or how to fix it.

SETUP CODE (Google Colab Notebook)

#@title Setup
import pkg_resources
print(pkg_resources.get_distribution("torch").version)
from IPython.utils import io
with io.capture_output() as captured:
  !git clone https://github.com/openai/CLIP
  # !pip install taming-transformers
  !git clone https://github.com/CompVis/taming-transformers.git
  !rm -Rf clipit
  !git clone https://github.com/mfrashad/clipit.git
  !pip install ftfy regex tqdm omegaconf pytorch-lightning
  !pip install kornia
  !pip install imageio-ffmpeg   
  !pip install einops
  !pip install torch-optimizer
  !pip install easydict
  !pip install braceexpand
  !pip install git+https://github.com/pvigier/perlin-numpy

  # ClipDraw deps
  !pip install svgwrite
  !pip install svgpathtools
  !pip install cssutils
  !pip install numba
  !pip install torch-tools
  !pip install visdom

  !pip install gradio

  !git clone https://github.com/BachiLi/diffvg
  %cd diffvg
  # !ls
  !git submodule update --init --recursive
  !python setup.py install
  %cd ..
  
  !mkdir -p steps
  !mkdir -p models
import sys
sys.path.append("clipit")

THEN ERRORS ON SECOND TO LAST INE

import clipit
# To reset settings to default
clipit.reset_settings()
# You can use "|" to separate multiple prompts
prompts = "underwater city"
# You can trade off speed for quality: draft, normal, better, best
quality = "normal"
# Aspect ratio: widescreen, square
aspect = "widescreen"
# Add settings
clipit.add_settings(prompts=prompts, quality=quality, aspect=aspect)
# Apply these settings and run
settings = clipit.apply_settings()
clipit.do_init(settings) # generates error
clipit.do_run(settings)

Working with z of shape (1, 256, 16, 16) = 65536 dimensions. loaded pretrained LPIPS loss from taming/modules/autoencoder/lpips/vgg.pth VQLPIPSWithDiscriminator running with hinge loss. Restored from models/vqgan_imagenet_f16_16384.ckpt --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) in () 12 # Apply these settings and run 13 settings = clipit.apply_settings() ---> 14 clipit.do_init(settings) 15 clipit.do_run(settings)

1 frames /usr/local/lib/python3.7/dist-packages/torch/jit/_script.py in fail(self, *args, **kwargs) 912 def _make_fail(name): 913 def fail(self, *args, **kwargs): --> 914 raise RuntimeError(name + " is not supported on ScriptModules") 915 916 return fail

RuntimeError: requires_grad_ is not supported on ScriptModules


Solution

  • For any unlucky soul that comes accross this issue this URL saved my soul

    https://github.com/mfrashad/text2art/issues/5