huggingface/pytorch-image-models · error · ValueError
batch_sizes must contain at least one value.
Error message
batch_sizes must contain at least one value.
What it means
batch_sizes (the list of batch sizes the scheduler alternates/schedules among) was empty, leaving the sampler with no valid batch size to emit; caught during constructor validation.
Source
Thrown at timm/data/scheduled_sampler.py:65
self,
sampler: Sampler,
batch_sizes: Sequence[int],
choice_weights: Optional[Sequence[float]] = None,
seed: int = 0,
drop_last: bool = True,
shuffle_schedule: bool = True,
num_batches: Optional[int] = None,
choice_schedule: str = 'constant',
schedule_epochs: Optional[int] = None,
schedule_spread: float = 0.65,
schedule_random_mix: float = 0.1,
) -> None:
if not hasattr(sampler, '__len__'):
raise TypeError('ScheduledBatchSampler requires a sampler with a length.')
if len(sampler) <= 0:
raise ValueError('ScheduledBatchSampler requires a non-empty sampler.')
if not batch_sizes:
raise ValueError('batch_sizes must contain at least one value.')
if any(int(batch_size) != batch_size or batch_size <= 0 for batch_size in batch_sizes):
raise ValueError('All scheduled batch sizes must be positive integers.')
if num_batches is not None and (int(num_batches) != num_batches or num_batches <= 0):
raise ValueError('num_batches must be a positive integer when specified.')
if choice_schedule not in ('constant', 'progressive'):
raise ValueError("choice_schedule must be 'constant' or 'progressive'.")
if choice_schedule == 'progressive':
if len(batch_sizes) < 2:
raise ValueError('A progressive schedule requires at least two choices.')
if schedule_epochs is None or int(schedule_epochs) != schedule_epochs or schedule_epochs <= 0:
raise ValueError('schedule_epochs must be a positive integer for a progressive schedule.')
if schedule_spread < 0:
raise ValueError('schedule_spread must be non-negative.')
if not 0 <= schedule_random_mix <= 1:
raise ValueError('schedule_random_mix must be between 0 and 1.')
self.sampler = sampler
self.batch_sizes = tuple(int(batch_size) for batch_size in batch_sizes)View on GitHub (pinned to 9a5261e31b)
Solutions
- Provide at least one positive batch size, e.g. batch_sizes=[256].
- Fix the config loader to default to a sensible single-size list like [batch_size].
Example fix
# before ScheduledBatchSampler(sampler, batch_sizes=[]) # after ScheduledBatchSampler(sampler, batch_sizes=[256])
Defensive patterns
Strategy: validation
Validate before calling
batch_sizes = batch_sizes or [config['batch_size']] assert len(batch_sizes) >= 1
Prevention
- Default empty config lists to a sensible single-value list.
- Schema-validate training configs before constructing samplers.
When it happens
Trigger: Calling ScheduledBatchSampler(sampler, batch_sizes=[]) or batch_sizes=None after a config layer turned a missing value into an empty list.
Common situations: YAML/JSON config where the batch_sizes key is empty or omitted and defaults to []; programmatically generated lists that end up empty for small models.
Related errors
- All scheduled batch sizes must be positive integers.
- No full scheduled batch fits the sampler; reduce the batch s
- ScheduledBatchSampler requires a sampler with a length.
- ScheduledBatchSampler requires a non-empty sampler.
- num_batches must be a positive integer when specified.
AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27).
Data as JSON: /api/errors/6c27ea4c75a96c31.
Report an issue: GitHub.