lllyasviel/ControlNet · error · ValueError
Invalid weight_decay value: {}
Error message
Invalid weight_decay value: {} What it means
Raised by the EMA-tracking AdamW optimizer when weight_decay is negative (weight_decay < 0.0). This optimizer (unlike some SGD variants) only accepts zero or positive weight decay; a negative value aborts construction.
Source
Thrown at ldm/util.py:105
return getattr(importlib.import_module(module, package=None), cls)
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.View on GitHub (pinned to ed85cd1e25)
Solutions
- Fix the sign: use a small non-negative value like 0.01 or 0.0 to disable
- If using a sweep, bound weight_decay to [0.0, 1e-1]
- Add pre-construction validation of the optimizer kwargs dict
Example fix
# before opt = AdamW(params, weight_decay=-1e-2) # after opt = AdamW(params, weight_decay=1e-2)
Defensive patterns
Strategy: validation
Validate before calling
assert 0.0 <= weight_decay, f'bad weight_decay: {weight_decay}' Prevention
- Use 0.0 to disable weight decay, never negative values
- Bound sweeps to non-negative weight decay
- Centralize optimizer-kwargs validation in training scripts
When it happens
Trigger: Constructing AdamW(params, weight_decay=-1e-2), or configs where weight decay was entered with a minus sign intending a larger effective lr (a misunderstanding of decoupled weight decay).
Common situations: Sign typos in YAML/JSON training configs, hyperparameter search sampling negative values, or porting configs from optimizers that interpret weight decay differently.
Related errors
- Invalid learning rate: {}
- Invalid epsilon value: {}
- Invalid beta parameter at index 0: {}
- Invalid beta parameter at index 1: {}
- Invalid ema_decay value: {}
AI-assisted analysis of lllyasviel/ControlNet@ed85cd1e25 (2026-08-27).
Data as JSON: /api/errors/6ad2793b60d144ee.
Report an issue: GitHub.