huggingface/pytorch-image-models · error · ValueError

Invalid beta parameter at index 2: {}

Error message

Invalid beta parameter at index 2: {}

What it means

Raised by timm's Adan optimizer constructor when betas[2] (beta3, third decay coefficient) is outside [0.0, 1.0). This coefficient controls the third moment update in Adan's Nesterov-corrected scheme.

Source

Thrown at timm/optim/adan.py:82

            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)
            group.setdefault('caution', False)

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Set beta3 in [0.0, 1.0), typically 0.99 for Adan
  2. Validate the whole betas tuple with all(0.0 <= b < 1.0 for b in betas) before constructing

Example fix

# before
opt = timm.optim.Adan(model.parameters(), lr=1e-3, betas=(0.98, 0.92, 1.0))
# 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 b3 < 0.0 or b3 >= 1.0, e.g. betas=(0.98, 0.92, 1.0).

Common situations: Users porting Adam betas=(0.9, 0.999) and appending a third value like 1.0 or 0.999*10 by typo; misconfigured sweep overriding only the last beta.

Related errors


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