Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: Method 'forward' is not defined. #49

Closed
austinmw opened this issue Mar 3, 2021 · 5 comments
Closed

RuntimeError: Method 'forward' is not defined. #49

austinmw opened this issue Mar 3, 2021 · 5 comments

Comments

@austinmw
Copy link

austinmw commented Mar 3, 2021

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?

@jongwook
Copy link
Collaborator

jongwook commented 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.

@crowsonkb
Copy link

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

@nreimers
Copy link

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

@mitchellnw
Copy link

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

@jongwook
Copy link
Collaborator

Fixed with db20393 !

alopezrivera added a commit to alopezrivera/cliport that referenced this issue Apr 14, 2023
This change follows from the discussion[1,2] OpenAI CLIP issue
tracker and final fix[3] of the following error:

```
TypeError: 'torch._C.Node' object is not subscriptable
```

[1]: openai/CLIP#79
[2]: openai/CLIP#49
[3]: openai/CLIP@db20393
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants