ema-pytorch 0.3.1__tar.gz → 0.3.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ema-pytorch might be problematic. Click here for more details.
- {ema-pytorch-0.3.1 → ema-pytorch-0.3.3}/PKG-INFO +1 -1
- {ema-pytorch-0.3.1 → ema-pytorch-0.3.3}/README.md +13 -0
- {ema-pytorch-0.3.1 → ema-pytorch-0.3.3}/ema_pytorch/ema_pytorch.py +16 -2
- {ema-pytorch-0.3.1 → ema-pytorch-0.3.3}/ema_pytorch.egg-info/PKG-INFO +1 -1
- {ema-pytorch-0.3.1 → ema-pytorch-0.3.3}/setup.py +1 -1
- {ema-pytorch-0.3.1 → ema-pytorch-0.3.3}/LICENSE +0 -0
- {ema-pytorch-0.3.1 → ema-pytorch-0.3.3}/ema_pytorch/__init__.py +0 -0
- {ema-pytorch-0.3.1 → ema-pytorch-0.3.3}/ema_pytorch.egg-info/SOURCES.txt +0 -0
- {ema-pytorch-0.3.1 → ema-pytorch-0.3.3}/ema_pytorch.egg-info/dependency_links.txt +0 -0
- {ema-pytorch-0.3.1 → ema-pytorch-0.3.3}/ema_pytorch.egg-info/requires.txt +0 -0
- {ema-pytorch-0.3.1 → ema-pytorch-0.3.3}/ema_pytorch.egg-info/top_level.txt +0 -0
- {ema-pytorch-0.3.1 → ema-pytorch-0.3.3}/setup.cfg +0 -0
|
@@ -52,3 +52,16 @@ ema_output = ema(data)
|
|
|
52
52
|
## Todo
|
|
53
53
|
|
|
54
54
|
- [ ] address the issue of annealing EMA to 1 near the end of training for BYOL https://github.com/lucidrains/byol-pytorch/issues/82
|
|
55
|
+
|
|
56
|
+
## Citations
|
|
57
|
+
|
|
58
|
+
```bibtex
|
|
59
|
+
@article{Karras2023AnalyzingAI,
|
|
60
|
+
title = {Analyzing and Improving the Training Dynamics of Diffusion Models},
|
|
61
|
+
author = {Tero Karras and Miika Aittala and Jaakko Lehtinen and Janne Hellsten and Timo Aila and Samuli Laine},
|
|
62
|
+
journal = {ArXiv},
|
|
63
|
+
year = {2023},
|
|
64
|
+
volume = {abs/2312.02696},
|
|
65
|
+
url = {https://api.semanticscholar.org/CorpusID:265659032}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
@@ -43,7 +43,7 @@ class EMA(Module):
|
|
|
43
43
|
|
|
44
44
|
Args:
|
|
45
45
|
inv_gamma (float): Inverse multiplicative factor of EMA warmup. Default: 1.
|
|
46
|
-
power (float): Exponential factor of EMA warmup. Default:
|
|
46
|
+
power (float): Exponential factor of EMA warmup. Default: 2/3.
|
|
47
47
|
min_value (float): The minimum EMA decay rate. Default: 0.
|
|
48
48
|
"""
|
|
49
49
|
|
|
@@ -53,6 +53,7 @@ class EMA(Module):
|
|
|
53
53
|
model: Module,
|
|
54
54
|
ema_model: Optional[Module] = None, # if your model has lazylinears or other types of non-deepcopyable modules, you can pass in your own ema model
|
|
55
55
|
beta = 0.9999,
|
|
56
|
+
karras_beta = False, # if True, uses the karras time dependent beta
|
|
56
57
|
update_after_step = 100,
|
|
57
58
|
update_every = 10,
|
|
58
59
|
inv_gamma = 1.0,
|
|
@@ -65,7 +66,10 @@ class EMA(Module):
|
|
|
65
66
|
allow_different_devices = False # if the EMA model is on a different device (say CPU), automatically move the tensor
|
|
66
67
|
):
|
|
67
68
|
super().__init__()
|
|
68
|
-
self.
|
|
69
|
+
self._beta = beta
|
|
70
|
+
self.karras_beta = karras_beta
|
|
71
|
+
|
|
72
|
+
self.is_frozen = beta == 1.
|
|
69
73
|
|
|
70
74
|
# whether to include the online model within the module tree, so that state_dict also saves it
|
|
71
75
|
|
|
@@ -127,6 +131,13 @@ class EMA(Module):
|
|
|
127
131
|
@property
|
|
128
132
|
def model(self):
|
|
129
133
|
return self.online_model if self.include_online_model else self.online_model[0]
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def beta(self):
|
|
137
|
+
if self.karras_beta:
|
|
138
|
+
return (1 - 1 / (self.step + 1)) ** (1 + self.power)
|
|
139
|
+
|
|
140
|
+
return self._beta
|
|
130
141
|
|
|
131
142
|
def eval(self):
|
|
132
143
|
return self.ema_model.eval()
|
|
@@ -193,6 +204,9 @@ class EMA(Module):
|
|
|
193
204
|
|
|
194
205
|
@torch.no_grad()
|
|
195
206
|
def update_moving_average(self, ma_model, current_model):
|
|
207
|
+
if self.is_frozen:
|
|
208
|
+
return
|
|
209
|
+
|
|
196
210
|
copy, lerp = self.inplace_copy, self.inplace_lerp
|
|
197
211
|
current_decay = self.get_current_decay()
|
|
198
212
|
|
|
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
|
|
|
3
3
|
setup(
|
|
4
4
|
name = 'ema-pytorch',
|
|
5
5
|
packages = find_packages(exclude=[]),
|
|
6
|
-
version = '0.3.
|
|
6
|
+
version = '0.3.3',
|
|
7
7
|
license='MIT',
|
|
8
8
|
description = 'Easy way to keep track of exponential moving average version of your pytorch module',
|
|
9
9
|
author = 'Phil Wang',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|