huggingface/pytorch-image-models · error · ValueError

Invalid beta parameter at index 0: {}

Error message

Invalid beta parameter at index 0: {}

What it means

Raised by timm's AdamW optimizer constructor when the first beta (beta1, the momentum decay coefficient) is outside the valid range [0.0, 1.0). Beta1 controls exponential decay of the first-moment estimate; values <0 or >=1 are mathematically invalid for the running-average update.

Source

Thrown at timm/optim/adamw.py:68

            self,
            params: ParamsT,
            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)

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Set beta1 to a value in [0.0, 1.0), typically 0.9
  2. Check your config/YAML for a typo in betas or the value bound to beta1
  3. If beta1 came from CLI args, verify the argparse type=float and default

Example fix

# before
opt = timm.optim.AdamW(model.parameters(), lr=1e-3, betas=(9.0, 0.999))
# 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=(beta1, beta2)) with beta1 < 0.0 or beta1 >= 1.0, e.g. betas=(1.0, 0.999) or betas=(-0.1, 0.999).

Common situations: Typo in a training config (e.g. 0.5 vs 5.0), swapping lr and beta values in argparse/YAML, or copying hyperparameters from a paper that used a different parameterization.

Related errors


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