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 Adan optimizer constructor when betas[1] (beta2, second-moment decay) is outside [0.0, 1.0). This coefficient weights the gradient-difference moment estimate and must be a valid decay factor.

Source

Thrown at timm/optim/adan.py:80

    def __init__(self,
            params,
            lr: float = 1e-3,
            betas: Tuple[float, float, float] = (0.98, 0.92, 0.99),
            eps: float = 1e-8,
            weight_decay: float = 0.0,
            no_prox: bool = False,
            caution: bool = False,
            foreach: Optional[bool] = None,
    ):
        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 <= betas[2] < 1.0:
            raise ValueError('Invalid beta parameter at index 2: {}'.format(betas[2]))

        defaults = dict(
            lr=lr,
            betas=betas,
            eps=eps,
            weight_decay=weight_decay,
            no_prox=no_prox,
            caution=caution,
            foreach=foreach,
        )
        super().__init__(params, defaults)

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

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Set beta2 in [0.0, 1.0), typically 0.92 for Adan
  2. Double-check the order and length of the betas tuple in your config

Example fix

# before
opt = timm.optim.Adan(model.parameters(), lr=1e-3, betas=(0.98, 1.2, 0.99))
# after
opt = timm.optim.Adan(model.parameters(), lr=1e-3, betas=(0.98, 0.92, 0.99))
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Prevention

When it happens

Trigger: Calling timm.optim.Adan(params, betas=(b1, b2, b3)) where b2 < 0.0 or b2 >= 1.0.

Common situations: Typo in the middle element of the three-element betas tuple, or values shifted by one position when editing a config.

Related errors


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