{"record":{"id":"b0ee89223ccc911d","repo":"huggingface/pytorch-image-models","slug":"no-full-scheduled-batch-fits-the-sampler-reduce-t","errorCode":null,"errorMessage":"No full scheduled batch fits the sampler; reduce the batch sizes.","messagePattern":"No full scheduled batch fits the sampler; reduce the batch sizes\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"timm/data/scheduled_sampler.py","lineNumber":106,"sourceCode":"            if choice_weight > 0\n        )\n        self.seed = seed\n        self.drop_last = drop_last\n        self.shuffle_schedule = shuffle_schedule\n        self.choice_schedule = choice_schedule\n        self.schedule_epochs = int(schedule_epochs) if schedule_epochs is not None else None\n        self.schedule_spread = schedule_spread\n        self.schedule_random_mix = schedule_random_mix\n        self.epoch = 0\n        self.average_batch_size = self._calculate_average_batch_size()\n        if choice_schedule == 'progressive' and num_batches is None:\n            num_batches = self._infer_num_batches()\n        self.num_batches = int(num_batches) if num_batches is not None else None\n        self._sample_budget_schedule: Tuple[Tuple[int, int], ...] = ()\n        if self.num_batches is None:\n            self._sample_budget_schedule = self._create_sample_budget_schedule()\n            if not self._sample_budget_schedule:\n                raise ValueError(\n                    'No full scheduled batch fits the sampler; reduce the batch sizes.'\n                )\n\n    def _normalize_choice_weights(\n            self,\n            choice_weights: Optional[Sequence[float]],\n    ) -> torch.Tensor:\n        if choice_weights is None:\n            return torch.full((len(self.batch_sizes),), 1.0 / len(self.batch_sizes), dtype=torch.float64)\n        if len(choice_weights) != len(self.batch_sizes):\n            raise ValueError('choice_weights and batch_sizes must have the same length.')\n\n        weights = torch.tensor(choice_weights, dtype=torch.float64)\n        if not torch.isfinite(weights).all() or (weights < 0).any():\n            raise ValueError('choice_weights must contain finite, non-negative values.')\n        weight_sum = weights.sum()\n        if weight_sum <= 0:\n            raise ValueError('choice_weights must have a positive sum.')","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/data/scheduled_sampler.py#L88-L124","documentation":"When num_batches is not given, ScheduledBatchSampler builds a per-batch sample budget schedule from batch_sizes; if even one full smallest scheduled batch doesn't fit within len(sampler), the schedule is empty and this ValueError is raised — effectively the sampler is smaller than its own batch size.","triggerScenarios":"len(sampler) < min(batch_sizes), e.g. a 100-sample dataset with batch_sizes=[256], or an aggressively large progressive final batch size.","commonSituations":"Small debug datasets with production batch sizes; distributed sharding leaving each rank fewer samples than the batch size; last-stage batch sizes in a progressive schedule exceeding the dataset.","solutions":["Reduce batch_sizes so the smallest is <= len(sampler) (and the largest if you need full progressive coverage).","Or pass num_batches explicitly if you accept truncation semantics of your own loop.","Scale batch size per rank: batch_size = base // world_size."],"exampleFix":"# before\nsched = ScheduledBatchSampler(sampler, batch_sizes=[256, 512])  # len(sampler)=100\n\n# after\nsched = ScheduledBatchSampler(sampler, batch_sizes=[32, 64])  # fits 100 samples","handlingStrategy":"validation","validationCode":"assert min(batch_sizes) <= len(sampler) <= max(batch_sizes) * 1000 and min(batch_sizes) <= len(sampler), \\\n    'smallest batch exceeds sampler length'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Scale batch sizes to dataset size (and per-rank in DDP).","For smoke tests, shrink batch_sizes along with the dataset.","Assert min(batch_sizes) <= len(sampler) before construction."],"tags":["timm","sampler","batch-size","dataset-size"],"backgroundTag":"batch-size-exceeds-dataset-size","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}