DSE-MSU / DeepRobust

A pytorch adversarial library for attack and defense methods on images and graphs
MIT License
994 stars 192 forks source link

A question about r_gcn #67

Closed MatoCom closed 3 years ago

MatoCom commented 3 years ago

When trying to train a r_gcn model with the following code:

from deeprobust.graph.data import Dataset from deeprobust.graph.defense import RGCN data = Dataset(root='/tmp/', name='cora') adj, features, labels = data.adj, data.features, data.labels idx_train, idx_val, idx_test = data.idx_train, data.idx_val, data.idx_test rgcn = RGCN(nnodes=adj.shape[0],nfeat=features.shape[1], nhid=16, nclass=labels.max().item() + 1, dropout=0.5, device='cuda') rgcn.fit(features, adj, labels, idx_train) # train without earlystopping rgcn.fit(features, adj, labels, idx_train, idx_val, patience=30) # train with earlystopping rgcn.test(idx_test)

I encountered the following error:

RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking arugment for argument mat2 in method wrapper_mm)

I also tried the codes in the official document by changing the parameter "device='cpu'" into "device='cuda'", it also raised the same error.

ChandlerBang commented 3 years ago

Hi, can you provide more details about this bug? I just ran python examples/graph/test_rgcn.py and it works fine.

MatoCom commented 3 years ago

Ah, silly of me. I forgot to add that model = model.to(device). Sorry about that.