Hi everyone. I am working on the CLIP project. I am trying to parse models from it, script them and save them, but I am getting this error:
$ CUDA_VISIBLE_DEVICES=0 python get_encoder.py
Using cuda
Traceback (most recent call last):
File "/media/ssdraid/training/clip/test/get_encoder.py", line 74, in <module>
model_scripted = torch.jit.script(model)
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_script.py", line 1286, in script
return torch.jit._recursive.create_script_module(
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_recursive.py", line 458, in create_script_module
return create_script_module_impl(nn_module, concrete_type, stubs_fn)
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_recursive.py", line 520, in create_script_module_impl
script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn)
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_script.py", line 615, in _construct
init_fn(script_module)
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_recursive.py", line 498, in init_fn
scripted = create_script_module_impl(orig_value, sub_concrete_type, stubs_fn)
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_recursive.py", line 520, in create_script_module_impl
script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn)
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_script.py", line 615, in _construct
init_fn(script_module)
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_recursive.py", line 498, in init_fn
scripted = create_script_module_impl(orig_value, sub_concrete_type, stubs_fn)
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_recursive.py", line 520, in create_script_module_impl
script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn)
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_script.py", line 615, in _construct
init_fn(script_module)
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_recursive.py", line 498, in init_fn
scripted = create_script_module_impl(orig_value, sub_concrete_type, stubs_fn)
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_recursive.py", line 520, in create_script_module_impl
script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn)
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_script.py", line 615, in _construct
init_fn(script_module)
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_recursive.py", line 498, in init_fn
scripted = create_script_module_impl(orig_value, sub_concrete_type, stubs_fn)
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_recursive.py", line 524, in create_script_module_impl
create_methods_and_properties_from_stubs(concrete_type, method_stubs, property_stubs)
File "/home/tensorflow/venvs/triton/lib/python3.10/site-packages/torch/jit/_recursive.py", line 375, in create_methods_and_properties_from_stubs
concrete_type._create_methods_and_properties(property_defs, property_rcbs, method_defs, method_rcbs, method_defaults)
RuntimeError:
'Tensor' object has no attribute or method 'forward'.:
File "/media/ssdraid/training/clip/test/model.py", line 156
def forward(self, x: torch.Tensor):
orig_type = x.dtype
ret = super().forward(x.type(torch.float32))
~~~~~~~~~~~~~ <--- HERE
return ret.type(orig_type)
Can anyone please tell me how to solve it?
The codes I am using can be found here, and the get_encoder.py
script includes downloading a model from external link, so just you know.
Versions
Collecting environment information...
PyTorch version: 1.12.1+cu102
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A
OS: Ubuntu 20.04.4 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: 10.0.0-4ubuntu1
CMake version: version 3.16.3
Libc version: glibc-2.31
Python version: 3.10.4 (main, Apr 8 2022, 17:35:13) [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.4.0-1020-ibm-x86_64-with-glibc2.31
Is CUDA available: True
CUDA runtime version: 11.2.152
GPU models and configuration:
GPU 0: NVIDIA GeForce RTX 2080 Ti
GPU 1: NVIDIA GeForce GTX 980 Ti
GPU 2: NVIDIA GeForce RTX 2080 Ti
Nvidia driver version: 515.65.01
cuDNN version: Probably one of the following:
/usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn.so.8.1.1
/usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.1.1
/usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.1.1
/usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.1.1
/usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.1.1
/usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.1.1
/usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.1.1
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Versions of relevant libraries:
[pip3] numpy==1.22.4
[pip3] torch==1.12.1
[pip3] torchvision==0.12.0
[conda] Could not collect
Thank you very much in advance.