[GH-ISSUE #79] TypeError: 'torch._C.Node' object is not subscriptable #71

Closed
opened 2026-10-31 21:10:29 +00:00 by bsakaguchi · 6 comments
Owner

Originally created by @lonngxiang on GitHub (Apr 7, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/79

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

Originally created by @lonngxiang on GitHub (Apr 7, 2021). Original GitHub issue: https://github.com/openai/CLIP/issues/79 Traceback (most recent call last): File "D:/openai/CLIP/test1.py", line 7, in <module> 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
Author
Owner

@jongwook commented on GitHub (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.

<!-- gh-comment-id:815478537 --> @jongwook commented on GitHub (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.
Author
Owner

@maksimovkonstantin commented on GitHub (Oct 18, 2021):

@jongwook This very unclear and strange solution helped me https://github.com/microsoft/nni/issues/2574 - so If someone will face the same problem - just import torchvision

<!-- gh-comment-id:945850322 --> @maksimovkonstantin commented on GitHub (Oct 18, 2021): @jongwook This very unclear and strange solution helped me https://github.com/microsoft/nni/issues/2574 - so If someone will face the same problem - just import torchvision
Author
Owner

@fuqichen1998 commented on GitHub (Apr 19, 2023):

@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.

<!-- gh-comment-id:1515504638 --> @fuqichen1998 commented on GitHub (Apr 19, 2023): > @jongwook This very unclear and strange solution helped me [microsoft/nni#2574](https://github.com/microsoft/nni/issues/2574) - so If someone will face the same problem - just import torchvision This doesn't work for me.
Author
Owner

@samuela commented on GitHub (May 24, 2023):

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

Update: setting jit=False fixes it for me

<!-- gh-comment-id:1561942397 --> @samuela commented on GitHub (May 24, 2023): FWIW I've found the same error on Ubuntu 20.04, with PyTorch 2.0.0 and CLIP a9b1bf5920416aaeaec965c25dd9e8f98c864f16. Update: setting `jit=False` fixes it for me
Author
Owner

@dreamlychina commented on GitHub (Jun 7, 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

thanks, It is helpful for me。

<!-- gh-comment-id:1579949035 --> @dreamlychina commented on GitHub (Jun 7, 2023): > FWIW I've found the same error on Ubuntu 20.04, with PyTorch 2.0.0 and CLIP [a9b1bf5](https://github.com/openai/CLIP/commit/a9b1bf5920416aaeaec965c25dd9e8f98c864f16). > > Update: setting `jit=False` fixes it for me thanks, It is helpful for me。
Author
Owner

@jamt9000 commented on GitHub (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)
<!-- gh-comment-id:1624202950 --> @jamt9000 commented on GitHub (Jul 6, 2023): For torch 2.0.0 this is working to monkeypatch the subscript operator: ```py 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 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#71
No description provided.