huggingface/pytorch-image-models · error · ValueError

Invalid beta parameter at index 0: {betas[0]}

Error message

Invalid beta parameter at index 0: {betas[0]}

What it means

NAdamW constructor validation: betas[0] (beta1, momentum decay) must satisfy 0.0 <= beta1 < 1.0. Values outside this range make the exponential moving average unstable.

Source

Thrown at timm/optim/nadamw.py:60

    def __init__(
            self,
            params: ParamsT,
            lr: float = 1e-3,
            betas: Tuple[float, float] = (0.9, 0.999),
            eps: float = 1e-8,
            weight_decay: float = 1e-2,
            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(f'Invalid learning rate: {lr}')
        if not 0.0 <= eps:
            raise ValueError(f'Invalid epsilon value: {eps}')
        if not 0.0 <= betas[0] < 1.0:
            raise ValueError(f'Invalid beta parameter at index 0: {betas[0]}')
        if not 0.0 <= betas[1] < 1.0:
            raise ValueError(f'Invalid beta parameter at index 1: {betas[1]}')
        if not 0.0 <= weight_decay:
            raise ValueError(f'Invalid weight_decay value: {weight_decay}')
        defaults = dict(
            lr=lr,
            betas=betas,
            eps=eps,
            weight_decay=weight_decay,
            caution=caution,
            corrected_weight_decay=corrected_weight_decay,
            foreach=foreach,
            maximize=maximize,
            capturable=capturable,
        )
        super().__init__(params, defaults)

    def __setstate__(self, state):

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Use standard betas like (0.9, 0.999)
  2. Restrict hyperparameter search ranges to [0, 1) for beta1

Example fix

# before
opt = NAdamW(model.parameters(), betas=(1.0, 0.999))

# after
opt = NAdamW(model.parameters(), betas=(0.9, 0.999))
Defensive patterns

Strategy: validation

Validate before calling

assert 0.0 <= betas[0] < 1.0

Prevention

When it happens

Trigger: Calling timm.optim.NAdamW(params, betas=(1.0, 0.999)) or betas=(-0.1, 0.999).

Common situations: Copying betas from another optimizer with different conventions, sweep search spaces that include 1.0, or swapping beta1/beta2 order.

Related errors


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