Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HeteroGraphConv documentation sample code crash #7687

Open
FatherOfDragons opened this issue Aug 12, 2024 · 1 comment
Open

HeteroGraphConv documentation sample code crash #7687

FatherOfDragons opened this issue Aug 12, 2024 · 1 comment
Labels
bug:confirmed Something isn't working topic: doc Issues related to DGL's documentation, tutorials or any requests on doc improvement

Comments

@FatherOfDragons
Copy link

🐛 Bug

To Reproduce

Steps to reproduce the behavior:
Following the code snippet example in HeteroGraphConv documentation with an actual implementation results in a crash
HeteroGraphConv

import dgl
import dgl.graphbolt as gb
import dgl.nn as dglnn

import torch as th
import numpy as np

n_users = 50
n_games = 10
n_stores = 5

follows_src = np.random.randint(0, n_users, 100)
follows_dst = np.random.randint(0, n_users, 100)

plays_src = np.random.randint(0, n_users, 50)
plays_dst = np.random.randint(0, n_games, 50)

sells_src = np.random.randint(0, n_stores, 20)
sells_dst = np.random.randint(0, n_games, 20)


g = dgl.heterograph(
    {
        ("user", "follows", "user"): (follows_src, follows_dst),
        ("user", "plays", "game"): (plays_src, plays_dst),
        ("store", "sells", "game"): (sells_src, sells_dst),
    }
)

input_dim = 16
out_dim = 8

hetero_conv = dglnn.HeteroGraphConv(
    {
        "follows": dglnn.GraphConv(input_dim, out_dim),
        "plays": dglnn.GraphConv(input_dim, out_dim),
        "sells": dglnn.GraphConv(input_dim, out_dim),
    },
    aggregate="sum",
)

h1 = {"user": th.randn((g.num_nodes("user"), input_dim))}

h2 = hetero_conv(g, h1)
print(h2.keys())
python heterographconv_example.py
Traceback (most recent call last):
  File "/Users/yuri/remix/projects/easy-platform/platform-python/pinsage-recommender/heterographconv_example.py", line 44, in <module>
    h2 = hetero_conv(g, h1)
         ^^^^^^^^^^^^^^^^^^
  File "/Users/yuri/remix/projects/easy-platform/platform-python/pinsage-recommender/.venv/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yuri/remix/projects/easy-platform/platform-python/pinsage-recommender/.venv/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yuri/remix/projects/easy-platform/platform-python/pinsage-recommender/.venv/lib/python3.11/site-packages/dgl-2.3.0-py3.11-macosx-11.1-arm64.egg/dgl/nn/pytorch/hetero.py", line 212, in forward
    (inputs[stype], inputs[dtype]),
                    ~~~~~~^^^^^^^
KeyError: 'game'

Expected behavior

dict_keys(['user', 'game'])

Environment

  • DGL Version: 2.3.0
  • OS: macOS Sonoma 14.5
  • How you installed DGL: source (HEAD detached at v2.3.0)
  • Build command you used:
cmake -DBUILD_CPP_TEST=OFF -DUSE_OPENMP=OFF -DUSE_LIBXSMM=OFF  ..
make -j4
  • Python version: Python 3.11.5

Additional context

When 'game' features are added to h1 the example works
Not sure, if this is an implementation bug or a documentation issue.
It seems reasonable to expect the example code to work as shown in documentation in case 'game' nodes don't have any intrinsic features
Also, when a block is passed into the forward function instead of a graph, the failure is silent and the call returns an empty dictionary

@rudongyu rudongyu added bug:confirmed Something isn't working topic: doc Issues related to DGL's documentation, tutorials or any requests on doc improvement labels Aug 15, 2024
@rudongyu
Copy link
Collaborator

In our current development, we assume all types of node features should be provided. We will update the documentation later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:confirmed Something isn't working topic: doc Issues related to DGL's documentation, tutorials or any requests on doc improvement
Projects
Status: 🏠 Backlog
Development

No branches or pull requests

2 participants