{"record":{"id":"3e6f76982b86b2e6","repo":"tensorflow/models","slug":"the-builder-does-not-support-a-global-batch-size-w","errorCode":null,"errorMessage":"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`.","messagePattern":"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`\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/legacy/image_classification/dataset_factory.py","lineNumber":443,"sourceCode":"\n    if self.config.cache:\n      dataset = dataset.cache()\n\n    if self.is_training:\n      dataset = dataset.shuffle(self.config.shuffle_buffer_size)\n      dataset = dataset.repeat()\n\n    # Parse, pre-process, and batch the data in parallel\n    if self.config.builder == 'records':\n      preprocess = self.parse_record\n    else:\n      preprocess = self.preprocess\n    dataset = dataset.map(\n        preprocess, num_parallel_calls=tf.data.experimental.AUTOTUNE)\n\n    if self.input_context and self.config.num_devices > 1:\n      if not self.config.use_per_replica_batch_size:\n        raise ValueError(\n            'The builder does not support a global batch size with more than '\n            'one replica. Got {} replicas. Please set a '\n            '`per_replica_batch_size` and enable '\n            '`use_per_replica_batch_size=True`.'.format(\n                self.config.num_devices))\n\n      # The batch size of the dataset will be multiplied by the number of\n      # replicas automatically when strategy.distribute_datasets_from_function\n      # is called, so we use local batch size here.\n      dataset = dataset.batch(\n          self.local_batch_size, drop_remainder=self.is_training)\n    else:\n      dataset = dataset.batch(\n          self.global_batch_size, drop_remainder=self.is_training)\n\n    # Prefetch overlaps in-feed with training\n    dataset = dataset.prefetch(tf.data.experimental.AUTOTUNE)\n","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/legacy/image_classification/dataset_factory.py#L425-L461","documentation":"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.","triggerScenarios":"Thrown at official/legacy/image_classification/dataset_factory.py:443 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}