huggingface/pytorch-image-models · warning · FutureWarning

Importing from {__name__} is deprecated, please import via t

Error message

Importing from {__name__} is deprecated, please import via timm.layers

What it means

Importing timm.models.layers is deprecated: the layers package moved to timm.layers and this shim re-exports its contents with a FutureWarning. All layer classes (conv, norm, attention, etc.) should come from timm.layers.

Source

Thrown at timm/models/layers/__init__.py:49

from timm.layers.non_local_attn import NonLocalAttn, BatNonLocalAttn
from timm.layers.norm import GroupNorm, GroupNorm1, LayerNorm, LayerNorm2d
from timm.layers.norm_act import BatchNormAct2d, GroupNormAct, convert_sync_batchnorm
from timm.layers.padding import get_padding, get_same_padding, pad_same
from timm.layers.patch_embed import PatchEmbed
from timm.layers.pool2d_same import AvgPool2dSame, create_pool2d
from timm.layers.pos_embed_sincos import RotaryEmbedding
from timm.layers.squeeze_excite import SEModule, SqueezeExcite, EffectiveSEModule, EffectiveSqueezeExcite
from timm.layers.selective_kernel import SelectiveKernel
from timm.layers.separable_conv import SeparableConv2d, SeparableConvNormAct
from timm.layers.split_attn import SplitAttn
from timm.layers.split_batchnorm import SplitBatchNorm2d, convert_splitbn_model
from timm.layers.std_conv import StdConv2d, StdConv2dSame, ScaledStdConv2d, ScaledStdConv2dSame
from timm.layers.test_time_pool import TestTimePoolHead, apply_test_time_pool
from timm.layers.trace_utils import _assert, _float_to_int
from timm.layers.weight_init import trunc_normal_, trunc_normal_tf_, variance_scaling_, lecun_normal_

import warnings
warnings.warn(f"Importing from {__name__} is deprecated, please import via timm.layers", FutureWarning)

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Replace with from timm.layers import ... everywhere (grep 'timm.models.layers')
  2. For plugin modules registered with timm, also update module paths accordingly
  3. If you must keep old paths short-term, filter the FutureWarning, but schedule the rename

Example fix

# before
from timm.models.layers import DropPath, trunc_normal_
# after
from timm.layers import DropPath, trunc_normal_
Defensive patterns

Strategy: validation

Validate before calling

from timm.layers import DropPath, trunc_normal_  # modern path
# transitional suppression:
import warnings
with warnings.catch_warnings():
    warnings.simplefilter('ignore', FutureWarning)
    from timm.models.layers import StdConv2d

Prevention

When it happens

Trigger: from timm.models.layers import StdConv2d, trunc_normal_, DropPath; import timm.models.layers.* in custom model code — one of the most common imports in the timm ecosystem.

Common situations: Nearly every downstream repo, tutorial, and custom ViT/ConvNet model written before timm 0.9; coupling to timm.models.layers paths breaks after upgrade.

Related errors


AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27). Data as JSON: /api/errors/56bf20670d952739. Report an issue: GitHub.