Hi, I’m trying to train heter-graph with GraphSAGE in distributed mode. Following the demos in ‘examples/pytorch/rgcn/experiment’ and 'examples/pytorch/graphsage/experiment ',I found that the DGL actually sampled homo-graphs and doesn’t convert homo-blocks back to heter-blocks.
I wanna use GraphSAGE with my heter-graph, so the heter-blocks is necessary in my scenario.
I read the source code and tried to write my homo2heter function, but it doesn’t work well.
Here is my codes in ‘sample_blocks’ and the error messages.
class SimpleMeta:
def edges(self, keys=True):
# (srctype, dsttype, etype)
return [
("company", "person", "company-person"),
("person", "company", "person-company"),
("person", "person", "person-person")
]
def sample_blocks(self, seeds):
blocks = []
etypes = []
norms = []
ntypes = []
seeds = th.LongTensor(np.asarray(seeds))
gpb = self.g.get_partition_book()
# We need to map the per-type node IDs to homogeneous IDs.
next_global_homo_seeds = gpb.map_to_homo_nid(seeds, 'person')
for fanout in self.fanouts:
# For a heterogeneous input graph, the returned frontier is stored in
# the homogeneous graph format.
# -----------------------org-----------------------------
curr_global_homo_seeds = next_global_homo_seeds
homo_frontier = self.sample_neighbors(self.g, next_global_homo_seeds, fanout, replace=False)
block_tmp = dgl.to_block(homo_frontier, next_global_homo_seeds)
next_global_homo_seeds = block_tmp.srcdata[dgl.NID]
# -----------------------org-----------------------------
homo_frontier.ndata[dgl.NID] = th.arange(homo_frontier.number_of_nodes())
homo_frontier.ndata[dgl.NTYPE], _ = gpb.map_to_per_ntype(homo_frontier.ndata[dgl.NID])
homo_frontier.edata[dgl.ETYPE], _ = gpb.map_to_per_etype(homo_frontier.edata[dgl.EID])
heter_seed_nodes = {"person": [], "company": []}
for nid in curr_global_homo_seeds:
nid = nid.item()
ntype = homo_frontier.ndata[dgl.NTYPE][nid].item()
if ntype == 0:
heter_seed_nodes["company"].append(nid)
else:
heter_seed_nodes["person"].append(nid)
heter_frontier = dgl.to_heterogeneous(homo_frontier,
ntypes=["company", "person"], #self.g.ntypes
etypes=["company-person", "person-company", "person-person"], #self.g.etypes
metagraph=SimpleMeta())
heter_block = dgl.to_block(heter_frontier, heter_seed_nodes)
blocks.insert(0, heter_block)
return seeds, blocks
error message
Is there any idea to convert homo-blocks to heter-blocks or why my code raise this error message?
Thanks!