tensorflow/models · error · ValueError

global_batch_size {} is not a multiple of num_replicas {}

Error message

global_batch_size {} is not a multiple of num_replicas {}

What it means

Error "global_batch_size {} is not a multiple of num_replicas {}" thrown in tensorflow/models.

Source

Thrown at official/projects/pointpillars/tasks/pointpillars.py:51


def pick_dataset_fn(file_type: str) -> Any:
  if file_type == 'tfrecord':
    return tf.data.TFRecordDataset
  if file_type == 'tfrecord_compressed':
    return functools.partial(tf.data.TFRecordDataset, compression_type='GZIP')
  raise ValueError('Unrecognized file_type: {}'.format(file_type))


def get_batch_size_per_replica(global_batch_size: int) -> int:
  """Get batch size per accelerator replica."""
  num_replicas = tf.distribute.get_strategy().num_replicas_in_sync
  if global_batch_size < num_replicas:
    logging.warning('Global batch size is smaller than num replicas. '
                    'Set batch size per replica to 1.')
    return 1
  if global_batch_size % num_replicas != 0:
    raise ValueError(
        'global_batch_size {} is not a multiple of num_replicas {}'
        .format(global_batch_size, num_replicas))
  batch_size = int(global_batch_size / num_replicas)
  return batch_size


@task_factory.register_task_cls(cfg.PointPillarsTask)
class PointPillarsTask(base_task.Task):
  """A single-replica view of training procedure."""

  def __init__(self,
               params: cfg.PointPillarsTask,
               logging_dir: Optional[str] = None,
               name: Optional[str] = None):
    super().__init__(params, logging_dir, name)
    self._model = None
    self._attribute_heads = self.task_config.model.head.attribute_heads

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/projects/pointpillars/tasks/pointpillars.py:51 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/e3671d61d8b5d42d. Report an issue: GitHub.