fadel / pytorch_ema

Tiny PyTorch library for maintaining a moving average of a collection of parameters.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Usage of weakref broke pickling/unpickling

toshas opened this issue · comments

If I want to store a EMA'd GAN generator, there should either be an option to not use weakrefs at all, or instantiate some real memory upon serialization.
Since I came across it from a project using it as a dependency, it took me a while to locate a commit where pickling got broken. I suggest to make versioned releases to pip registry, in order to facilitate reproducibility.
Thanks for the great library otherwise!

Hi @toshas,

Thanks for pointing this out — did not occur to me when I added weakref. Recent additions to the code mean the supported way to save an ExponentialMovingAverage is through its state dict (state_dict(), like a PyTorch optimizer), but we don't want to break backward compatibility either...

We are planning to release this to PyPI with versioning in the coming days; what we can do for reproducibility is to first release a version based on the code before any recent changes and then another version with the recent changes. This should allow projects like the one you mention to pin to the older version until they decide they want features from the updated code.

Would that resolve your issue?

Yes that sounds like a plan indeed, thanks!
We are currently using commit id b1de75d

The previous version (0.2, in our versioning, before any of the weakref or other new changes), is now public on PyPI: https://pypi.org/project/torch-ema/0.2/