{"record":{"id":"d5e995d0030ee64c","repo":"huggingface/pytorch-image-models","slug":"name-capitalize-range-reversed-swapping","errorCode":null,"errorMessage":"{name.capitalize()} range reversed. Swapping.","messagePattern":"(.+?) range reversed\\. Swapping\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"timm/data/naflex_transforms.py","lineNumber":490,"sourceCode":"            width=target_hw[1],\n            fill=self.fill,\n            padding_mode=self.padding_mode,\n        )\n\n    def __repr__(self) -> str:\n        return (f\"{self.__class__.__name__}(patch_size={self.patch_size}, \"\n                f\"max_sequence_len={self.max_sequence_len}, \"\n                f\"divisible_by_patch={self.divisible_by_patch})\")\n\n\ndef _validate_range(value, name, length=2):\n    # Validate type and length\n    if not isinstance(value, Sequence) or len(value) != length:\n        raise ValueError(f\"{name} should be a sequence of length {length}.\")\n\n    # Validate order\n    if value[0] > value[1]:\n        warnings.warn(f\"{name.capitalize()} range reversed. Swapping.\")\n        return value[1], value[0]\n\n    return value\n\n\nclass RandomResizedCropToSequence(torch.nn.Module):\n    \"\"\"\n    Randomly crop the input image to a subregion with varying area and aspect ratio\n    (relative to the original), then resize that crop to a target size. The target size\n    is determined such that patchifying the resized image (with `patch_size`)\n    does not exceed `max_seq_len` patches, while maintaining the aspect ratio of the crop.\n\n    This combines aspects of torchvision's RandomResizedCrop with sequence length constraints.\n\n    Args:\n        patch_size (int or tuple[int, int]):\n            Patch dimensions (patch_h, patch_w) for sequence length calculation.\n        max_seq_len (int):","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/data/naflex_transforms.py#L472-L508","documentation":"_validate_range in timm.data.naflex_transforms warns and auto-swaps when a (min, max) range is given reversed (value[0] > value[1]) — e.g. final_scale_range=(0.9, 0.3). The transform still works because the pair is reordered, but the warning flags likely config intent ambiguity.","triggerScenarios":"Passing final_scale_range=(1.0, 0.5) or similar reversed bounds to RandomResizedCropToSequence/NaFlex transforms that use _validate_range.","commonSituations":"Copy-paste scale ranges from configs written as (max, min); thinking of scale as 'start scale' to 'end scale' during progressive resizing (where a descending range can be intentional).","solutions":["Rewrite ranges as (min, max): final_scale_range=(0.5, 1.0)","If a descending range is intentional for your schedule, note the swap or suppress the warning"],"exampleFix":"# before\ntransform = RandomResizedCropToSequence(..., final_scale_range=(0.9, 0.3))\n# after\ntransform = RandomResizedCropToSequence(..., final_scale_range=(0.3, 0.9))","handlingStrategy":"validation","validationCode":"assert lo <= hi for lo, hi in [final_scale_range], 'range must be (min, max)'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Author all ranges as (min, max) by convention","Add a config linter that checks tuple ordering"],"tags":["naflex","transforms","range-validation","timm"],"backgroundTag":"reversed-min-max-range","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}