huggingface/pytorch-image-models · error · ValueError

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

Error message

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

What it means

Raised by ADOPT's constructor when betas[1] (beta2, second-moment decay) is outside [0.0, 1.0).

Source

Thrown at timm/optim/adopt.py:95

            maximize: bool = False,
            capturable: bool = False,
            differentiable: bool = False,
    ):
        if isinstance(lr, Tensor):
            if foreach and not capturable:
                raise ValueError(
                    "lr as a Tensor is not supported for capturable=False and foreach=True"
                )
            if lr.numel() != 1:
                raise ValueError("Tensor lr must be 1-element")
        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,
            clip_exp=clip_exp,
            decoupled=decoupled,
            corrected_weight_decay=corrected_weight_decay,
            caution=caution,
            maximize=maximize,
            foreach=foreach,
            capturable=capturable,
            differentiable=differentiable,
        )
        super().__init__(params, defaults)

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Set beta2 in [0.0, 1.0), typically 0.99 for ADOPT
  2. Check the betas values in your config file

Example fix

# before
opt = timm.optim.Adopt(model.parameters(), lr=1e-3, betas=(0.9, 1.0))
# after
opt = timm.optim.Adopt(model.parameters(), lr=1e-3, betas=(0.9, 0.99))
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_adopt_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: Constructing timm.optim.Adopt(params, betas=(b1, b2)) with b2 < 0.0 or b2 >= 1.0, e.g. betas=(0.9, 1.0).

Common situations: Typo in the second beta, or accidentally swapping in a value like 0.999*10 from a misconfigured sweep.

Related errors


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