Saving torch models
<SCODE>class VAE(nn.Module):
    def __init__(self):
        super(VAE, self).__init__()

        self.fc1 = nn.Linear(784, 400)

model = VAE()

with open('model_save', 'wb') as f: 
torch.save(model, f)
<ECODE>
Russel_Russel
I have no idea when are you getting the first error and what does it mean. I’ve never seen that.
apaszke
Russel_Russel
<SCODE>net = Net(...).cuda()
torch.save(net.state_dict(), './net.pth')
net.load_state_dict(torch.load('./net.pth'))<ECODE>
Veril
apaszke
x0s
I am implementing these exact same lines of code, but I get an error. Code : (On a different computer, with GPU) Code: (on my laptop) Error : module ‘torch._C’ has no attribute ‘_cuda_getDevice’ Note : I trained my model with cuda = True on a virtual environment on a network (with GPUs), but I want to evaluate my model on my laptop. I believe we need to ‘switch off’ the cuda before saving. Could you help?
jphreid
Ok, got it! …  map_location=lambda storage, loc: storage) : load the model on CPU.
jphreid