huggingface/pytorch-image-models · error · ValueError

Invalid epsilon value: {}

Error message

Invalid epsilon value: {}

What it means

Mars validates that the epsilon hyperparameter is non-negative; a negative eps breaks the denominator in the Adam-style update and is rejected at construction.

Source

Thrown at timm/optim/mars.py:115

    """
    def __init__(
            self,
            params: ParamsT,
            lr: float = 3e-3,
            betas: Tuple[float, float] = (0.9, 0.99),
            eps: float = 1e-8,
            weight_decay: float = 0.,
            gamma: float = 0.025,
            mars_type: str = "adamw",
            optimize_1d: bool = False,
            lr_1d_factor: float = 1.0,
            betas_1d: Optional[Tuple[float, float]] = None,
            caution: 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]))
        assert mars_type in ["adamw", "lion"], "MARS type not supported"

        defaults = dict(
            lr=lr,
            betas=betas,
            eps=eps,
            weight_decay=weight_decay,
            mars_type=mars_type,
            gamma=gamma,
            optimize_1d=optimize_1d,
            lr_1d_factor=lr_1d_factor,
            betas_1d=betas_1d or betas,
            caution=caution,
        )

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Use a positive eps (default 1e-8 style values)
  2. Correct the source of the negative eps

Example fix

# before
opt = Mars(model.parameters(), eps=-1e-8)
# after
opt = Mars(model.parameters(), eps=1e-8)
Defensive patterns

Strategy: validation

Validate before calling

assert cfg.eps >= 0, 'eps must be non-negative'

Type guard

def is_valid_eps(e: float) -> bool:
    return isinstance(e, (int, float)) and e >= 0

Prevention

When it happens

Trigger: Constructing Mars(params, eps=-1e-8) or otherwise passing a negative epsilon.

Common situations: Sign typos; eps derived from arithmetic that can go negative in sweeps.

Related errors


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