{"record":{"id":"de96a82d06797fe2","repo":"tensorflow/models","slug":"batch-size-must-be-divisible-by-number-of-replicas-de96a8","errorCode":null,"errorMessage":"Batch size must be divisible by number of replicas : {}","messagePattern":"Batch size must be divisible by number of replicas : (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/nhnet/input_pipeline.py","lineNumber":224,"sourceCode":"                                                      params)\n  dataset = dataset.prefetch(tf.data.experimental.AUTOTUNE)\n  return dataset\n\n\ndef get_input_dataset(input_file_pattern,\n                      batch_size,\n                      params,\n                      is_training,\n                      strategy=None):\n  \"\"\"Returns input dataset from input file string.\"\"\"\n\n  # When using TPU pods, we need to clone dataset across\n  # workers and need to pass in function that returns the dataset rather\n  # than passing dataset instance itself.\n  use_dataset_fn = isinstance(strategy, tf.distribute.TPUStrategy)\n  if use_dataset_fn:\n    if batch_size % strategy.num_replicas_in_sync != 0:\n      raise ValueError(\n          \"Batch size must be divisible by number of replicas : {}\".format(\n              strategy.num_replicas_in_sync))\n\n    # As auto rebatching is not supported in\n    # `distribute_datasets_from_function()` API, which is\n    # required when cloning dataset to multiple workers in eager mode,\n    # we use per-replica batch size.\n    batch_size = int(batch_size / strategy.num_replicas_in_sync)\n\n  def _dataset_fn(ctx=None):\n    \"\"\"Returns tf.data.Dataset for distributed BERT pretraining.\"\"\"\n    input_files = []\n    for input_pattern in input_file_pattern.split(\",\"):\n      input_files.extend(tf.io.gfile.glob(input_pattern))\n\n    return create_dataset(\n        input_files,\n        batch_size,","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/nhnet/input_pipeline.py#L206-L242","documentation":"Error \"Batch size must be divisible by number of replicas : {}\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/nhnet/input_pipeline.py:224 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"}