tensorflow/models · error · ValueError
Evaluation batch size must be divisible by {} times {}
Error message
Evaluation batch size must be divisible by {} times {} What it means
Error "Evaluation batch size must be divisible by {} times {}" thrown in tensorflow/models.
Source
Thrown at official/recommendation/ncf_input_pipeline.py:146
strategy: Distribution strategy used for distributed training. If specified,
used to assert that evaluation batch size is correctly a multiple of total
number of devices used.
Returns:
(training dataset, evaluation dataset, train steps per epoch,
eval steps per epoch)
Raises:
ValueError: If data is being generated online for when using TPU's.
"""
# NCF evaluation metric calculation logic assumes that evaluation data
# sample size are in multiples of (1 + number of negative samples in
# evaluation) for each device. As so, evaluation batch size must be a
# multiple of (number of replicas * (1 + number of negative samples)).
num_devices = strategy.num_replicas_in_sync if strategy else 1
if (params["eval_batch_size"] % (num_devices *
(1 + rconst.NUM_EVAL_NEGATIVES))):
raise ValueError("Evaluation batch size must be divisible by {} "
"times {}".format(num_devices,
(1 + rconst.NUM_EVAL_NEGATIVES)))
if params["train_dataset_path"]:
assert params["eval_dataset_path"]
train_dataset = create_dataset_from_tf_record_files(
params["train_dataset_path"],
input_meta_data["train_prebatch_size"], # pyrefly: ignore[unsupported-operation]
params["batch_size"],
is_training=True,
rebatch=False)
# Re-batch evaluation dataset for TPU Pods.
# TODO (b/162341937) remove once it's fixed.
eval_rebatch = (params["use_tpu"] and strategy.num_replicas_in_sync > 8) # pyrefly: ignore[missing-attribute]
eval_dataset = create_dataset_from_tf_record_files(
params["eval_dataset_path"],View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/recommendation/ncf_input_pipeline.py:146 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/33f5f90908cf2f43.
Report an issue: GitHub.