[GH-ISSUE #49] RuntimeError: Method 'forward' is not defined. #44

Closed
opened 2026-10-31 21:10:11 +00:00 by bsakaguchi · 5 comments
Owner

Originally created by @austinmw on GitHub (Mar 3, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/49

Hi, I need to use a nightly version of PyTorch in order to get GPU support for my RTX 3080, and am facing an issue where,

model, preprocess = clip.load("ViT-B/32") gives a RuntimeError:


RuntimeError Traceback (most recent call last)
in
----> 1 model, preprocess = clip.load("ViT-B/32")

~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/clip/clip.py in load(name, device, jit)
129 node.copyAttributes(device_node)
130
--> 131 model.apply(patch_device)
132 patch_device(model.encode_image)
133 patch_device(model.encode_text)

~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/nn/modules/module.py in apply(self, fn)
471 """
472 for module in self.children():
--> 473 module.apply(fn)
474 fn(self)
475 return self

~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/nn/modules/module.py in apply(self, fn)
471 """
472 for module in self.children():
--> 473 module.apply(fn)
474 fn(self)
475 return self

~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/nn/modules/module.py in apply(self, fn)
471 """
472 for module in self.children():
--> 473 module.apply(fn)
474 fn(self)
475 return self

~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/nn/modules/module.py in apply(self, fn)
471 """
472 for module in self.children():
--> 473 module.apply(fn)
474 fn(self)
475 return self

~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/nn/modules/module.py in apply(self, fn)
471 """
472 for module in self.children():
--> 473 module.apply(fn)
474 fn(self)
475 return self

~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/nn/modules/module.py in apply(self, fn)
471 """
472 for module in self.children():
--> 473 module.apply(fn)
474 fn(self)
475 return self

~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/nn/modules/module.py in apply(self, fn)
472 for module in self.children():
473 module.apply(fn)
--> 474 fn(self)
475 return self
476

~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/clip/clip.py in patch_device(module)
120
121 def patch_device(module):
--> 122 graphs = [module.graph] if hasattr(module, "graph") else []
123 if hasattr(module, "forward1"):
124 graphs.append(module.forward1.graph)

~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/jit/_script.py in graph(self)
452 forward method. See :ref:interpreting-graphs for details.
453 """
--> 454 return self._c._get_method("forward").graph
455
456 @property

RuntimeError: Method 'forward' is not defined.

Is there any chance this could be made forward compatible with latest PyTorch releases?

Originally created by @austinmw on GitHub (Mar 3, 2021). Original GitHub issue: https://github.com/openai/CLIP/issues/49 Hi, I need to use a nightly version of PyTorch in order to get GPU support for my RTX 3080, and am facing an issue where, `model, preprocess = clip.load("ViT-B/32")` gives a RuntimeError: > --------------------------------------------------------------------------- > RuntimeError Traceback (most recent call last) > <ipython-input-8-6a22aec02c19> in <module> > ----> 1 model, preprocess = clip.load("ViT-B/32") > > ~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/clip/clip.py in load(name, device, jit) > 129 node.copyAttributes(device_node) > 130 > --> 131 model.apply(patch_device) > 132 patch_device(model.encode_image) > 133 patch_device(model.encode_text) > > ~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/nn/modules/module.py in apply(self, fn) > 471 """ > 472 for module in self.children(): > --> 473 module.apply(fn) > 474 fn(self) > 475 return self > > ~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/nn/modules/module.py in apply(self, fn) > 471 """ > 472 for module in self.children(): > --> 473 module.apply(fn) > 474 fn(self) > 475 return self > > ~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/nn/modules/module.py in apply(self, fn) > 471 """ > 472 for module in self.children(): > --> 473 module.apply(fn) > 474 fn(self) > 475 return self > > ~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/nn/modules/module.py in apply(self, fn) > 471 """ > 472 for module in self.children(): > --> 473 module.apply(fn) > 474 fn(self) > 475 return self > > ~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/nn/modules/module.py in apply(self, fn) > 471 """ > 472 for module in self.children(): > --> 473 module.apply(fn) > 474 fn(self) > 475 return self > > ~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/nn/modules/module.py in apply(self, fn) > 471 """ > 472 for module in self.children(): > --> 473 module.apply(fn) > 474 fn(self) > 475 return self > > ~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/nn/modules/module.py in apply(self, fn) > 472 for module in self.children(): > 473 module.apply(fn) > --> 474 fn(self) > 475 return self > 476 > > ~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/clip/clip.py in patch_device(module) > 120 > 121 def patch_device(module): > --> 122 graphs = [module.graph] if hasattr(module, "graph") else [] > 123 if hasattr(module, "forward1"): > 124 graphs.append(module.forward1.graph) > > ~/miniconda3/envs/pytorch_p38/lib/python3.8/site-packages/torch/jit/_script.py in graph(self) > 452 ``forward`` method. See :ref:`interpreting-graphs` for details. > 453 """ > --> 454 return self._c._get_method("forward").graph > 455 > 456 @property > > RuntimeError: Method 'forward' is not defined. Is there any chance this could be made forward compatible with latest PyTorch releases?
Author
Owner

@jongwook commented on GitHub (Mar 3, 2021):

Hi, currently it is not tested on versions other than 1.7.1, but we'll look into supporting future PyTorch versions. Did you need CUDA 11.1 for your GPU? You might try building pytorch 1.7.1 yourself, but YMMV.

In the meantime, can you try loading the model with the jit=False flag and see if that works? This might be a JIT-specific issue.

<!-- gh-comment-id:789415576 --> @jongwook commented on GitHub (Mar 3, 2021): Hi, currently it is not tested on versions other than 1.7.1, but we'll look into supporting future PyTorch versions. Did you need CUDA 11.1 for your GPU? You might try building pytorch 1.7.1 yourself, but YMMV. In the meantime, can you try loading the model with the `jit=False` flag and see if that works? This might be a JIT-specific issue.
Author
Owner

@crowsonkb commented on GitHub (Mar 5, 2021):

I tried loading the model with the jit=False flag and it worked for me.

<!-- gh-comment-id:791421923 --> @crowsonkb commented on GitHub (Mar 5, 2021): I tried loading the model with the `jit=False` flag and it worked for me.
Author
Owner

@nreimers commented on GitHub (Mar 19, 2021):

Setting jit=False and comment out line 134 +135:
https://github.com/openai/CLIP/blob/main/clip/clip.py#L134

#patch_device(model.encode_image)
#patch_device(model.encode_text)

solved the issue for me

<!-- gh-comment-id:803098153 --> @nreimers commented on GitHub (Mar 19, 2021): Setting jit=False and comment out line 134 +135: https://github.com/openai/CLIP/blob/main/clip/clip.py#L134 ```python #patch_device(model.encode_image) #patch_device(model.encode_text) ``` solved the issue for me
Author
Owner

@mitchellnw commented on GitHub (Apr 20, 2021):

Works when jit=False but is their any plans/recommendations for fixes when jit=True with PyTorch >= 1.8?

<!-- gh-comment-id:823655616 --> @mitchellnw commented on GitHub (Apr 20, 2021): Works when `jit=False` but is their any plans/recommendations for fixes when `jit=True` with PyTorch >= 1.8?
Author
Owner

@jongwook commented on GitHub (Jul 19, 2021):

Fixed with db20393 !

<!-- gh-comment-id:882177255 --> @jongwook commented on GitHub (Jul 19, 2021): Fixed with db20393 !
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openai/CLIP#44
No description provided.