{"record":{"id":"68479178dc8e835a","repo":"huggingface/pytorch-image-models","slug":"rank-self-rank-assigned-scheduled-samples-coun","errorCode":null,"errorMessage":"Rank {self.rank}: Assigned {scheduled_samples_count} samples to batches, but expected {effective_samples_this_rank} effective samples this epoch. Indices remaining: {effective_samples_this_rank - scheduled_samples_count}.","messagePattern":"Rank (.+?): Assigned (.+?) samples to batches, but expected (.+?) effective samples this epoch\\. Indices remaining: (.+?)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"timm/data/naflex_dataset.py","lineNumber":480,"sourceCode":"            # Ensure we don't try to grab more indices than available for the rank\n            actual_bs = min(bs, effective_samples_this_rank - idx_pos)\n            if actual_bs <= 0:\n                 if scheduled_samples_count < effective_samples_this_rank:\n                     # This indicates mismatch between schedule total and actual samples\n                     warnings.warn(f\"Rank {self.rank}: Ran out of samples ({idx_pos}/{effective_samples_this_rank}) before processing entire schedule. Check schedule generation.\")\n                 break # Stop if no more indices or batch size is zero\n\n            batch_indices = indices_this_rank[idx_pos : idx_pos + actual_bs]\n            patch_idx = 0\n            if self.variable_patch_size:\n                patch_idx = torch.multinomial(patch_size_probs, 1, generator=g).item()\n            epoch_batches.append((seq_len, patch_idx, batch_indices))\n            idx_pos += actual_bs\n            scheduled_samples_count += actual_bs\n\n        # Final check\n        if scheduled_samples_count != effective_samples_this_rank:\n             warnings.warn(\n                f\"Rank {self.rank}: Assigned {scheduled_samples_count} samples to batches, \"\n                f\"but expected {effective_samples_this_rank} effective samples this epoch. \"\n                f\"Indices remaining: {effective_samples_this_rank - scheduled_samples_count}.\"\n             )\n        return epoch_batches\n\n    def set_epoch(self, epoch: int) -> None:\n        \"\"\"Set the multiprocessing-safe epoch read by DataLoader workers.\n\n        Args:\n            epoch: New epoch number.\n        \"\"\"\n        self.shared_epoch.value = epoch\n\n    def __len__(self) -> int:\n        \"\"\"Return the number of batches for this rank.\n\n        Returns:","sourceCodeStart":462,"sourceCodeEnd":498,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/data/naflex_dataset.py#L462-L498","documentation":"Final sanity check in NaFlexDataset._prepare_epoch_batches: after assigning indices to schedule batches, scheduled_samples_count should equal effective_samples_this_rank. A warning means some indices were never assigned to any batch (leftovers), so the epoch silently sees fewer samples than requested.","triggerScenarios":"Batch_divisor/min_batch_size constraints leave a remainder that no schedule entry can hold (cascade from 267); clamping via min(bs, remaining) truncated batches; drop_last-style behavior on a non-divisible per-rank count.","commonSituations":"Same family as 267–269: odd dataset sizes under distributed sharding and packing constraints. Usually benign (a few dropped samples) but should be eliminated if exact epoch size matters.","solutions":["Tune min_batch_size/batch_divisor so total scheduled == effective samples, or pad dataset accordingly","Verify world_size/rank consistency","If dropping a few samples per epoch is acceptable, suppress with warnings.filterwarnings for this message"],"exampleFix":"# before\nNaFlexDataset(ds, ..., batch_divisor=32)  # 1000 samples/rank leaves remainder\n# after\nNaFlexDataset(ds, ..., batch_divisor=32, min_batch_size=1)  # remainder scheduled","handlingStrategy":"validation","validationCode":"assert sum(bs for _, bs in schedule) == effective_samples_per_rank, 'indices will go unused'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Align min_batch_size/batch_divisor with per-rank sample counts","Monitor actual samples-per-epoch vs expected in logs"],"tags":["naflex","distributed","schedule-mismatch","timm"],"backgroundTag":"uneven-data-sharding","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}