pytorch_ema icon indicating copy to clipboard operation
pytorch_ema copied to clipboard

How to use it in pytorch-lightning?

Open Devoe-97 opened this issue 2 years ago • 5 comments

Hi, I would like to know how to use pytorch-ema for training in pytorh-lightning?

Devoe-97 avatar May 23 '22 04:05 Devoe-97

Hi @Devoe-97,

I think you'd want to implement a Lightning Callback that runs the appropriate ema.update(), ema.store(); ema.copy_to(), and ema.restore() operations at the right points in the training loop. Which callback methods that is I don't know, I'm not super familiar with Lightning. You might be able to take some inspiration from their StochasticWeightAveraging callback, which is somewhat similar of an idea to the EMA implemented in this package. (That callback may also work for you depending on what you are trying to achieve.)

If you have any luck with this, please share your work if you are willing!

Linux-cpp-lisp avatar May 23 '22 05:05 Linux-cpp-lisp

Hi @Devoe-97,

I think you'd want to implement a Lightning Callback that runs the appropriate ema.update(), ema.store(); ema.copy_to(), and ema.restore() operations at the right points in the training loop. Which callback methods that is I don't know, I'm not super familiar with Lightning. You might be able to take some inspiration from their StochasticWeightAveraging callback, which is somewhat similar of an idea to the EMA implemented in this package. (That callback may also work for you depending on what you are trying to achieve.)

If you have any luck with this, please share your work if you are willing!

Thanks!

Devoe-97 avatar May 23 '22 06:05 Devoe-97

Hi @Devoe-97,

I think you'd want to implement a Lightning Callback that runs the appropriate ema.update(), ema.store(); ema.copy_to(), and ema.restore() operations at the right points in the training loop. Which callback methods that is I don't know, I'm not super familiar with Lightning. You might be able to take some inspiration from their StochasticWeightAveraging callback, which is somewhat similar of an idea to the EMA implemented in this package. (That callback may also work for you depending on what you are trying to achieve.)

If you have any luck with this, please share your work if you are willing!

Hi, could you provide a demo in ddp mode? I encountered an OOM error while broadcasting in the validation step.

Devoe-97 avatar May 23 '22 08:05 Devoe-97

I second this original question. I think having this functionality working within PyTorch Lightning could greatly increase the visibility of this awesome repository!

amorehead avatar Nov 15 '22 16:11 amorehead

A demo would be great!

malbergo avatar Apr 14 '23 15:04 malbergo