dgl icon indicating copy to clipboard operation
dgl copied to clipboard

The assignment behavior of DGLGraph.dstdata is wrong in some cases

Open yfismine opened this issue 1 year ago • 5 comments

🐛 Bug

To Reproduce

Steps to reproduce the behavior:

import dgl
from openhgnn.dataset.gtn_dataset import ACM4GTNDataset

graph = dgl.to_block(ACM4GTNDataset()[0])
print(graph)
print(graph.dstdata["label"])
graph.dstdata["label_copy"] = graph.dstdata["label"]
print(graph.dstdata["label_copy"])
print(graph.srcdata["label_copy"])
graph.dstnodes["paper"].data["label_copy"] = next(iter(graph.dstdata["label"].values()))
print(graph.dstdata["label_copy"])

image

Expected behavior

You can see that the attribute directly assigned to dstdata can't be found by querying dstdata. On the contrary, it is amazing to find this attribute in srcdata. I checked the code of HeteroNodeDataView and found that, The ntid used by self._graph._set_n_repr is through self._graph.get_ntype_id(ntype), but in get_ntype_id, ntid = self. _ srctypes _ invmap.get (ntype, Self. _ dsttypes _ invmap.get (ntype, none)), that is to say, the obtained ntid gives priority to srctypes, so this bug will be triggered if ntype appears in both the source node and the destination node.

Environment

  • DGL Version : 2.2.1
  • Backend Library & Version : Pytorch 2.3.0
  • OpenHGNN Version: 0.4.2
  • OS : Linux
  • How you installed DGL : conda
  • Python version: 3.12.3
  • CUDA/cuDNN version (if applicable): 11.8
  • GPU models and configuration : nvidia 3090

yfismine avatar Jun 07 '24 12:06 yfismine

What's your use case of using to_block()?

frozenbugs avatar Jun 13 '24 02:06 frozenbugs

What's your use case of using to_block()?

DGLGraph image

yfismine avatar Jun 13 '24 03:06 yfismine

to_block is to create a bipartite-structured block for message passing. It is more an internal util method than public api of dgl, we expose it just in case users want to experiment with it. Can you be more specific about why you need to use to_block to create a bipartite-structured block? Can DGLGraph fit your need?

frozenbugs avatar Jun 17 '24 09:06 frozenbugs

to_block is to create a bipartite-structured block for message passing. It is more an internal util method than public api of dgl, we expose it just in case users want to experiment with it. Can you be more specific about why you need to use to_block to create a bipartite-structured block? Can DGLGraph fit your need?

It is found that the assignment behavior here is normal if to_block is not used. I encountered this problem when I used dist dgl for neighbor sampling and found that the generated block has no attributes. I need to pull data through DistGraph in a way like "batch _ labels = g. ndata ["labels "] [seeds]. long (). To (device)". I hope to unify the training codes of stand-alone and distributed. I re-implement the sampler_block of neighborSampler and assign attributes to the block in it. image

yfismine avatar Jun 17 '24 09:06 yfismine

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 Jul 18 '24 01:07 github-actions[bot]