tensorflow/models · error · ValueError

steps_per_loop should be positive integer.

Error message

steps_per_loop should be positive integer.

What it means

Argument guard in _steps_to_run: the steps_per_loop (iterations_per_loop) parameter is zero or negative, so the number of steps to execute per loop iteration cannot be computed. The input at fault is the iterations_per_loop/ steps_per_loop training config value.

Solutions

  1. Set iterations_per_loop (steps_per_loop) to a positive integer such as 125 or 1000
  2. Validate the value early in the train config instead of relying on this runtime check
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at official/legacy/detection/executor/distributed_executor.py:53 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/eefddddd139f7781. Report an issue: GitHub.

Appendix: source

Thrown at official/legacy/detection/executor/distributed_executor.py:53

FLAGS = flags.FLAGS

strategy_flags_dict = hyperparams_flags.strategy_flags_dict
hparam_flags_dict = hyperparams_flags.hparam_flags_dict


def _save_checkpoint(checkpoint, model_dir, checkpoint_prefix):
  """Saves model to model_dir with provided checkpoint prefix."""

  checkpoint_path = os.path.join(model_dir, checkpoint_prefix)
  saved_path = checkpoint.save(checkpoint_path)
  logging.info('Saving model as TF checkpoint: %s', saved_path)


def _steps_to_run(current_step, total_steps, steps_per_loop):
  """Calculates steps to run on device."""
  if steps_per_loop <= 0:
    raise ValueError('steps_per_loop should be positive integer.')
  return min(total_steps - current_step, steps_per_loop)


def _no_metric():
  return None


def metrics_as_dict(metric):
  """Puts input metric(s) into a list.

  Args:
    metric: metric(s) to be put into the list. `metric` could be an object, a
      list, or a dict of tf_keras.metrics.Metric or has the `required_method`.

  Returns:
    A dictionary of valid metrics.
  """
  if isinstance(metric, tf_keras.metrics.Metric):

View on GitHub (pinned to e006f5f0d5)