{"record":{"id":"ccb59de00631ae2c","repo":"tensorflow/models","slug":"batch-size-must-be-divisible-by-number-of-replicas-ccb59d","errorCode":null,"errorMessage":"Batch size must be divisible by number of replicas : {}","messagePattern":"Batch size must be divisible by number of replicas : (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/legacy/xlnet/data_utils.py","lineNumber":181,"sourceCode":"  input_data = input_fn()\n  if callable(input_data):\n    iterator = iter(strategy.distribute_datasets_from_function(input_data))\n  else:\n    iterator = iter(strategy.experimental_distribute_dataset(input_data))\n  return iterator\n\n\ndef get_classification_input_data(batch_size, seq_len, strategy, is_training,\n                                  file_path):\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    del ctx\n\n    train_dataset = create_classification_dataset(\n        file_path=file_path,\n        seq_length=seq_len,\n        batch_size=batch_size,\n        is_training=is_training)\n    return train_dataset","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/legacy/xlnet/data_utils.py#L163-L199","documentation":"Error \"Batch size must be divisible by number of replicas : {}\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/legacy/xlnet/data_utils.py:181 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"}