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.models

What it means

Importing timm.models.factory is deprecated: the module was renamed to timm.models._factory and only exists as a compatibility shim that re-exports its contents and emits this FutureWarning. New code should import from timm.models (or timm.models._factory).

Source

Thrown at timm/models/factory.py:4

from ._factory import *

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

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Change to from timm.models import create_model (preferred public API)
  2. Or import the private module timm.models._factory directly if you need module-style access
  3. Upgrade third-party code that references the old path

Example fix

# before
from timm.models.factory import create_model
# after
from timm import create_model
Defensive patterns

Strategy: validation

Validate before calling

import warnings
with warnings.catch_warnings():
    warnings.filterwarnings('ignore', message='Importing from timm.models.factory')
    import timm.models.factory  # transitional

Prevention

When it happens

Trigger: import timm.models.factory; from timm.models.factory import create_model; older scripts importing module paths from timm <0.9.

Common situations: Legacy training scripts, copied tutorials, third-party repos targeting old timm versions after a timm upgrade.

Related errors


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