PySyft icon indicating copy to clipboard operation
PySyft copied to clipboard

RuntimeError: Expected object of device type cuda but got device type cpu for argument #1 'self' in call to _th_set_

Open aynesss opened this issue 1 year ago • 2 comments

Description

A clear and concise description of what you want to test.

Type of Test

class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = nn.Conv2d(1, 20, 5, 1)
        self.conv2 = nn.Conv2d(20, 50, 5, 1)
        self.fc1 = nn.Linear(4*4*50, 500)
        self.fc2 = nn.Linear(500, 10)
    def forward(self, x):
        x = F.relu(self.conv1(x))
        ...
        x = self.fc2(x)
        return F.log_softmax(x, dim=1) 
model = Net().to(device)

I would like to modify this model by a pretrained resnet :

model = models.resnet50(pretrained=True)
model.to(device)

But its triggers:

RuntimeError: Expected object of device type cuda but got device type cpu for argument #1 'self' in call to _th_set_

The error was in model.get() How can I solve this pb. Thks

aynesss avatar Mar 06 '23 11:03 aynesss

same question. When I use device = torch.device("cpu") this error would disappear. This could be because PySyft may have some compatibility issues with PyTorch’s CUDA functionality, and it may not allow you to move your tensors and models to the GPU device.

cherry-licongyi avatar Aug 22 '23 08:08 cherry-licongyi

@aynesss what version of Syft are you using?

madhavajay avatar Feb 14 '24 06:02 madhavajay

Closing for now.

madhavajay avatar Feb 26 '24 13:02 madhavajay