Build graph datasets by self data

#1

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.add_nodes(len(data))
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,

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

i am sorry i failed to find to set type

#2

Hi,

What’s the data type of data?

#3

tensor device cuda:0

#4

Hi,

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

#5

I have fixed this problem. thx.