{"record":{"id":"a9d1f1fab0d25d33","repo":"huggingface/pytorch-image-models","slug":"final-scale-randomization-scale-factor-2f-res","errorCode":null,"errorMessage":"Final scale randomization ({scale_factor:.2f}) resulted in size {final_size} exceeding max_seq_len={max_seq_len} after rounding. Reverting to feasible size {feasible_size}.","messagePattern":"Final scale randomization \\((.+?)\\) resulted in size (.+?) exceeding max_seq_len=(.+?) after rounding\\. Reverting to feasible size (.+?)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"timm/data/naflex_transforms.py","lineNumber":693,"sourceCode":"                target_h = patch_h * math.ceil(raw_h / patch_h)\n                target_w = patch_w * math.ceil(raw_w / patch_w)\n            else:\n                target_h = int(round(raw_h))\n                target_w = int(round(raw_w))\n\n            # Ensure final size is at least one patch dimension\n            target_h = max(target_h, patch_h)\n            target_w = max(target_w, patch_w)\n            final_size = (target_h, target_w)\n\n             # Final check: Ensure this randomized size still fits max_seq_len\n             # (It should, as we scaled down, but rounding might theoretically push it over)\n            num_patches_h = final_size[0] // patch_h\n            num_patches_w = final_size[1] // patch_w\n            if (num_patches_h * num_patches_w) > max_seq_len:\n                 # If it exceeds, revert to the original feasible_size (safest)\n                 final_size = feasible_size\n                 warnings.warn(f\"Final scale randomization ({scale_factor:.2f}) resulted in size {final_size} exceeding max_seq_len={max_seq_len} after rounding. Reverting to feasible size {feasible_size}.\")\n\n        # Select interpolation mode\n        if isinstance(interpolation, (tuple, list)):\n            interpolation = random.choice(interpolation)\n        else:\n            interpolation = interpolation\n\n        return (top, left, crop_h, crop_w), final_size, interpolation\n\n    def forward(self, img: torch.Tensor) -> torch.Tensor:\n        # Sample crop, resize, and interpolation parameters\n        crop_params, final_size, interpolation = self.get_params(\n            img,\n            scale=self.scale,\n            ratio=self.ratio,\n            crop_attempts=self.attempts,\n            patch_h=self.patch_h,\n            patch_w=self.patch_w,","sourceCodeStart":675,"sourceCodeEnd":711,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/data/naflex_transforms.py#L675-L711","documentation":"In RandomResizedCropToSequence.get_params, after applying a random final-scale factor the recomputed patch grid can (due to rounding) exceed max_seq_len tokens. The transform warns and reverts to the previously computed feasible size, guaranteeing the sequence-length budget is respected.","triggerScenarios":"final_scale_range close to 1.0 combined with max_seq_len exactly at the boundary; patch sizes where rounding up h*w//patch pushes num_patches one over max_seq_len.","commonSituations":"Aggressive NaFlex configs that pack sequences to the max token budget. The fallback is intentional and safe; the warning just notes the randomized scale was discarded for that sample.","solutions":["No fix required — behavior is a safe revert; ignore or silence the warning","To reduce frequency, lower the top of final_scale_range (e.g. (0.7, 0.95)) or slightly raise max_seq_len","Align patch size and max_seq_len so rounding margins exist"],"exampleFix":"# before\ntfm = RandomResizedCropToSequence(..., final_scale_range=(0.9, 1.0), max_seq_len=256)\n# after\ntfm = RandomResizedCropToSequence(..., final_scale_range=(0.8, 0.95), max_seq_len=256)","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat as informational: the transform safely reverts","Leave headroom between scale-range top and max_seq_len"],"tags":["naflex","transforms","max-seq-len","timm"],"backgroundTag":"fallback-size-clamp","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}