pyg-team / pytorch_geometric

Graph Neural Network Library for PyTorch
https://pyg.org
MIT License
21.16k stars 3.64k forks source link

torch.fx.Tracer '_module_getattr' error #6023

Open Nibir088 opened 1 year ago

Nibir088 commented 1 year ago

🐛 Describe the bug

I am trying to run sample codes of 'Automatically Converting GNN Models' from PyG documentation. I found that torch.fx.Tracer has no attribute named '_module_getattr'. How to resolve this problem? I am attaching my codes and error bellow.



import torch_geometric.transforms as T
from torch_geometric.datasets import OGB_MAG
from torch_geometric.nn import SAGEConv, to_hetero as t_heter
import torch

dataset = OGB_MAG(root='./data', preprocess='metapath2vec', transform=T.ToUndirected())
data = dataset[0]

class GNN(torch.nn.Module):
    def __init__(self, hidden_channels, out_channels):
        super().__init__()
        self.conv1 = SAGEConv((-1, -1), hidden_channels)
        self.conv2 = SAGEConv((-1, -1), out_channels)

    def forward(self, x, edge_index):
        x = self.conv1(x, edge_index).relu()
        x = self.conv2(x, edge_index)
        return x

model = GNN(hidden_channels=64, out_channels=dataset.num_classes)
model = t_heter(model, data.metadata(), aggr='sum')

``` Error Message

Traceback (most recent call last):
  File "/u/wyr6fx/PyG/GNNModel/HeterogenousGraph.py", line 22, in <module>
    model = t_heter(model, data.metadata(), aggr='sum')
  File "/u/wyr6fx/myenv/lib/python3.9/site-packages/torch_geometric/nn/to_hetero_transformer.py", line 117, in to_hetero
    transformer = ToHeteroTransformer(module, metadata, aggr, input_map, debug)
  File "/u/wyr6fx/myenv/lib/python3.9/site-packages/torch_geometric/nn/to_hetero_transformer.py", line 141, in __init__
    super().__init__(module, input_map, debug)
  File "/u/wyr6fx/myenv/lib/python3.9/site-packages/torch_geometric/nn/fx.py", line 73, in __init__
    self.gm = symbolic_trace(module)
  File "/u/wyr6fx/myenv/lib/python3.9/site-packages/torch_geometric/nn/fx.py", line 358, in symbolic_trace
    return GraphModule(module, Tracer().trace(module, concrete_args))
  File "/u/wyr6fx/myenv/lib/python3.9/site-packages/torch_geometric/nn/fx.py", line 351, in trace
    'output', 'output', (self.create_arg(fn(*args)), ), {},
  File "/u/wyr6fx/PyG/GNNModel/HeterogenousGraph.py", line 16, in forward
    x = self.conv1(x, edge_index).relu()
  File "/u/wyr6fx/myenv/lib/python3.9/site-packages/torch_geometric/nn/fx.py", line 322, in module_getattr_wrapper
    return self._module_getattr(attr, attr_val,
AttributeError: 'Tracer' object has no attribute '_module_getattr'

### Environment

* PyG version: 2.0.4
* PyTorch version: 1.13.0
* OS: macOS
* Python version: 3.9.7
* CUDA/cuDNN version: cpu
* How you installed PyTorch and PyG (`conda`, `pip`, source): pip
* Any other relevant information (*e.g.*, version of `torch-scatter`): torch-scatter 2.0.9
rusty1s commented 1 year ago

This should be fixed in master, and will be released soon. Can you try upgrading to PyG master as indicated in the README.md?