pytorch - net.cuda() seems don't work
I wrote a cnn module to do digit recognition using pytorch, then try to train the network with gpu but got following error.

Traceback (most recent call last):
  File "main.py", line 51, in &lt;module&gt;
    outputs = cnn(inputs)
  File "/home/daniel/anaconda3/envs/pytorch/lib/python3.5/site-packages/torch/nn/modules/module.py", line 357, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/daniel/Code/kaggle-competitions/digit-recognizer/Net.py", line 40, in forward
    x = self.pool(F.relu(self.conv[i](x)))
  File "/home/daniel/anaconda3/envs/pytorch/lib/python3.5/site-packages/torch/nn/modules/module.py", line 357, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/daniel/anaconda3/envs/pytorch/lib/python3.5/site-packages/torch/nn/modules/conv.py", line 282, in forward
    self.padding, self.dilation, self.groups)
  File "/home/daniel/anaconda3/envs/pytorch/lib/python3.5/site-packages/torch/nn/functional.py", line 90, in conv2d
    return f(input, weight, bias)
RuntimeError: Input type (CUDAFloatTensor) and weight type (CPUFloatTensor) should be the same


here is my source code

It seems that cnn.cuda() didn't work properly because I got the same error after removing it. But I have no idea how to fix it.

Daniel's answer to his own question seems to be correct. The problem is indeed that modules are not recognized if they are appended to a list. However, Pytorch also provides built-in solutions to this problem:
nn.ModuleList and nn.ModuleDict are two container types that keep track of the added content and their parameters. 
Both have the same functionality as their Python equivalents, but the dictionary uses named arguments and can be used to keep track of for example task-specific layers. 

A working example would be:

    self.conv = torch.nn.ModuleList()
    self.conv.append(nn.Conv2d(1, channels[0], kernel_sizes[0]))
    self.conv_img_size = math.floor((self.conv_img_size - (kernel_sizes[0]-1))/2)

    for i in range(1, self.conv_layer_size):
        self.conv.append(nn.Conv2d(channels[i-1], channels[i], kernel_sizes[i]))
        self.conv_img_size = math.floor((self.conv_img_size - (kernel_sizes[i]-1))/2)
        # Modules are automatically added to the model parameters

