PyTorch 运行时错误:ScriptModules 不支持 requires_grad_。

5

我正在运行一份旧代码库的Python代码,但似乎不再起作用,但我无法弄清原因或如何修复它。

安装代码(Google Colab笔记本)

#@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")

然后在倒数第二行出现错误

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)

使用形状为(1, 256, 16, 16) = 65536维的z。从taming/modules/autoencoder/lpips/vgg.pth加载预训练的LPIPS损失。VQLPIPSWithDiscriminator使用铰链损失运行。从models/vqgan_imagenet_f16_16384.ckpt恢复。在执行时发生错误:requires_grad_不支持ScriptModules。

1
Pytorch 中以下划线 _ 结尾的东西是原地操作。你可以尝试使用 requires_grad(不要在末尾加下划线)。 - jkr
你好!我尝试了一下,但是出现了这个错误:AttributeError: 'RecursiveScriptModule' object has no attribute 'requires_grad' - metalaureate
1个回答

1

对于任何不幸遇到这个问题的人,这个URL拯救了我的灵魂

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接