tensorflow/models · error · ValueError

producer batch size ( ) differs from params batch size ( )

Error message

producer batch size ({}) differs from params batch size ({})

What it means

Consistency check inside the input_fn closure created by make_input_fn: the batch size recorded when the data was produced differs from the batch size the Estimator passed in params, which would silently mis-shape the batches.

Solutions

  1. Align the producer's batch_size with params['batch_size'] (train) or eval_batch_size (eval) when constructing the data pipeline
  2. Rebuild/re-serialize the dataset files with the same batch size used at run time
  3. Verify you are not passing a per-replica vs global batch size mismatch under distribution strategy
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at official/recommendation/data_pipeline.py:349 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/0db62f3d90e7ab85. Report an issue: GitHub.

Appendix: source

Thrown at official/recommendation/data_pipeline.py:349

          self.data_generator, epochs_between_evals=epochs_between_evals)
      dataset = tf.data.Dataset.from_generator(
          generator=data_generator, output_types=types, output_shapes=shapes)

    return dataset.prefetch(16)

  def make_input_fn(self, batch_size):
    """Create an input_fn which checks for batch size consistency."""

    def input_fn(params):
      """Returns batches for training."""

      # Estimator passes batch_size during training and eval_batch_size during
      # eval.
      param_batch_size = (
          params["batch_size"] if self._is_training else
          params.get("eval_batch_size") or params["batch_size"])
      if batch_size != param_batch_size:
        raise ValueError("producer batch size ({}) differs from params batch "
                         "size ({})".format(batch_size, param_batch_size))

      epochs_between_evals = (
          params.get("epochs_between_evals", 1) if self._is_training else 1)
      return self.get_dataset(
          batch_size=batch_size, epochs_between_evals=epochs_between_evals)

    return input_fn


class BaseDataConstructor(threading.Thread):
  """Data constructor base class.

  This class manages the control flow for constructing data. It is not meant
  to be used directly, but instead subclasses should implement the following
  two methods:

    self.construct_lookup_variables

View on GitHub (pinned to e006f5f0d5)