lllyasviel/ControlNet · error · ValueError
Invalid ema_decay value: {}
Error message
Invalid ema_decay value: {} What it means
Raised by the EMA-tracking AdamW optimizer when ema_decay is outside [0.0, 1.0]. This custom parameter tracks an exponential moving average of the weights during training (used at inference for smoothed weights), so its decay factor must be a valid probability in the closed interval [0, 1].
Source
Thrown at ldm/util.py:107
class AdamWwithEMAandWings(optim.Optimizer):
# credit to https://gist.github.com/crowsonkb/65f7265353f403714fce3b2595e0b298
def __init__(self, params, lr=1.e-3, betas=(0.9, 0.999), eps=1.e-8, # TODO: check hyperparameters before using
weight_decay=1.e-2, amsgrad=False, ema_decay=0.9999, # ema decay to match previous code
ema_power=1., param_names=()):
"""AdamW that saves EMA versions of the parameters."""
if not 0.0 <= lr:
raise ValueError("Invalid learning rate: {}".format(lr))
if not 0.0 <= eps:
raise ValueError("Invalid epsilon value: {}".format(eps))
if not 0.0 <= betas[0] < 1.0:
raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0]))
if not 0.0 <= betas[1] < 1.0:
raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1]))
if not 0.0 <= weight_decay:
raise ValueError("Invalid weight_decay value: {}".format(weight_decay))
if not 0.0 <= ema_decay <= 1.0:
raise ValueError("Invalid ema_decay value: {}".format(ema_decay))
defaults = dict(lr=lr, betas=betas, eps=eps,
weight_decay=weight_decay, amsgrad=amsgrad, ema_decay=ema_decay,
ema_power=ema_power, param_names=param_names)
super().__init__(params, defaults)
def __setstate__(self, state):
super().__setstate__(state)
for group in self.param_groups:
group.setdefault('amsgrad', False)
@torch.no_grad()
def step(self, closure=None):
"""Performs a single optimization step.
Args:
closure (callable, optional): A closure that reevaluates the model
and returns the loss.
"""
loss = NoneView on GitHub (pinned to ed85cd1e25)
Solutions
- Set ema_decay to a value in [0, 1]; the constructor default is 0.9999
- If ramping decay per step, clamp: ema_decay = min(max(decay, 0.0), 1.0)
- Double-check you didn't pass ema_power (typically 1.0 or 3/4) into the ema_decay slot
Example fix
# before opt = AdamW(params, ema_decay=min(1.0 + k * 0.01, ...)) # can exceed 1.0 # after opt = AdamW(params, ema_decay=min(max(0.9999 + k * 1e-5, 0.0), 1.0))
Defensive patterns
Strategy: validation
Validate before calling
assert 0.0 <= ema_decay <= 1.0, f'bad ema_decay: {ema_decay}' Prevention
- Clamp any schedule-computed decay: min(max(d, 0.0), 1.0)
- Don't confuse ema_decay with ema_power
- Keep EMA decay near 0.9999 unless deliberately tuning
When it happens
Trigger: Constructing AdamW(params, ema_decay=1.2) or ema_decay=-0.5, or computing ema_decay dynamically (e.g. d * scale in EMA-adjustment logic) so that it leaves the valid range.
Common situations: Custom training loops that ramp EMA decay over time and overshoot 1.0, configs mixing up ema_decay with ema_power, or ported hyperparameters from torch_ema where valid ranges differ.
Related errors
- Invalid learning rate: {}
- Invalid epsilon value: {}
- Invalid beta parameter at index 0: {}
- Invalid beta parameter at index 1: {}
- Invalid weight_decay value: {}
AI-assisted analysis of lllyasviel/ControlNet@ed85cd1e25 (2026-08-27).
Data as JSON: /api/errors/b90fc61fe661bc45.
Report an issue: GitHub.