tensorflow/models · error · ValueError
Pre-batch ({}) size is not equal to batch size ({})
Error message
Pre-batch ({}) size is not equal to batch size ({}) What it means
Error "Pre-batch ({}) size is not equal to batch size ({})" thrown in tensorflow/models.
Source
Thrown at official/recommendation/ncf_input_pipeline.py:35
import functools
# pylint: disable=g-bad-import-order
import tensorflow as tf, tf_keras
# pylint: enable=g-bad-import-order
from official.recommendation import constants as rconst
from official.recommendation import data_pipeline
from official.recommendation import movielens
def create_dataset_from_tf_record_files(input_file_pattern,
pre_batch_size,
batch_size,
is_training=True,
rebatch=False):
"""Creates dataset from (tf)records files for training/evaluation."""
if pre_batch_size != batch_size:
raise ValueError("Pre-batch ({}) size is not equal to batch "
"size ({})".format(pre_batch_size, batch_size))
files = tf.data.Dataset.list_files(input_file_pattern, shuffle=is_training)
dataset = files.interleave(
tf.data.TFRecordDataset,
cycle_length=16,
num_parallel_calls=tf.data.experimental.AUTOTUNE)
decode_fn = functools.partial(
data_pipeline.DatasetManager.deserialize,
batch_size=pre_batch_size,
is_training=is_training)
dataset = dataset.map(
decode_fn, num_parallel_calls=tf.data.experimental.AUTOTUNE)
if rebatch:
# A workaround for TPU Pod evaluation dataset.
# TODO (b/162341937) remove once it's fixed.View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/recommendation/ncf_input_pipeline.py:35 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/427c141c2c5e3e8b.
Report an issue: GitHub.