huggingface/pytorch-image-models · error · RuntimeError
Patch interpolation is not supported by this embedding confi
Error message
Patch interpolation is not supported by this embedding configuration.
What it means
prewarm_patch_interpolator precomputes interpolation buffers for target patch sizes, but the current patch embedding configuration (e.g. fixed conv patch embed with no interpolator) does not support patch interpolation at all, so it raises RuntimeError.
Source
Thrown at timm/models/naflexvit.py:569
nn.init.normal_(self.pos_embed_y, std=.02)
if self.pos_embed_x is not None:
nn.init.normal_(self.pos_embed_x, std=.02)
@torch.jit.ignore
def prewarm_patch_interpolator(
self,
patch_sizes: Iterable[Union[int, Tuple[int, int]]],
) -> None:
"""Precompute patch interpolation matrices on the projection device.
The cache is cleared by any subsequent ``.to()`` / dtype conversion of the model,
so prewarm after the model has been moved to its execution device.
Args:
patch_sizes: Iterable of target patch sizes to precompute.
"""
if not self.supports_patch_interpolation:
raise RuntimeError('Patch interpolation is not supported by this embedding configuration.')
self.patch_interpolator.prewarm(patch_sizes, device=self.proj.weight.device)
def feature_info(self, location) -> Dict[str, Any]:
"""Get feature information for feature extraction.
Args:
location: Feature extraction location identifier
Returns:
Dictionary containing feature channel count and reduction factor
"""
return dict(num_chs=self.embed_dim, reduction=self.patch_size)
def feat_ratio(self, as_scalar: bool = True) -> Union[int, Tuple[int, int]]:
"""Get the feature reduction ratio (stride) of the patch embedding.
Args:
as_scalar: Whether to return the maximum dimension as a scalarView on GitHub (pinned to 9a5261e31b)
Solutions
- Check model.patch_embed.supports_patch_interpolation before calling
- Build the model with an interpolation-capable embed config (provide compatible pos_embed type / interpolator kwargs)
- Skip prewarming; interpolation will be computed lazily if supported, or is simply unavailable otherwise
Example fix
# before
model.patch_embed.prewarm_patch_interpolator([14, 16])
# after
if model.patch_embed.supports_patch_interpolation:
model.patch_embed.prewarm_patch_interpolator([14, 16]) Defensive patterns
Strategy: type-guard
Type guard
def can_prewarm(pe) -> bool:
return bool(getattr(pe, 'supports_patch_interpolation', False)) Try / catch
try:
pe.prewarm_patch_interpolator(sizes)
except RuntimeError:
pass # interpolation unsupported; proceed lazily Prevention
- Gate prewarm calls on supports_patch_interpolation
- Log the flag at model build time in config-driven pipelines
When it happens
Trigger: Calling prewarm_patch_interpolator([14, 16]) on a NaFlexViT whose patch_embed was built with a configuration where supports_patch_interpolation is False (e.g. pos_embed grid fixed and non-interpolatable, or an embed type without an interpolator).
Common situations: Optimizing startup latency for multi-resolution inference on a model variant that was configured with fixed patch geometry.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Cannot initialize position embeddings without grid_size.Plea
- Unknown rope_type: {cfg.rope_type}
- output_fmt="NCHW" is not supported for NaFlex (dict) inputs,
- NaFlex forward_intermediates with active patch dropout requi
- 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/3b684996b575567f.
Report an issue: GitHub.