Stability-AI/generative-models · error · ValueError
Decay must be between 0 and 1
Error message
Decay must be between 0 and 1
What it means
LitEma stores exponential-moving-average shadow weights and requires a decay factor in [0, 1]; the constructor validates this up front and raises ValueError otherwise. Decay of 0 would make the EMA meaningless and negative or >1 values are mathematically invalid for an EMA.
Source
Thrown at sgm/modules/ema.py:9
import torch
from torch import nn
class LitEma(nn.Module):
def __init__(self, model, decay=0.9999, use_num_upates=True):
super().__init__()
if decay < 0.0 or decay > 1.0:
raise ValueError("Decay must be between 0 and 1")
self.m_name2s_name = {}
self.register_buffer("decay", torch.tensor(decay, dtype=torch.float32))
self.register_buffer(
"num_updates",
torch.tensor(0, dtype=torch.int)
if use_num_upates
else torch.tensor(-1, dtype=torch.int),
)
for name, p in model.named_parameters():
if p.requires_grad:
# remove as '.'-character is not allowed in buffers
s_name = name.replace(".", "")
self.m_name2s_name.update({name: s_name})
self.register_buffer(s_name, p.clone().detach().data)
self.collected_params = []View on GitHub (pinned to e8cd657656)
Solutions
- Pass decay as a fraction in [0,1], e.g. decay=0.9999
- Fix the value in the model config dict/YAML that feeds LitEma
- Clamp or validate the config value before constructing the model
Example fix
// before LitEma(model, decay=99.9) // after LitEma(model, decay=0.999)
Defensive patterns
Strategy: validation
Validate before calling
decay = config.get('decay', 0.9999)
if not isinstance(decay, (int, float)) or not (0.0 <= decay <= 1.0):
raise ValueError(f'decay must be in [0,1], got {decay}')
ema = LitEma(model, decay=float(decay)) Try / catch
try:
ema = LitEma(model, decay=cfg.model.decay)
except ValueError as e:
logging.error('bad EMA decay in config: %s', cfg.model.decay)
raise Prevention
- Store decay as a fraction (0.9999), never a percent, in configs
- Add a config-schema check that clamps/validates decay before model build
- Comment config values with their expected range
When it happens
Trigger: Instantiating LitEma(model, decay=...) with decay < 0.0 or decay > 1.0, e.g. passing a percentage like 99.9 instead of 0.999, or a typo such as 0.99999.9999.
Common situations: Config YAML files holding decay as 9999 or 0.9999e2; unit misinterpretation (percent vs fraction); loading an old config where decay was expressed differently.
Related errors
- unknown merge strategy {self.merge_strategy}
- Order {order} too high for step {i}
- unknown merge strategy {merge_strategy}
- rearranging not available for {len(in_shape)}-dimensional in
- Unknown loss type {self.loss_type}
AI-assisted analysis of Stability-AI/generative-models@e8cd657656 (2026-08-29).
Data as JSON: /api/errors/f5ccd3ceb49b2a1e.
Report an issue: GitHub.