{"record":{"id":"3b684996b575567f","repo":"huggingface/pytorch-image-models","slug":"patch-interpolation-is-not-supported-by-this-embed","errorCode":null,"errorMessage":"Patch interpolation is not supported by this embedding configuration.","messagePattern":"Patch interpolation is not supported by this embedding configuration\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"timm/models/naflexvit.py","lineNumber":569,"sourceCode":"            nn.init.normal_(self.pos_embed_y, std=.02)\n        if self.pos_embed_x is not None:\n            nn.init.normal_(self.pos_embed_x, std=.02)\n\n    @torch.jit.ignore\n    def prewarm_patch_interpolator(\n            self,\n            patch_sizes: Iterable[Union[int, Tuple[int, int]]],\n    ) -> None:\n        \"\"\"Precompute patch interpolation matrices on the projection device.\n\n        The cache is cleared by any subsequent ``.to()`` / dtype conversion of the model,\n        so prewarm after the model has been moved to its execution device.\n\n        Args:\n            patch_sizes: Iterable of target patch sizes to precompute.\n        \"\"\"\n        if not self.supports_patch_interpolation:\n            raise RuntimeError('Patch interpolation is not supported by this embedding configuration.')\n        self.patch_interpolator.prewarm(patch_sizes, device=self.proj.weight.device)\n\n    def feature_info(self, location) -> Dict[str, Any]:\n        \"\"\"Get feature information for feature extraction.\n\n        Args:\n            location: Feature extraction location identifier\n\n        Returns:\n            Dictionary containing feature channel count and reduction factor\n        \"\"\"\n        return dict(num_chs=self.embed_dim, reduction=self.patch_size)\n\n    def feat_ratio(self, as_scalar: bool = True) -> Union[int, Tuple[int, int]]:\n        \"\"\"Get the feature reduction ratio (stride) of the patch embedding.\n\n        Args:\n            as_scalar: Whether to return the maximum dimension as a scalar","sourceCodeStart":551,"sourceCodeEnd":587,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/models/naflexvit.py#L551-L587","documentation":"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.","triggerScenarios":"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).","commonSituations":"Optimizing startup latency for multi-resolution inference on a model variant that was configured with fixed patch geometry.","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"],"exampleFix":"# before\nmodel.patch_embed.prewarm_patch_interpolator([14, 16])\n# after\nif model.patch_embed.supports_patch_interpolation:\n    model.patch_embed.prewarm_patch_interpolator([14, 16])","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"def can_prewarm(pe) -> bool:\n    return bool(getattr(pe, 'supports_patch_interpolation', False))","tryCatchPattern":"try:\n    pe.prewarm_patch_interpolator(sizes)\nexcept RuntimeError:\n    pass  # interpolation unsupported; proceed lazily","preventionTips":["Gate prewarm calls on supports_patch_interpolation","Log the flag at model build time in config-driven pipelines"],"tags":["timm","naflexvit","patch-embed","runtime-check"],"backgroundTag":"unsupported-operation","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}