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
- Change to from timm.models import create_model (preferred public API)
- Or import the private module timm.models._factory directly if you need module-style access
- 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
- Import from the timm top-level (from timm import create_model)
- Add a lint rule/grep check for 'timm.models.factory'
- Test imports after timm upgrades
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
- Importing from {__name__} is deprecated, please import via t
- Importing from {__name__} is deprecated, please import via t
- Importing from {__name__} is deprecated, please import via t
- Importing from {__name__} is deprecated, please import via t
- Importing from {__name__} is deprecated, please import via t
AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27).
Data as JSON: /api/errors/e8f1611c6bdcf7e8.
Report an issue: GitHub.