ema-pytorch
Easy way to keep track of exponential moving average version of your pytorch module
What it is and what it does
ema-pytorch wraps a PyTorch neural network to automatically maintain an exponential moving average (EMA) copy of its weights during training. Instead of using the latest model weights for inference or validation, you can use the EMA version, which often generalizes better by smoothing out noisy weight updates. The wrapper handles the decay schedule, update frequency, and optional warmup logic so you only need to call update() after each training step.
The package supports three main patterns: standard EMA with configurable decay and update frequency, post-hoc EMA synthesis (where multiple EMA versions are checkpointed and interpolated to create a new EMA at a different decay rate), and target representation routing for nested module architectures where EMA outputs are injected as teacher signals into student submodules. It is commonly used in diffusion models, self-supervised learning, and other training regimes where model averaging improves convergence or generalization.
Use it for:
- Improve validation accuracy in diffusion models by using EMA weights instead of the latest training weights.
- Implement teacher-student training in self-supervised learning where EMA outputs guide online module predictions.
- Synthesize a new EMA model at a different decay rate from saved checkpoints without retraining.
- Reduce overfitting in standard supervised learning by averaging weights across training steps.
- Experiment with Switch EMA to update the online model with EMA weights periodically for better loss landscape flatness.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Maintains an exponential moving average (EMA) copy of a PyTorch model during training, with configurable decay, update frequency, and optional post-hoc synthesis across multiple EMA versions.
Yes. The package is lightweight, actively maintained, has no known vulnerabilities, and solves a well-defined problem (EMA tracking) that is standard in modern deep learning. Install it if you are training a PyTorch model and want to leverage weight averaging for better generalization or if you need post-hoc EMA synthesis for research.
Install
ema-pytorch on PyPI
pip
pip install ema-pytorchuv
uv add ema-pytorchpoetry
poetry add ema-pytorchInstalling ema-pytorch
Before you install
Low friction: pure Python wheel with only torch as a runtime dependency. Active maintenance with a recent release (14 days old) and steady commit history.
License in practice
MIT license permits commercial and private use with minimal restrictions; you must include a copy of the license and copyright notice.
Quickstart
pip install ema-pytorch
import torch
from ema_pytorch import EMA
net = torch.nn.Linear(512, 512)
ema = EMA(net, beta=0.9999, update_after_step=100, update_every=10)
# After training updates to net:
ema.update()
output = ema(data)
Requires PyTorch to be installed; Python 3.8 or later.
Verify before relying
- Whether post-hoc EMA synthesis (Karras et al.) offers measurable accuracy gains for your model architecture.
- Performance overhead of EMA updates relative to model size and batch frequency.
- Compatibility with distributed training frameworks (DDP, FSDP) not mentioned in the description.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — torch |
| Maintenance | actively maintained — 14 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 253,140/month — #8,526 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: ema_pytorch-0.8.3-py3-none-any.whl
Keywords: artificial intelligence, deep learning, exponential moving average
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
torch-emaComputes exponential moving averages of PyTorch…
unclear · top 15,000 on PyPI
adam-atan2-pytorchProvides an Adam optimizer variant using atan2…
permissive · top 15,000 on PyPI
torchmetricsTorchmetrics provides a collection of PyTorch…
permissive · top 5,000 on PyPI
torchsummaryDisplays a Keras-style summary of PyTorch…
unclear · top 15,000 on PyPI
torch-model-archiverTorch Model Archiver creates .mar archive files…
permissive · top 15,000 on PyPI
vit-pytorchProvides PyTorch implementations of Vision…
permissive · top 15,000 on PyPI
vector-quantize-pytorchImplements vector quantization layers for…
permissive · top 5,000 on PyPI
conformerProvides PyTorch implementations of the…
permissive · top 15,000 on PyPI
schedulefreeProvides schedule-free optimizers for PyTorch…
permissive · top 15,000 on PyPI
lion-pytorchLion is a PyTorch optimizer that implements an…
permissive · top 15,000 on PyPI