tensorflow/models · error · ValueError

The builder does not support a global batch size with more t

Error message

The builder does not support a global batch size with more than one replica. Got {} replicas. Please set a `per_replica_batch_size` and enable `use_per_replica_batch_size=True`.

What it means

Error "The builder does not support a global batch size with more than one replica. Got {} replicas. Please set a `per_replica_batch_size` and enable `use_per_replica_batch_size=True`." thrown in tensorflow/models.

Source

Thrown at official/legacy/image_classification/dataset_factory.py:443

    if self.config.cache:
      dataset = dataset.cache()

    if self.is_training:
      dataset = dataset.shuffle(self.config.shuffle_buffer_size)
      dataset = dataset.repeat()

    # Parse, pre-process, and batch the data in parallel
    if self.config.builder == 'records':
      preprocess = self.parse_record
    else:
      preprocess = self.preprocess
    dataset = dataset.map(
        preprocess, num_parallel_calls=tf.data.experimental.AUTOTUNE)

    if self.input_context and self.config.num_devices > 1:
      if not self.config.use_per_replica_batch_size:
        raise ValueError(
            'The builder does not support a global batch size with more than '
            'one replica. Got {} replicas. Please set a '
            '`per_replica_batch_size` and enable '
            '`use_per_replica_batch_size=True`.'.format(
                self.config.num_devices))

      # The batch size of the dataset will be multiplied by the number of
      # replicas automatically when strategy.distribute_datasets_from_function
      # is called, so we use local batch size here.
      dataset = dataset.batch(
          self.local_batch_size, drop_remainder=self.is_training)
    else:
      dataset = dataset.batch(
          self.global_batch_size, drop_remainder=self.is_training)

    # Prefetch overlaps in-feed with training
    dataset = dataset.prefetch(tf.data.experimental.AUTOTUNE)

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/legacy/image_classification/dataset_factory.py:443 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/3e6f76982b86b2e6. Report an issue: GitHub.