I would like to save and load the weights of my model several time for each epochs during training. At the moment I save and load the model from a file but it is slow.
I know that it is possible to save it inside a IOBuffer object but it is not possible on GPU. Is there a way to save and load a model from a variable on both CPU and GPU quickly ?
Thank you.
But it does not work, the weights of the model do not change after the loading for both solutions :
model = torch.nn.Linear(4,4)
save = model
#training here
print(net.weight.data)
model = save
print(net.weight.data)
#Same result for both print
model = torch.nn.Linear(4,4)
save = model.state_dict()
#training here
print(net.weight.data)
model.load_state_dict(save)
print(net.weight.data)
#Same result for both print