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

Hi,
Try this in the line you defined Hq = self.lq(hq):

self.lq = self.lq.float()
Hq = self.lq(hq)

Similar case:

# no error
linear = nn.Linear(1, 5).half().cuda()
x = torch.randn(1, 5, 1).cuda()
linear = linear.float()
linear(x)

# your error
linear = nn.Linear(1, 5).half().cuda()
x = torch.randn(1, 5, 1).cuda()
linear(x)

Bests

2 Likes

Thank you, this solved the issue!

Great, something I have mention is that based on stacktrace error, it seems you are using Nvidia Apex which does something related to mixed-precision, so explicitly, torch.half datatype has been used in the code. The solution I suggested was based on code, but it may affect the logic (I am not sure) although it should not as .float converts to 32-bit floating point meanwhile torch.half only needs 16 bits. Maybe somewhere else you can convert back to half to save memory or speed up.

Good luck

1 Like