jcjohnson / torch-rnn

Efficient, reusable RNNs and LSTMs for torch
MIT License
2.5k stars 508 forks source link

How to deep copy checkpoint.model ? #109

Open already-taken-m17 opened 8 years ago

already-taken-m17 commented 8 years ago

I am trying to copy checkpoint.model (in sample.lua file) into another variable and then I want both the variables to perform independently (basically I need a way to deep copy). I tried many ways, including this: [(https://gist.github.com/tylerneylon/81333721109155b2d244)] But, some of the variables have datatype userdata in checkpoint model, and because of this I am not able to perform of deep copy. Can anyone please suggest a way how to perform that ?

jcjohnson commented 8 years ago

An easy way to get a deep copy of anything in Torch is to serialize and deserialize the same object:

local model_copy = torch.deserialize(torch.serialize(model))
brisker commented 7 years ago

@already-taken-m17 @jcjohnson After training a model, I find the training epoch seems not enough, so I reload it and try to finetune(retrain), but why the training loss seems like the beginning training loss, just like I am training it from scratch? I save the model using local model_copy = torch.deserialize(torch.serialize(model)) and torch.save('model_dir',model_copy) Help?