tensorflow/models · error · ValueError
Wrong train dataset size
Error message
Wrong train dataset size {!r} What it means
Sanity check in the yt8m experiment helper add_trainer: num_train_examples must be positive because the trainer divides by it to compute steps per epoch; zero or negative would yield zero or negative train steps. Note the message interpolates the repr of experiment.task.train_data rather than the offending number — a formatting quirk that can mislead diagnosis. Reached from yt8m_experiment when a bad count is passed.
Solutions
- Pass a positive num_train_examples matching your dataset size (default YT8M_TRAIN_EXAMPLES)
- Do not explicitly set num_train_examples=0 in yt8m_experiment
- For custom datasets, count training records and pass that count
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at official/projects/yt8m/configs/yt8m.py:228 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/f57c5a460081889f.
Report an issue: GitHub.
Appendix: source
Thrown at official/projects/yt8m/configs/yt8m.py:228
default_factory=lambda: Evaluation( # pylint: disable=g-long-lambda
average_precision=AveragePrecisionConfig()
)
)
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',View on GitHub (pinned to e006f5f0d5)