pytorch-image-models icon indicating copy to clipboard operation
pytorch-image-models copied to clipboard

Use in-place operations for EMA

Open jeromerony opened this issue 1 year ago • 4 comments

Hi,

I noticed that the EMA used here is pretty slow, since it does not use in-place operations. Using in-place ops results in a ~50% faster EMA, however, it does not work with type-promotion.

One workaround is to check whether a tensor from the model is floating point or not, with Tensor.is_floating_point(). I don't think there is any point in doing EMA on int tensors such as num_batches_tracked in BN.

Cheers!

jeromerony avatar Nov 17 '22 16:11 jeromerony