tensorflow/models · error · ValueError

`eval_step` is required when `eval_input_fn ` is not none.

Error message

`eval_step` is required when `eval_input_fn ` is not none.

What it means

Consistency check in run_customized_training_loop: an eval_input_fn was supplied so evaluation will run, but eval_steps is None, leaving the loop without a step count for evaluation. Note the message's backtick typo ('eval_input_fn ') — the failing input is the eval_steps argument.

Solutions

  1. Set eval_steps to the number of evaluation batches (num_eval_examples // eval_batch_size)
  2. Drop eval_input_fn entirely if you do not want evaluation to run
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at official/legacy/bert/model_training_utils.py:256 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/1724d3700f7961c2. Report an issue: GitHub.

Appendix: source

Thrown at official/legacy/bert/model_training_utils.py:256

                 steps_per_loop)
  if steps_per_loop > steps_between_evals:
    logging.warning(
        'steps_per_loop: %d is specified to be greater than '
        ' steps_between_evals: %d, we will use steps_between_evals as'
        ' steps_per_loop.', steps_per_loop, steps_between_evals)
    steps_per_loop = steps_between_evals
  assert tf.executing_eagerly()

  if run_eagerly:
    if isinstance(
        strategy,
        (tf.distribute.TPUStrategy, tf.distribute.experimental.TPUStrategy)):
      raise ValueError(
          'TPUStrategy should not run eagerly as it heavily relies on graph'
          ' optimization for the distributed system.')

  if eval_input_fn and eval_steps is None:
    raise ValueError(
        '`eval_step` is required when `eval_input_fn ` is not none.')
  if metric_fn and not callable(metric_fn):
    raise ValueError(
        'if `metric_fn` is specified, metric_fn must be a callable.')

  total_training_steps = steps_per_epoch * epochs  # pyrefly: ignore[unsupported-operation]
  train_iterator = _get_input_iterator(train_input_fn, strategy)
  eval_loss_metric = tf_keras.metrics.Mean('training_loss', dtype=tf.float32)

  with distribute_utils.get_strategy_scope(strategy):
    # To correctly place the model weights on accelerators,
    # model and optimizer should be created in scope.
    model, sub_model = model_fn()  # pyrefly: ignore[not-callable]
    if not hasattr(model, 'optimizer'):
      raise ValueError('User should set optimizer attribute to model '
                       'inside `model_fn`.')
    if sub_model_export_name and sub_model is None:
      raise ValueError('sub_model_export_name is specified as %s, but '

View on GitHub (pinned to e006f5f0d5)