{"record":{"id":"fb65660962a96ee9","repo":"huggingface/pytorch-image-models","slug":"num-batches-must-be-a-positive-integer-when-specif","errorCode":null,"errorMessage":"num_batches must be a positive integer when specified.","messagePattern":"num_batches must be a positive integer when specified\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"timm/data/scheduled_sampler.py","lineNumber":69,"sourceCode":"            seed: int = 0,\n            drop_last: bool = True,\n            shuffle_schedule: bool = True,\n            num_batches: Optional[int] = None,\n            choice_schedule: str = 'constant',\n            schedule_epochs: Optional[int] = None,\n            schedule_spread: float = 0.65,\n            schedule_random_mix: float = 0.1,\n    ) -> None:\n        if not hasattr(sampler, '__len__'):\n            raise TypeError('ScheduledBatchSampler requires a sampler with a length.')\n        if len(sampler) <= 0:\n            raise ValueError('ScheduledBatchSampler requires a non-empty sampler.')\n        if not batch_sizes:\n            raise ValueError('batch_sizes must contain at least one value.')\n        if any(int(batch_size) != batch_size or batch_size <= 0 for batch_size in batch_sizes):\n            raise ValueError('All scheduled batch sizes must be positive integers.')\n        if num_batches is not None and (int(num_batches) != num_batches or num_batches <= 0):\n            raise ValueError('num_batches must be a positive integer when specified.')\n        if choice_schedule not in ('constant', 'progressive'):\n            raise ValueError(\"choice_schedule must be 'constant' or 'progressive'.\")\n        if choice_schedule == 'progressive':\n            if len(batch_sizes) < 2:\n                raise ValueError('A progressive schedule requires at least two choices.')\n            if schedule_epochs is None or int(schedule_epochs) != schedule_epochs or schedule_epochs <= 0:\n                raise ValueError('schedule_epochs must be a positive integer for a progressive schedule.')\n            if schedule_spread < 0:\n                raise ValueError('schedule_spread must be non-negative.')\n            if not 0 <= schedule_random_mix <= 1:\n                raise ValueError('schedule_random_mix must be between 0 and 1.')\n\n        self.sampler = sampler\n        self.batch_sizes = tuple(int(batch_size) for batch_size in batch_sizes)\n        self.choice_weights = self._normalize_choice_weights(choice_weights)\n        self._active_choices = tuple(\n            choice_index\n            for choice_index, choice_weight in enumerate(self.choice_weights)","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/data/scheduled_sampler.py#L51-L87","documentation":"num_batches (optional cap/override on the number of batches per epoch) must, when provided, be a positive integer; None/non-positive/fractional values fail this check in the constructor.","triggerScenarios":"ScheduledBatchSampler(..., num_batches=0), num_batches=-5, num_batches=2.5, or num_batches computed as len(dataset)//0 (ZeroDivision caught earlier) / a float division result.","commonSituations":"Computing num_batches from steps-per-epoch math that yields 0 on a tiny dataset; config typos; passing math.floor results of negative numbers.","solutions":["Omit num_batches (pass None) to let the sampler infer it from the dataset length.","Compute it defensively: num_batches = max(1, round(steps)) or verify steps > 0 before passing.","Fix the underlying steps-per-epoch calculation (check batch size vs dataset size)."],"exampleFix":"# before\nsteps = len(dataset) // batch_size  # 0 when dataset < batch_size\nsched = ScheduledBatchSampler(s, batch_sizes=[b], num_batches=steps)\n\n# after\nsteps = max(1, len(dataset) // batch_size)  # or omit num_batches entirely\nsched = ScheduledBatchSampler(s, batch_sizes=[b], num_batches=steps)","handlingStrategy":"validation","validationCode":"num_batches = None if steps is None else max(1, int(round(steps))) if steps and steps > 0 else None","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer omitting num_batches (let the sampler infer).","Clamp computed step counts to >= 1.","Check steps-per-epoch math against dataset size."],"tags":["timm","sampler","num-batches","validation"],"backgroundTag":"invalid-numeric-config-value","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}