Having trouble with nn.to(device) and device = 'cuda:0'

(Rita) #1

Hi all,
I just started with pytorch.

I have a this configuration:
description: VGA compatible controller
product: NVIDIA Corporation
vendor: NVIDIA Corporation
physical id: 0
bus info: pci@0000:01:00.0
version: a1
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress vga_controller bus_master cap_list rom
configuration: driver=nvidia latency=0
CUDA: NVIDIA ® Cuda compiler driver
Copyright © 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85
Torch: 0.4.0
Torchvision 0.2.1
Python 3.6

I’m studing on the tutorials and I when i do:
class Net(nn.Module):

def __init__(self):
    super(Net, self).__init__()
    #1 input, 6 output, 5x5 square conv
    self.conv1 = nn.Conv2d(3,6,5)
    self.pool = nn.MaxPool2d(2,2)
    self.conv2 = nn.Conv2d(6,16,5)
    #y = Wx+b
    self.fc1 = nn.Linear(16*5*5,120)
    self.fc2 = nn.Linear(120,84)
    self.fc3 = nn.Linear(84, 10)

def forward(self,x):
    #max pooling over 2x2 window
    x = self.pool(F.relu(self.conv1(x)))
    #if the size is a square it is possible to specify only one number
    x = self.pool(F.relu(self.conv2(x)))
    #view is a resize
    x = x.view(-1,16*5*5)
    x = F.relu(self.fc1(x))
    x = F.relu(self.fc2(x))
    x = self.fc3(x)
    return x

device = torch.device(‘cuda:0’ if torch.cuda.is_available() else ‘cpu’)

net = Net()

The system stuck on net.to(device) and then crash with sigkill:

Process finished with exit code 137 (interrupted by signal 9: SIGKILL)

I do not have any problem when device = ‘cpu’
Is here anyone that can explain to me how to fix it?
thank you super so much