{"record":{"id":"900301426e4d8c48","repo":"geekcomputers/Python","slug":"invalid-beta-parameter-at-index-0-betas-0","errorCode":null,"errorMessage":"Invalid beta parameter at index 0: {betas[0]}","messagePattern":"Invalid beta parameter at index 0: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ML/src/python/neuralforge/optim/optimizers.py","lineNumber":12,"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:","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/ML/src/python/neuralforge/optim/optimizers.py#L1-L30","documentation":"This ValueError is raised by the AdamW optimizer's constructor when the first momentum decay coefficient (betas[0]) falls outside the half-open range [0.0, 1.0). betas[0] controls the exponential decay rate for the first-moment (gradient mean) estimate. The check `0.0 <= betas[0] < 1.0` mirrors PyTorch's AdamW validation, rejecting values like 1.0 or negative numbers that would make the moving average degenerate or unstable.","triggerScenarios":"Constructing the optimizer with betas=(1.0, 0.999), a negative beta like (-0.1, 0.999), or a beta >= 1.0 such as betas=(1.2, 0.999). Also happens when configuration is loaded from a file/env var and parsed as float without bounds checking, or when betas is accidentally reversed/malformed (e.g., passing lr into betas via keyword mix-ups).","commonSituations":"Hyperparameter sweeps that include 1.0 as an endpoint, YAML/JSON configs where betas is typed as a string, porting configs between frameworks with different beta conventions, or programmatic tuning that explores values outside [0,1).","solutions":["Set betas[0] to the default 0.9 (e.g., betas=(0.9, 0.999))","Validate hyperparameter ranges before constructing the optimizer, clamping to [0.0, 1.0)","If loading config from file, ensure betas values are parsed as floats and sanity-checked","Check for swapped keyword arguments if the value looks like a learning rate"],"exampleFix":"// before\nopt = AdamW(params, lr=1e-3, betas=(1.0, 0.999))\n\n# after\nopt = AdamW(params, lr=1e-3, betas=(0.9, 0.999))","handlingStrategy":"validation","validationCode":"betas = (0.9, 0.999)\nassert all(0.0 <= b < 1.0 for b in betas), f'betas out of range: {betas}'\nopt = AdamW(params, betas=betas)","typeGuard":"def valid_betas(betas) -> bool:\n    return (isinstance(betas, (tuple, list)) and len(betas) == 2\n            and all(isinstance(b, (int, float)) and 0.0 <= b < 1.0 for b in betas))","tryCatchPattern":"try:\n    opt = AdamW(params, betas=betas)\nexcept ValueError as e:\n    raise ValueError(f'Optimizer config invalid: {e}; using defaults') from e","preventionTips":["Validate loaded hyperparameter configs against ranges before constructing optimizers","Clamp beta values to [0.0, 1.0) in hyperparameter search spaces","Use typed config schemas (pydantic/dataclass) with bounded fields for training configs"],"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"}