TypeError: addmm_, after transfering the net to GPU (works fine on CPU)
Hi all, to Thanks a lot for your help.
nelsonleung
the input to your network is on the CPU, but your network is transferred to the GPU (or vice versa). Here’s the critical part of the error that helped me figure this out: <SCODE> got (int, int, torch.FloatTensor, torch.cuda.FloatTensor),
<ECODE>
smth
I see. Got it to work. Thanks a lot for your prompt reply!
nelsonleung
Thanks in advance.
Ke_Bai
jupiter
<SCODE>def __len__(self):
    return self.npy_data.shape[0]

def __getitem__(self, index):
    fm_data = np.array(self.npy_data[:, :-1], dtype = np.float)
    label_data = np.array(self.npy_data[:, -1], dtype = np.float)

    return fm_data, label_data
<ECODE> <SCODE>def forward(self, x):
    out = self.fc1(x)
    out = self.relu(out)
    out = self.fc2(out)
    return out
<ECODE> <SCODE>        label_data = torch.from_numpy(label_data).float().cuda()
        label_data = Variable(label_data)

        optimizer.zero_grad()  # zero the gradient buffer
        outputs = net(fm_data)
        loss = criterion(outputs, label_data)
        loss.backward()
        optimizer.step()

        if (i + 1) % 100 == 0:
            print ('Epoch [%d/%d], Step [%d/%d], Loss: %.4f'
                   %(epoch+1, num_epochs, i+1, len(train_data)//batch_size, loss.data[0]))
<ECODE> could you give me an advice to solve this problem? Thank you very much!
Dami_Mi
By the way, your question has nothing to do with the original post. So you should post a new thread instead replying in here. Further more, the error message is quite clear in your case, you might be able to solve such issues faster if you think about the message and consult the doc in future…
SimonW
Dami_Mi
Hi Nelson
Borna_Ghotbi
Hey. Have you got it worked?
xhran2010