Load saved network

[BEFORE]
net = nn.DataParallel(net).cuda()

torch.save(net, save_folder + '/' + 'net.pt')
net = nn.DataParallel(torch.load(save_folder + '/net.pt'), device_ids=[0]).to(device)

[AFTER]
torch.save(net.module.state_dict(), 'net.pt')
net.module.load_state_dict(torch.load('/net.pt'), strict=False)

I saved the saved model with [BEFORE] codes.
Now I’ve changed codes from [BEFORE] to [AFTER]. Because I figured out there are some problems with [BEFORE] codes when I loaded the model with DataParallel.

But I have to use the trained model that saved with [BEFORE] codes. How can I load ?

If I trained the model with gpu_id:{2,3}, then should I load this model with {2,3} ?

If you need to load the [BEFORE] model, you could directly try to use:

net = torch.load(PATH)

and make sure the source code is in the same location (and “important” parts are unchanged).
If possible, use the same machine, which should load the model to the same devices.
Once this is done, save the state_dict properly using the [AFTER] approach.