huggingface/pytorch-image-models · critical · ValueError
ScheduledBatchSampler requires a non-empty sampler.
Error message
ScheduledBatchSampler requires a non-empty sampler.
What it means
ScheduledBatchSampler rejects samplers whose __len__() is <= 0 because there would be nothing to sample; raised right after the __len__ presence check during construction.
Source
Thrown at timm/data/scheduled_sampler.py:63
def __init__(
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.')
View on GitHub (pinned to 9a5261e31b)
Solutions
- Check len(sampler) / len(dataset) before constructing and fix the empty data source (correct path, split, or filter).
- For distributed runs, verify world_size divides or shards the data so each rank gets samples.
- Log dataset size early in your training script to catch empty loads immediately.
Example fix
assert len(sampler) > 0, f'empty sampler ({len(sampler)} items) — check dataset path/filters'
sched = ScheduledBatchSampler(sampler, batch_sizes=[128, 256]) Defensive patterns
Strategy: validation
Validate before calling
assert len(sampler) > 0, 'sampler/dataset is empty — check data loading'
Prevention
- Check len(dataset) > 0 right after loading data.
- Validate filters/subsets didn't remove all rows.
- In DDP, verify per-rank shard sizes.
When it happens
Trigger: Passing a sampler over an empty dataset (len(dataset)==0), a filtered/subset dataset with zero matching items, or a sampler initialized with n=0.
Common situations: Empty train split after a bad filter or path; Subset/DatasetFilter removing all rows; misconfigured distributed setup where the local rank got an empty shard.
Related errors
- ScheduledBatchSampler requires a sampler with a length.
- batch_sizes must contain at least one value.
- All scheduled batch sizes must be positive integers.
- num_batches must be a positive integer when specified.
- choice_schedule must be 'constant' or 'progressive'.
AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27).
Data as JSON: /api/errors/ab5ab8a101ef13f2.
Report an issue: GitHub.