Build graph datasets by self data


Hi, all:
i have some data, src, dst to build a graph dataset. and g.ndata is used tensor, device = cuda:0 , no edata.

g = dgl.DGLGraph()
g.ndata[‘h’] = data
g.add_edges(src, dst)
g.add_edges(dst, src)

but when i batched these built graph data, i met some problems,

RuntimeError: Traceback (most recent call last):
File “/home/yanglan/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/utils/data/”, line 138, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File “/home/yanglan/code/”, line 23, in collate
batched_graph = dgl.batch(graphs)
File “/home/yanglan/anaconda3/envs/pytorch/lib/python3.7/site-packages/dgl/”, line 354, in batch
return BatchedDGLGraph(graph_list, node_attrs, edge_attrs)
File “/home/yanglan/anaconda3/envs/pytorch/lib/python3.7/site-packages/dgl/”, line 192, in init
for key in node_attrs}
File “/home/yanglan/anaconda3/envs/pytorch/lib/python3.7/site-packages/dgl/”, line 192, in
for key in node_attrs}
File “/home/yanglan/anaconda3/envs/pytorch/lib/python3.7/site-packages/dgl/”, line 191, in
if gr.number_of_nodes() > 0], dim=0)
File “/home/yanglan/anaconda3/envs/pytorch/lib/python3.7/site-packages/dgl/”, line 557, in getitem
return self.select_column(key)
File “/home/yanglan/anaconda3/envs/pytorch/lib/python3.7/site-packages/dgl/”, line 584, in select_column
return col[self._index]
File “/home/yanglan/anaconda3/envs/pytorch/lib/python3.7/site-packages/dgl/”, line 100, in getitem
user_idx = idx.tousertensor(F.context(
File “/home/yanglan/anaconda3/envs/pytorch/lib/python3.7/site-packages/dgl/”, line 107, in tousertensor
self._user_tensor_data[ctx] = F.copy_to(data, ctx)
File “/home/yanglan/anaconda3/envs/pytorch/lib/python3.7/site-packages/dgl/backend/pytorch/”, line 84, in copy_to
File “/home/yanglan/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch/cuda/”, line 264, in set_device
RuntimeError: cuda runtime error (3) : initialization error at /opt/conda/conda-bld/pytorch_1544176307774/work/torch/csrc/cuda/Module.cpp:34

i am sorry i failed to find to set type



What’s the data type of data?


tensor device cuda:0



Do you have the same error without multiprocessing dataloader (when num_workers=0) ?


I have fixed this problem. thx.