{"record":{"id":"3847f2e8f7043bc0","repo":"geekcomputers/Python","slug":"invalid-epsilon-value-eps","errorCode":null,"errorMessage":"Invalid epsilon value: {eps}","messagePattern":"Invalid epsilon value: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ML/src/python/neuralforge/optim/optimizers.py","lineNumber":10,"sourceCode":"import torch\nfrom torch.optim.optimizer import Optimizer\nimport math\n\nclass AdamW(Optimizer):\n    def __init__(self, params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, weight_decay=0.01, amsgrad=False):\n        if lr < 0.0:\n            raise ValueError(f\"Invalid learning rate: {lr}\")\n        if eps < 0.0:\n            raise ValueError(f\"Invalid epsilon value: {eps}\")\n        if not 0.0 <= betas[0] < 1.0:\n            raise ValueError(f\"Invalid beta parameter at index 0: {betas[0]}\")\n        if not 0.0 <= betas[1] < 1.0:\n            raise ValueError(f\"Invalid beta parameter at index 1: {betas[1]}\")\n        \n        defaults = dict(lr=lr, betas=betas, eps=eps, weight_decay=weight_decay, amsgrad=amsgrad)\n        super().__init__(params, defaults)\n    \n    def step(self, closure=None):\n        loss = None\n        if closure is not None:\n            loss = closure()\n        \n        for group in self.param_groups:\n            for p in group['params']:\n                if p.grad is None:\n                    continue\n                ","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/ML/src/python/neuralforge/optim/optimizers.py#L1-L28","documentation":"Raised by neuralforge's custom AdamW constructor when eps is negative. Like the lr check, it validates the denominator-stability constant up front; eps of exactly 0 is allowed, only negative values raise ValueError.","triggerScenarios":"Constructing AdamW(params, eps=-1e-8); loading eps from a config with a stray minus sign; hyperparameter search sampling eps from a symmetric range around zero.","commonSituations":"Typo'd configs; sweeps that sample eps uniformly in [-1e-8, 1e-6]; copying settings from another library with different sign conventions; checkpoint config deserialization mangling values.","solutions":["Log the eps value passed to the constructor","Sample eps in log-space or a strictly positive range: eps = abs(eps) or 10**uniform(-9, -7)","Fix the config typo","If eps=0 is intended (rare, risks division by zero), it passes validation but consider a small positive floor"],"exampleFix":"# before\nopt = AdamW(params, eps=-1e-8)  # ValueError\n\n# after\neps = trial.suggest_float('log_eps', -9, -7)\nopt = AdamW(params, eps=10 ** eps)","handlingStrategy":"validation","validationCode":"assert eps >= 0, f'eps must be >= 0, got {eps}'\nopt = AdamW(params, eps=eps)","typeGuard":"def is_valid_eps(eps) -> bool:\n    return isinstance(eps, (int, float)) and eps >= 0","tryCatchPattern":"try:\n    opt = AdamW(params, eps=eps)\nexcept ValueError as e:\n    if 'Invalid epsilon' in str(e):\n        opt = AdamW(params, eps=abs(eps) or 1e-8)\n    else:\n        raise","preventionTips":["Sample eps from positive log ranges (1e-9..1e-7)","Double-check minus signs when porting optimizer configs","Validate the full hyperparameter dict once before constructing the optimizer"],"tags":["optimizer","adamw","hyperparameter","validation","neuralforge"],"backgroundTag":"invalid-hyperparameter","analyzedSha":"40f4cd2652d75ef8e49d76e5c4d431d458712719","analyzedAt":"2026-08-27T11:12:20.313Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}