Fix bug in torch::load and unpack torch::optim::detail namespace (#15926)
Summary:
Wasn't clearing optimizer buffers before adding new entries to it during deserialization. Successive calls to `torch::load` with the same optimizer would just append to the buffer container. Also moved `serialize()` function from `torch::optim::detail` into `torch::optim` so users can use it for custom optimizers.
Fixes #15792
ezyang
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15926
Differential Revision: D13623615
Pulled By: goldsborough
fbshipit-source-id: e193091f25f56a95f2a9648af312cb7caa45f300