huggingface/pytorch-image-models · error · ValueError

Invalid beta parameter at index 1: {}

Error message

Invalid beta parameter at index 1: {}

What it means

Raised by timm's AdamW optimizer constructor when the second beta (beta2, the second-moment decay coefficient) is outside [0.0, 1.0). Beta2 controls the decay of the gradient-squared running average; values <0 or >=1 make the bias-corrected denominator degenerate.

Source

Thrown at timm/optim/adamw.py:70

            lr: float = 1e-3,
            betas: Tuple[float, float] = (0.9, 0.999),
            eps: float = 1e-8,
            weight_decay: float = 1e-2,
            amsgrad: bool = False,
            caution: bool = False,
            corrected_weight_decay: bool = False,
            maximize: bool = False,
            foreach: Optional[bool] = None,
            capturable: 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]))
        defaults = dict(
            lr=lr,
            betas=betas,
            eps=eps,
            weight_decay=weight_decay,
            amsgrad=amsgrad,
            caution=caution,
            corrected_weight_decay=corrected_weight_decay,
            foreach=foreach,
            maximize=maximize,
            capturable=capturable,
        )
        super(AdamWLegacy, self).__init__(params, defaults)

    def __setstate__(self, state):
        super(AdamWLegacy, self).__setstate__(state)
        for group in self.param_groups:
            group.setdefault('amsgrad', False)

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Set beta2 to a value in [0.0, 1.0), typically 0.999
  2. Check the betas tuple order is (beta1, beta2) in your config
  3. Validate hyperparameters from YAML/CLI before constructing the optimizer

Example fix

# before
opt = timm.optim.AdamW(model.parameters(), lr=1e-3, betas=(0.9, 1.0))
# after
opt = timm.optim.AdamW(model.parameters(), lr=1e-3, betas=(0.9, 0.999))
Defensive patterns

Strategy: validation

Validate before calling

assert len(betas) == 2 and all(0.0 <= b < 1.0 for b in betas), f'betas out of range: {betas}'

Type guard

def valid_adamw_betas(betas: tuple) -> bool:
    return len(betas) == 2 and all(isinstance(b, (int, float)) and 0.0 <= b < 1.0 for b in betas)

Prevention

When it happens

Trigger: Calling timm.optim.AdamW(params, betas=(0.9, beta2)) with beta2 < 0.0 or beta2 >= 1.0, e.g. betas=(0.9, 1.0) or betas=(0.9, 0.0 - 0.999 swapped into wrong slot).

Common situations: Config typo such as betas=(0.9, 0.99) mistyped as (0.9, 9.9), or accidentally passing a tuple like (beta2, beta1) in reversed order with an out-of-range beta1.

Related errors


AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27). Data as JSON: /api/errors/7789a19db6751802. Report an issue: GitHub.