THUDM / CogDL

CogDL: A Comprehensive Library for Graph Deep Learning (WWW 2023)

Home Page:https://cogdl.ai

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'np.int' should changed to 'np.int16' in cogdl/utils/utils.py

Song-xx opened this issue · comments

commented

🐛 Bug

To Reproduce

Steps to reproduce the behavior:

  1. install cogdl==0.6.0;
  2. from cogdl import pipeline and use 'generate-emb’ for pipeline;
  3. use 'cora' as dataset, and use 'line' or 'netsmf' as model name;
  4. bug is in the function alias_setup of cogdl/utils/utils.py.
data = build_dataset_from_name("cora").data
edge_index = ......
generator = pipeline("generate-emb", model=model.lower(), return_model=True,
                     num_features=-1, hidden_size=emb_dim, cpu=True,
                     cpu_inference=True, no_test=True)
emb = generator(edge_index, data.x.numpy())

Expected behavior

Environment

  • CogDL version: 0.6.0
  • OS (e.g., Linux): macos m1
  • Python version: 3.9
  • PyTorch version: 2.0.1
  • CUDA/cuDNN version (if applicable): None
  • Any other relevant information: numpy==1.23.5

Additional context

Traceback (most recent call last):
    ......
    emb = generator(edge_index, data.x.numpy())
  File "/Users/xxx/python3.9/site-packages/cogdl/pipelines.py", line 189, in __call__
    embeddings = self.model(data)
  File "/Users/xxx/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/Users/xxx/python3.9/site-packages/cogdl/models/emb/line.py", line 75, in forward
    self.edges_table, self.edges_prob = alias_setup(self.edges_prob)
  File "/Users/xxx/python3.9/site-packages/cogdl/utils/utils.py", line 109, in alias_setup
    J = np.zeros(K, dtype=np.int)
  File "/Users/xxx/python3.9/site-packages/numpy/__init__.py", line 305, in __getattr__
    raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
commented

A similar error occurs in construct_sparse in cogdl/utils/ppr_utils.py, it also has a dtype=np.int.

Hi @Song-xx, it seems that the new version of Numpy does not support np.int. Maybe you can download the source code and quickly fix the error by replacing the np.int with int or numpy.int_. And we will update the code for latest Numpy in the near future.