{"record":{"id":"427c141c2c5e3e8b","repo":"tensorflow/models","slug":"pre-batch-size-is-not-equal-to-batch-size","errorCode":null,"errorMessage":"Pre-batch ({}) size is not equal to batch size ({})","messagePattern":"Pre-batch \\((.+?)\\) size is not equal to batch size \\((.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/recommendation/ncf_input_pipeline.py","lineNumber":35,"sourceCode":"import functools\n\n# pylint: disable=g-bad-import-order\nimport tensorflow as tf, tf_keras\n# pylint: enable=g-bad-import-order\n\nfrom official.recommendation import constants as rconst\nfrom official.recommendation import data_pipeline\nfrom official.recommendation import movielens\n\n\ndef create_dataset_from_tf_record_files(input_file_pattern,\n                                        pre_batch_size,\n                                        batch_size,\n                                        is_training=True,\n                                        rebatch=False):\n  \"\"\"Creates dataset from (tf)records files for training/evaluation.\"\"\"\n  if pre_batch_size != batch_size:\n    raise ValueError(\"Pre-batch ({}) size is not equal to batch \"\n                     \"size ({})\".format(pre_batch_size, batch_size))\n\n  files = tf.data.Dataset.list_files(input_file_pattern, shuffle=is_training)\n\n  dataset = files.interleave(\n      tf.data.TFRecordDataset,\n      cycle_length=16,\n      num_parallel_calls=tf.data.experimental.AUTOTUNE)\n  decode_fn = functools.partial(\n      data_pipeline.DatasetManager.deserialize,\n      batch_size=pre_batch_size,\n      is_training=is_training)\n  dataset = dataset.map(\n      decode_fn, num_parallel_calls=tf.data.experimental.AUTOTUNE)\n\n  if rebatch:\n    # A workaround for TPU Pod evaluation dataset.\n    # TODO (b/162341937) remove once it's fixed.","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/recommendation/ncf_input_pipeline.py#L17-L53","documentation":"Error \"Pre-batch ({}) size is not equal to batch size ({})\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/recommendation/ncf_input_pipeline.py:35 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"}