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

TypeError: 'torch._C.Node' object is not subscriptable #79

Closed
lonngxiang opened this issue Apr 7, 2021 · 6 comments · Fixed by #372
Closed

TypeError: 'torch._C.Node' object is not subscriptable #79

lonngxiang opened this issue Apr 7, 2021 · 6 comments · Fixed by #372

Comments

@lonngxiang
Copy link

Traceback (most recent call last):
File "D:/openai/CLIP/test1.py", line 7, in
model, preprocess = clip.load("ViT-B/32", device=device)
File "D:\openai\CLIP\clip\clip.py", line 133, in load
model.apply(patch_device)
File "D:\conda\envs\my_pytorch\lib\site-packages\torch\nn\modules\module.py", line 445, in apply
module.apply(fn)
File "D:\conda\envs\my_pytorch\lib\site-packages\torch\nn\modules\module.py", line 445, in apply
module.apply(fn)
File "D:\conda\envs\my_pytorch\lib\site-packages\torch\nn\modules\module.py", line 446, in apply
fn(self)
File "D:\openai\CLIP\clip\clip.py", line 130, in patch_device
if "value" in node.attributeNames() and str(node["value"]).startswith("cuda"):
TypeError: 'torch._C.Node' object is not subscriptable

@jongwook
Copy link
Collaborator

jongwook commented Apr 8, 2021

Likely related to PyTorch 1.8. Please try loading with jit=False or stick to torch 1.7.1. See #49 for more info.

@maksimovkonstantin
Copy link

@jongwook This very unclear and strange solution helped me microsoft/nni#2574 - so If someone will face the same problem - just import torchvision

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
@fuqichen1998
Copy link

@jongwook This very unclear and strange solution helped me microsoft/nni#2574 - so If someone will face the same problem - just import torchvision

This doesn't work for me.

@samuela
Copy link

samuela commented May 24, 2023

FWIW I've found the same error on Ubuntu 20.04, with PyTorch 2.0.0 and CLIP a9b1bf5.

Update: setting jit=False fixes it for me

@dreamlychina
Copy link

FWIW I've found the same error on Ubuntu 20.04, with PyTorch 2.0.0 and CLIP a9b1bf5.

Update: setting jit=False fixes it for me

thanks, It is helpful for me。

@jamt9000
Copy link
Contributor

jamt9000 commented Jul 6, 2023

For torch 2.0.0 this is working to monkeypatch the subscript operator:

import torch
import clip

# From https://github.com/pytorch/pytorch/blob/2efe4d809fdc94501fc38bf429e9a8d4205b51b6/torch/utils/tensorboard/_pytorch_graph.py#L384
def _node_get(node: torch._C.Node, key: str):
    """Gets attributes of a node which is polymorphic over return type."""
    sel = node.kindOf(key)
    return getattr(node, sel)(key)

torch._C.Node.__getitem__ = _node_get

model, preprocess = clip.load('ViT-B/32', jit=True)

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

Successfully merging a pull request may close this issue.

7 participants