tensorflow/models · error · ValueError
`momentum` must be between [0, 1].
Error message
`momentum` must be between [0, 1].
What it means
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.
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]
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at official/projects/yolo/optimization/sgd_torch.py:107 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/eb2a913690368a9e.
Report an issue: GitHub.
Appendix: source
Thrown at official/projects/yolo/optimization/sgd_torch.py:107
# Create Hyper Params for each group of the LR
self._set_hyper("learning_rate", kwargs.get("lr", learning_rate))
self._set_hyper("bias_learning_rate", kwargs.get("lr", learning_rate))
self._set_hyper("other_learning_rate", kwargs.get("lr", learning_rate))
# SGD decay param
self._set_hyper("decay", self._initial_decay)
# Weight decay param
self._weight_decay = weight_decay != 0.0
self._set_hyper("weight_decay", weight_decay)
# Enable Momentum
self._momentum = False
if isinstance(momentum, tf.Tensor) or callable(momentum) or momentum > 0:
self._momentum = True
if isinstance(momentum, (int, float)) and (momentum < 0 or momentum > 1):
raise ValueError("`momentum` must be between [0, 1].")
self._set_hyper("momentum", momentum)
self._set_hyper("momentum_start", momentum_start)
self._set_hyper("warmup_steps", tf.cast(warmup_steps, tf.int32))
# Enable Nesterov Momentum
self.nesterov = nesterov
# weights, biases, other
self._weight_keys = weight_keys
self._bias_keys = bias_keys
self._variables_set = False
self._wset = set()
self._bset = set()
self._oset = set()
logging.info("Pytorch SGD simulation: ")
logging.info("Weight Decay: %f", weight_decay)
View on GitHub (pinned to e006f5f0d5)