dgl icon indicating copy to clipboard operation
dgl copied to clipboard

Can't get attribute 'DGLHeteroGraph' on <module 'dgl.heterograph' from '/usr/local/lib/python3.10/dist-packages/dgl/heterograph.py'>

Open 22842219 opened this issue 2 years ago • 10 comments

❓ Questions and Help

Hi,

I was trying to load a constructed dgl graph. but got the following error. Any advice for this? Thanks.

Can't get attribute 'DGLHeteroGraph' on <module 'dgl.heterograph' from '/usr/local/lib/python3.10/dist-packages/dgl/heterograph.py'>

22842219 avatar Jul 29 '23 12:07 22842219

Hi @22842219, could you follow the bug report template to provide more details?

czkkkkkk avatar Jul 31 '23 02:07 czkkkkkk

meet the same problem when using MNIST dataset at https://data.dgl.ai/dataset/benchmarking-gnns/MNIST.pkl

how to reproduce

curl https://data.dgl.ai/dataset/benchmarking-gnns/MNIST.pkl -o MNIST.pkl -J -L -k

with open("MNIST.pkl","rb") as f:
          f = pickle.load(f)

error

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    f = pickle.load(f)
AttributeError: Can't get attribute 'DGLHeteroGraph' on <module 'dgl.heterograph' from '/home/ubuntu/.local/lib/python3.8/site-packages/dgl/heterograph.py'>

paoxiaode avatar Jul 31 '23 06:07 paoxiaode

This is a known issue. Please refer to https://github.com/dmlc/dgl/issues/5574.

czkkkkkk avatar Aug 02 '23 04:08 czkkkkkk

If you use the new version of DGL, you can dump a new graph pkl file.

paoxiaode avatar Aug 02 '23 06:08 paoxiaode

how to deal with this problem?? @paoxiaode , looking for your reply, thx.

leaves520 avatar Aug 17 '23 06:08 leaves520

how to deal with this problem?? @paoxiaode , looking for your reply, thx.

@leaves520 This problem is due to the pkl file being dumped under an older version of DGL.

If you want to use the PATTERN, CLUSTER dataset, you can refer to https://github.com/dmlc/dgl/blob/master/python/dgl/data/pattern.py, they are now supported by DGL.

If you want to use the not DGL built-in dataset dataset(CIFAR 10 or MNIST), you can refer to https://github.com/graphdeeplearning/benchmarking-gnns/blob/master/data/superpixels/prepare_superpixels_MNIST.ipynb, use the code like below to re-dump the dataset pkl file

import pickle
import time

from data.superpixels import SuperPixDatasetDGL 

from data.data import LoadData
from torch.utils.data import DataLoader
from data.superpixels import SuperPixDataset

DATASET_NAME = 'MNIST'
dataset = SuperPixDatasetDGL(DATASET_NAME) 

with open('data/superpixels/MNIST.pkl','wb') as f:
        pickle.dump([dataset.train,dataset.val,dataset.test],f)

paoxiaode avatar Aug 24 '23 04:08 paoxiaode

This issue has been automatically marked as stale due to lack of activity. It will be closed if no further activity occurs. Thank you

github-actions[bot] avatar Sep 24 '23 01:09 github-actions[bot]

How to solve this for ZINC dataset.

GARV-k avatar Jul 02 '24 11:07 GARV-k

How to solve this for ZINC dataset.

Yes, please.

ruze00 avatar Aug 13 '24 01:08 ruze00

How to solve this for ZINC dataset.

Hi, I'm not sure if you still need, but if you want to use a new version DGL to load a dataset generated by old version DGL(with DGLHeteroGraph), you can define a class in the lib of DGL(/your_dir/miniconda3/envs/your_env_name/lib/python3.12/site-packages/dgl/heterograph.py) like this

class DGLHeteroGraph(DGLGraph):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs) 

Also add the DGLHeteroGraph to __all__ = ["DGLGraph", "combine_names"], and import DGLHeteroGraph in the __init__.py. I have tried and it works for me.

zyzheng17 avatar Aug 12 '25 07:08 zyzheng17