tensorflow/models · error · ValueError
Wrong validation dataset size
Error message
Wrong validation dataset size {!r} What it means
Companion check in add_trainer: num_val_examples is zero or negative. Validation steps per epoch are derived from this count; a non-positive value would skip or corrupt evaluation scheduling. Like the train-side check, the message interpolates experiment.task.train_data's repr instead of the number itself, which is misleading when reading the error.
Solutions
- Pass a positive num_val_examples (default YT8M_VAL_EXAMPLES)
- Count validation records for custom datasets and pass that number
- Check the yt8m_experiment caller for arguments passed in the wrong positional order
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at official/projects/yt8m/configs/yt8m.py:231 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/a171985d86efbd22.
Report an issue: GitHub.
Appendix: source
Thrown at official/projects/yt8m/configs/yt8m.py:231
)
gradient_clip_norm: float = 1.0
def add_trainer(
experiment: cfg.ExperimentConfig,
train_batch_size: int,
eval_batch_size: int,
learning_rate: float = 0.0001,
train_epochs: int = 50,
num_train_examples: int = YT8M_TRAIN_EXAMPLES,
num_val_examples: int = YT8M_VAL_EXAMPLES,
) -> cfg.ExperimentConfig:
"""Adds and config a trainer to the experiment config."""
if num_train_examples <= 0:
raise ValueError('Wrong train dataset size {!r}'.format(
experiment.task.train_data))
if num_val_examples <= 0:
raise ValueError('Wrong validation dataset size {!r}'.format(
experiment.task.validation_data))
experiment.task.train_data.global_batch_size = train_batch_size
experiment.task.validation_data.global_batch_size = eval_batch_size
steps_per_epoch = num_train_examples // train_batch_size
steps_per_loop = 500
experiment.trainer = cfg.TrainerConfig(
steps_per_loop=steps_per_loop,
summary_interval=steps_per_loop,
checkpoint_interval=steps_per_loop,
train_steps=train_epochs * steps_per_epoch,
validation_steps=num_val_examples // eval_batch_size,
validation_interval=steps_per_loop,
optimizer_config=optimization.OptimizationConfig({
'optimizer': {
'type': 'adam',
'adam': {}
},
'learning_rate': {View on GitHub (pinned to e006f5f0d5)