{"record":{"id":"eb2a913690368a9e","repo":"tensorflow/models","slug":"momentum-must-be-between-0-1","errorCode":null,"errorMessage":"`momentum` must be between [0, 1].","messagePattern":"`momentum` must be between \\[0, 1\\]\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/yolo/optimization/sgd_torch.py","lineNumber":107,"sourceCode":"\n    # Create Hyper Params for each group of the LR\n    self._set_hyper(\"learning_rate\", kwargs.get(\"lr\", learning_rate))\n    self._set_hyper(\"bias_learning_rate\", kwargs.get(\"lr\", learning_rate))\n    self._set_hyper(\"other_learning_rate\", kwargs.get(\"lr\", learning_rate))\n\n    # SGD decay param\n    self._set_hyper(\"decay\", self._initial_decay)\n\n    # Weight decay param\n    self._weight_decay = weight_decay != 0.0\n    self._set_hyper(\"weight_decay\", weight_decay)\n\n    # Enable Momentum\n    self._momentum = False\n    if isinstance(momentum, tf.Tensor) or callable(momentum) or momentum > 0:\n      self._momentum = True\n    if isinstance(momentum, (int, float)) and (momentum < 0 or momentum > 1):\n      raise ValueError(\"`momentum` must be between [0, 1].\")\n    self._set_hyper(\"momentum\", momentum)\n    self._set_hyper(\"momentum_start\", momentum_start)\n    self._set_hyper(\"warmup_steps\", tf.cast(warmup_steps, tf.int32))\n\n    # Enable Nesterov Momentum\n    self.nesterov = nesterov\n\n    # weights, biases, other\n    self._weight_keys = weight_keys\n    self._bias_keys = bias_keys\n    self._variables_set = False\n    self._wset = set()\n    self._bset = set()\n    self._oset = set()\n\n    logging.info(\"Pytorch SGD simulation: \")\n    logging.info(\"Weight Decay: %f\", weight_decay)\n","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/yolo/optimization/sgd_torch.py#L89-L125","documentation":"Range check in the SGD constructor: the momentum hyper-parameter must be within [0, 1]. Values outside that range (negative or > 1) produce diverging or nonsensical velocity updates in the momentum accumulation, so __init__ rejects them immediately. Fires when momentum comes from a config typo (e.g. 10 instead of 0.10) or a schedule/callable resolving to an out-of-range scalar.","triggerScenarios":"Thrown at official/projects/yolo/optimization/sgd_torch.py:107 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set momentum to a value in [0, 1] — typical choices are 0.9 or 0.99","Check the YAML/flags for decimal errors (10 vs 0.10)","If momentum is a schedule or callable, verify it never yields values outside [0, 1]"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}