THUDM / CogDL

CogDL: A Comprehensive Library for Graph Deep Learning (WWW 2023)
https://cogdl.ai
MIT License
1.73k stars 315 forks source link

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

Closed Song-xx closed 1 year ago

Song-xx commented 1 year ago

šŸ› 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

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
Song-xx commented 1 year ago

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

cenyk1230 commented 1 year ago

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.