{"record":{"id":"a3786852a408a778","repo":"huggingface/pytorch-image-models","slug":"calculated-batch-size-0-seq-len-seq-len-rem","errorCode":null,"errorMessage":"Calculated batch size <= 0 (seq_len={seq_len}, remaining={remaining_samples}). Stopping schedule generation early.","messagePattern":"Calculated batch size <= 0 \\(seq_len=(.+?), remaining=(.+?)\\)\\. Stopping schedule generation early\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"timm/data/naflex_dataset.py","lineNumber":370,"sourceCode":"            # Sample sequence length deterministically based on base seed\n            seq_idx = torch.randint(0, len(self.seq_lens), (1,), generator=g).item()\n            seq_len = self.seq_lens[seq_idx]\n\n            # Calculate batch size\n            batch_size = calculate_naflex_batch_size(\n                tokens_per_batch=self.max_tokens_per_batch,\n                seq_len=seq_len,\n                # max_size should be remaining_samples to avoid overshooting\n                max_size=remaining_samples,\n                divisor=self.batch_divisor,\n                rounding='floor',\n            )\n            # Ensure batch size is positive and doesn't exceed remaining samples\n            batch_size = max(1, batch_size)\n            batch_size = min(batch_size, remaining_samples)\n\n            if batch_size <= 0:\n                 warnings.warn(f\"Calculated batch size <= 0 (seq_len={seq_len}, remaining={remaining_samples}). Stopping schedule generation early.\")\n                 break # Avoid infinite loop if something goes wrong\n\n            current_schedule.append((seq_len, batch_size))\n            remaining_samples -= batch_size\n            total_scheduled_samples += batch_size\n\n        # Sanity check: Ensure the schedule covers all samples for the rank\n        if total_scheduled_samples != num_samples_per_rank:\n            warnings.warn(\n                f\"Rank {self.rank}: Canonical schedule accounts for {total_scheduled_samples} samples, \"\n                f\"but expected {num_samples_per_rank} samples per rank. \"\n                f\"This might happen if min_batch_size or batch_divisor constraints prevent utilizing all samples. \"\n                f\"Check parameters. Remaining samples: {remaining_samples}\"\n            )\n            # Adjust if needed? Could add a final small batch, but might violate constraints.\n            # Current behavior: some samples might be dropped if schedule logic fails.\n\n        self._canonical_batch_schedule = current_schedule","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/data/naflex_dataset.py#L352-L388","documentation":"NaFlexDataset._create_canonical_schedule clamps computed batch sizes with max(1, ...) and min(batch_size, remaining), so batch_size <= 0 is theoretically unreachable; the warning is a defensive guard that fires only if the clamping logic is broken or inputs (min_batch_size/batch_divisor) are pathological, and it breaks schedule generation to avoid an infinite loop.","triggerScenarios":"Passing inconsistent constraints such as min_batch_size=0 or batch_divisor=0 (division anomalies), or NaN sequence-length targets that make computed batch_size NaN before clamping.","commonSituations":"Misconfigured batch schedule parameters; upgrading timm where schedule math changed. In practice with valid params this warning never fires.","solutions":["Sanity-check constructor args: min_batch_size >= 1 and batch_divisor >= 1","Ensure seq_len targets are positive integers (no NaN/inf)","Update timm — if the clamping logic itself is buggy, a newer release may fix it"],"exampleFix":"# before\nds = NaFlexDataset(..., min_batch_size=0, batch_divisor=0)\n# after\nds = NaFlexDataset(..., min_batch_size=1, batch_divisor=8)","handlingStrategy":"validation","validationCode":"assert min_batch_size >= 1 and batch_divisor >= 1, 'schedule constraints must be positive'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate schedule kwargs in your training entrypoint","Treat this warning as a bug report — it should never fire with valid inputs"],"tags":["naflex","batch-schedule","defensive-check","timm"],"backgroundTag":"invalid-parameter-combination","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}