Hi,
I am interested in using the cuda primitive and also DataParallel
, currently I have implemented my network, it has multiple inputs, here is the train function :
for i, (input, target) in enumerate(train_loader):
# measure data loading time
data_time.update(time.time() - end)
target = target.cuda(async=True)
input_25 = torch.autograd.Variable(input[0])
input_51 = torch.autograd.Variable(input[1])
input_75 = torch.autograd.Variable(input[2])
target_var = torch.autograd.Variable(target)
# compute output
output = model(patch25=input_25, patch51=input_51, patch75=input_75)
This is actually working if I keep everything on CPU. The first implementation used DataParallel
, however the forward
function only takes a single input, not a list or dict, as the default implementation of nn.Module.forward()
, maybe this is an intended choice.
So I tried to just move the network to the GPU:
# basic_conv() returns a nn.Module
net = basic_conv().cuda()
Then I get this error that I cannot interpret myself :
Traceback (most recent call last):
File "read_network.py", line 29, in <module>
net(patch25=in25, patch51=in51, patch75=in75)
File "/home/ganaye/deps/miniconda3/lib/python3.5/site-packages/torch/nn/modules/module.py", line 210, in __call__
result = self.forward(*input, **kwargs)
File "/mnt/hdd/code/scripts/simple_conv.py", line 30, in forward
x_25 = self.conv2d_25_5(x['patch25'])
File "/home/ganaye/deps/miniconda3/lib/python3.5/site-packages/torch/nn/modules/module.py", line 210, in __call__
result = self.forward(*input, **kwargs)
File "/home/ganaye/deps/miniconda3/lib/python3.5/site-packages/torch/nn/modules/conv.py", line 235, in forward
self.padding, self.dilation, self.groups)
File "/home/ganaye/deps/miniconda3/lib/python3.5/site-packages/torch/nn/functional.py", line 37, in conv2d
return f(input, weight, bias) if bias is not None else f(input, weight)
File "/home/ganaye/deps/miniconda3/lib/python3.5/site-packages/torch/nn/_functions/conv.py", line 33, in forward
output = self._update_output(input, weight, bias)
File "/home/ganaye/deps/miniconda3/lib/python3.5/site-packages/torch/nn/_functions/conv.py", line 88, in _update_output
return self._thnn('update_output', input, weight, bias)
File "/home/ganaye/deps/miniconda3/lib/python3.5/site-packages/torch/nn/_functions/conv.py", line 147, in _thnn
return impl[fn_name](self, self._bufs[0], input, weight, *args)
File "/home/ganaye/deps/miniconda3/lib/python3.5/site-packages/torch/nn/_functions/conv.py", line 225, in call_update_output
bias, *args)
TypeError: FloatSpatialConvolutionMM_updateOutput received an invalid combination of arguments - got (int, torch.FloatTensor, torch.FloatTensor, torch.cuda.FloatTensor, torch.cuda.FloatTensor, torch.FloatTensor, torch.FloatTensor, int, int, int, int, int, int), but expected (int state, torch.FloatTensor input, torch.FloatTensor output, torch.FloatTensor weight, [torch.FloatTensor bias or None], torch.FloatTensor finput, torch.FloatTensor fgradInput, int kW, int kH, int dW, int dH, int padW, int padH)
It seems the error is coming from here, this is the forward call of my network:
def forward(self, **x):
# patch of size 25
x_25 = self.conv2d_25_5(x['patch25'])
x_25 = F.max_pool2d(x_25, 2, stride=1, padding=0)
I don’t get why it would work in CPU mode and not in GPU, the only thing I changed is calling cuda()
on the network.
Help !!
Thanks