huggingface/pytorch-image-models · error · ValueError
Invalid beta parameter at index 1: {}
Error message
Invalid beta parameter at index 1: {} What it means
Mars requires beta2 (betas[1]) to satisfy 0 <= beta2 < 1, matching the second-moment EMA decay constraint shared with Adam-family optimizers.
Source
Thrown at timm/optim/mars.py:119
lr: float = 3e-3,
betas: Tuple[float, float] = (0.9, 0.99),
eps: float = 1e-8,
weight_decay: float = 0.,
gamma: float = 0.025,
mars_type: str = "adamw",
optimize_1d: bool = False,
lr_1d_factor: float = 1.0,
betas_1d: Optional[Tuple[float, float]] = None,
caution: bool = False
):
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]))
assert mars_type in ["adamw", "lion"], "MARS type not supported"
defaults = dict(
lr=lr,
betas=betas,
eps=eps,
weight_decay=weight_decay,
mars_type=mars_type,
gamma=gamma,
optimize_1d=optimize_1d,
lr_1d_factor=lr_1d_factor,
betas_1d=betas_1d or betas,
caution=caution,
)
super(Mars, self).__init__(params, defaults)
def __setstate__(self, state):
super(Mars, self).__setstate__(state)View on GitHub (pinned to 9a5261e31b)
Solutions
- Use beta2 in [0,1), e.g. 0.999
- Double-check the tuple order is (beta1, beta2)
- Fix the config source
Example fix
# before opt = Mars(model.parameters(), betas=(0.9, 1.0)) # after opt = Mars(model.parameters(), betas=(0.9, 0.999))
Defensive patterns
Strategy: validation
Validate before calling
b1, b2 = cfg.betas assert 0 <= b2 < 1, 'beta2 must be in [0,1)'
Type guard
def are_valid_betas(betas: tuple) -> bool:
return (len(betas) == 2 and all(isinstance(b, (int, float)) and 0 <= b < 1 for b in betas)) Prevention
- Use standard (0.9, 0.999) defaults
- Check betas_1d too when using optimize_1d
When it happens
Trigger: Calling Mars(params, betas=(0.9, 1.0)) or betas=(0.9, 1.5); beta2=1 is rejected.
Common situations: Using beta2=1.0 intending 'long memory'; typos in YAML/JSON config; ordering mixups.
Related errors
- Invalid beta parameter at index 0: {}
- Invalid learning rate: {}
- Invalid epsilon value: {}
- Momentum {momentum} must be in the range [0,1]
- Learning rate {lr} must be positive
AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27).
Data as JSON: /api/errors/3415a8c8b2cd69fa.
Report an issue: GitHub.