huggingface/pytorch-image-models · warning
{name.capitalize()} range reversed. Swapping.
Error message
{name.capitalize()} range reversed. Swapping. What it means
_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.
Source
Thrown at timm/data/naflex_transforms.py:490
width=target_hw[1],
fill=self.fill,
padding_mode=self.padding_mode,
)
def __repr__(self) -> str:
return (f"{self.__class__.__name__}(patch_size={self.patch_size}, "
f"max_sequence_len={self.max_sequence_len}, "
f"divisible_by_patch={self.divisible_by_patch})")
def _validate_range(value, name, length=2):
# Validate type and length
if not isinstance(value, Sequence) or len(value) != length:
raise ValueError(f"{name} should be a sequence of length {length}.")
# Validate order
if value[0] > value[1]:
warnings.warn(f"{name.capitalize()} range reversed. Swapping.")
return value[1], value[0]
return value
class RandomResizedCropToSequence(torch.nn.Module):
"""
Randomly crop the input image to a subregion with varying area and aspect ratio
(relative to the original), then resize that crop to a target size. The target size
is determined such that patchifying the resized image (with `patch_size`)
does not exceed `max_seq_len` patches, while maintaining the aspect ratio of the crop.
This combines aspects of torchvision's RandomResizedCrop with sequence length constraints.
Args:
patch_size (int or tuple[int, int]):
Patch dimensions (patch_h, patch_w) for sequence length calculation.
max_seq_len (int):View on GitHub (pinned to 9a5261e31b)
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
Example fix
# before transform = RandomResizedCropToSequence(..., final_scale_range=(0.9, 0.3)) # after transform = RandomResizedCropToSequence(..., final_scale_range=(0.3, 0.9))
Defensive patterns
Strategy: validation
Validate before calling
assert lo <= hi for lo, hi in [final_scale_range], 'range must be (min, max)'
Prevention
- Author all ranges as (min, max) by convention
- Add a config linter that checks tuple ordering
When it happens
Trigger: Passing final_scale_range=(1.0, 0.5) or similar reversed bounds to RandomResizedCropToSequence/NaFlex transforms that use _validate_range.
Common situations: 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).
Related errors
- Transform returned None for index {idx}. Skipping sample.
- final_scale_range values should ideally be between 0.0 and 1
- Final scale randomization ({scale_factor:.2f}) resulted in s
- range should be of kind (min, max)
- Input image must have positive dimensions, got H={height}, W
AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27).
Data as JSON: /api/errors/d5e995d0030ee64c.
Report an issue: GitHub.