huggingface/pytorch-image-models · error · ValueError

choice_schedule must be 'constant' or 'progressive'.

Error message

choice_schedule must be 'constant' or 'progressive'.

What it means

choice_schedule controls how batch-size choices are selected over epochs and only accepts 'constant' or 'progressive'; any other string hits this ValueError during constructor validation.

Source

Thrown at timm/data/scheduled_sampler.py:71

            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)
        self.choice_weights = self._normalize_choice_weights(choice_weights)
        self._active_choices = tuple(
            choice_index
            for choice_index, choice_weight in enumerate(self.choice_weights)
            if choice_weight > 0
        )

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Use exactly 'constant' or 'progressive' (lowercase).
  2. If you wanted a gradually increasing batch size, 'progressive' is the intended mode — also set schedule_epochs and >=2 batch_sizes.

Example fix

# before
ScheduledBatchSampler(s, batch_sizes=[128,256], choice_schedule='linear')

# after
ScheduledBatchSampler(s, batch_sizes=[128,256], choice_schedule='progressive', schedule_epochs=10)
Defensive patterns

Strategy: validation

Validate before calling

assert choice_schedule in ('constant', 'progressive'), f'bad schedule: {choice_schedule}'

Type guard

def is_valid_schedule(v: str) -> bool:
    return isinstance(v, str) and v in ('constant', 'progressive')

Prevention

When it happens

Trigger: choice_schedule='linear', 'cosine', 'Progressive' (capitalized), or a typo like 'progresive'.

Common situations: Copy-pasting schedule names from LR-scheduler configs (cosine/step) into the sampler config; case or spelling mistakes from hand-edited YAML.

Related errors


AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27). Data as JSON: /api/errors/d3e0bb923d72d63f. Report an issue: GitHub.