{"record":{"id":"43477605199b70a9","repo":"huggingface/pytorch-image-models","slug":"all-scheduled-batch-sizes-must-be-positive-integer","errorCode":null,"errorMessage":"All scheduled batch sizes must be positive integers.","messagePattern":"All scheduled batch sizes must be positive integers\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"timm/data/scheduled_sampler.py","lineNumber":67,"sourceCode":"            batch_sizes: Sequence[int],\n            choice_weights: Optional[Sequence[float]] = None,\n            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(","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/data/scheduled_sampler.py#L49-L85","documentation":"Every entry in batch_sizes must be a positive integer (floats with fractional parts, 0, or negatives are rejected) because the sampler yields integer batch counts and budgets computed from these values.","triggerScenarios":"batch_sizes=[256.5], [0], [-32], or numpy float entries like [np.float64(128)] that don't compare equal to their int() cast… specifically any value where int(b)!=b or b<=0.","commonSituations":"Config files parsed as floats (256.0 is fine, but 25e1 typos like 256.5); computed batch sizes from divisions (total/num_workers) producing fractions; passing booleans/None inside the list.","solutions":["Round/normalize computed sizes: [max(1, int(round(b))) for b in sizes].","Fix the literal values in the config to plain positive integers.","Add an assert/validated schema in your config loader."],"exampleFix":"# before\nsizes = [total_samples / num_buckets]  # may be 170.67\nsched = ScheduledBatchSampler(sampler, batch_sizes=sizes)\n\n# after\nsizes = [max(1, round(total_samples / num_buckets))]\nsched = ScheduledBatchSampler(sampler, batch_sizes=sizes)","handlingStrategy":"validation","validationCode":"batch_sizes = [int(b) for b in batch_sizes if int(b) == b and b > 0]\nassert len(batch_sizes) == len(raw_sizes)","typeGuard":"def valid_batch_sizes(sizes) -> bool:\n    return bool(sizes) and all(isinstance(b,(int,float)) and b > 0 and int(b) == b for b in sizes)","tryCatchPattern":null,"preventionTips":["Round computed batch sizes.","Use integers in configs, not floats/percentages.","Validate with a helper before passing."],"tags":["timm","sampler","batch-size","validation"],"backgroundTag":"invalid-numeric-config-value","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}