tch-rs icon indicating copy to clipboard operation
tch-rs copied to clipboard

Saving optimizer state

Open cyb0124 opened this issue 3 years ago • 1 comments

It doesn't seem like optimizers' internal states are stored in VarStore. I also don't find any public interfaces for explicitly accessing / saving optimizers' internal states. So, is it possible to save and reload training state without losing optimizers' internal state?

cyb0124 avatar May 20 '21 19:05 cyb0124

I've taken a look into this. From the C++ API, I see this torch::save function template that accepts torch::optim::Optimizer as input, but it's not present in torch-sys API, probably since the generator does not generate it. We'll first need to add it to torch-sys/libtch/torch_api.{cpp,h}, and expose it in torch-sys/src/lib.rs, in order for tch to use it. It's similar to how torch_sys::at_save is done.

kotatsuyaki avatar Jul 15 '21 10:07 kotatsuyaki