{"record":{"id":"1660b3e434d4962a","repo":"geekcomputers/Python","slug":"invalid-beta-parameter-at-index-1-betas-1","errorCode":null,"errorMessage":"Invalid beta parameter at index 1: {betas[1]}","messagePattern":"Invalid beta parameter at index 1: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ML/src/python/neuralforge/optim/optimizers.py","lineNumber":14,"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                \n                grad = p.grad.data\n                if grad.is_sparse:\n                    raise RuntimeError('AdamW does not support sparse gradients')\n                ","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/ML/src/python/neuralforge/optim/optimizers.py#L1-L32","documentation":"This ValueError is raised by the AdamW optimizer's constructor when the second momentum decay coefficient (betas[1]) falls outside [0.0, 1.0). betas[1] controls the exponential decay rate for the second-moment (squared gradient) estimate used in the bias-corrected denominator. Values of 1.0 or greater would prevent the bias correction from ever stabilizing, and negative values are mathematically meaningless for a decay average.","triggerScenarios":"Constructing the optimizer with betas=(0.9, 1.0) or any second element >= 1.0 or < 0.0, e.g. betas=(0.9, -0.5). Common in schedules where beta2 is annealed toward 1.0 and the endpoint is hit exactly, or when a config value is mistyped.","commonSituations":"Beta2 annealing schedules (e.g., increasing beta2 during training) that reach 1.0, hyperparameter search boundaries including 1.0, config files with typos, or copy-paste from tutorials using nonstandard betas.","solutions":["Use the default betas=(0.9, 0.999) or clamp beta2 strictly below 1.0","If annealing beta2, cap the schedule at e.g. 0.9999 instead of 1.0","Validate loaded config values before passing them to the optimizer constructor"],"exampleFix":"# before\nopt = AdamW(params, betas=(0.9, beta2))  # beta2 may be 1.0\n\n# after\nbeta2 = min(beta2, 0.9999)\nopt = AdamW(params, betas=(0.9, beta2))","handlingStrategy":"validation","validationCode":"beta2 = min(float(beta2), 0.9999)\nassert 0.0 <= beta2 < 1.0\nopt = AdamW(params, betas=(0.9, beta2))","typeGuard":"def valid_beta2(b) -> bool:\n    return isinstance(b, (int, float)) and 0.0 <= float(b) < 1.0","tryCatchPattern":"try:\n    opt = AdamW(params, betas=(beta1, beta2))\nexcept ValueError:\n    beta2 = min(beta2, 0.9999)\n    opt = AdamW(params, betas=(beta1, beta2))","preventionTips":["Cap beta2 annealing schedules strictly below 1.0","Unit-test optimizer construction with the extremes of your sweep ranges","Parse config floats explicitly and range-check before use"],"tags":["python","optimizer","adamw","hyperparameter","validation"],"backgroundTag":"hyperparameter-out-of-range","analyzedSha":"40f4cd2652d75ef8e49d76e5c4d431d458712719","analyzedAt":"2026-08-27T11:12:20.313Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}