ImportError: cannot import name 'X' from 'timm.models.layers', No module named 'timm.layers' or 'timm.models.layers.norm': which timm versions have it
Almost all of these come from timm 0.9.0 (2023-05-12), which moved timm.models.layers to timm.layers and removed 65 modules. No module named 'timm.layers' means your timm is older than 0.9.0: upgrade. No module named 'timm.models.layers.norm' (or .helpers, .drop, ...) means code or a pickled model from timm 0.6.13 or older: the file is now timm.layers.norm, or pin pip install "timm<0.9.0". from timm.models.layers import X still works for the names that existed in 0.9.0, with a FutureWarning, but not for the 127 names added to timm.layers since. For any other module or name, paste the error below.
Corrected on 2026-12-05: this page read only the releases with a git tag. The releases on PyPI without one (the even 0.1.x releases and 0.3.0 to 0.3.2) were taken to have the names of the tagged release before them, which is not always so: from timm import list_models works from 0.1.2 (2019-06-24), not only from 0.2.1. Those releases were then read from their PyPI wheels: 8 top-level names (and 2,320 module-and-name pairs in all) differ from the tagged release before them. The lookup now gives them.
Examples:
Runs in your browser on timm.json (427 KB); nothing you paste is sent anywhere. Covers 12,776 module-and-name pairs in 382 modules.
Which modules did timm 0.9.0 remove, and where are they now?
65 modules left in 0.9.0; for 61 of them a module with the same file exists in 1.0.31, under timm.layers for the old layer files and with a leading underscore for the builders and helpers under timm.models. An import that names one of these modules fails on 0.9.0 and later, and so does loading a model pickled with timm 0.6.13 or older that used them.
| Removed in 0.9.0 | Same file in 1.0.31 |
|---|---|
timm.data.parsers | timm.data.readers |
timm.data.parsers.class_map | timm.data.readers.class_map |
timm.data.parsers.img_extensions | timm.data.readers.img_extensions |
timm.data.parsers.parser | timm.data.readers.reader |
timm.data.parsers.parser_factory | timm.data.readers.reader_factory |
timm.data.parsers.parser_image_folder | timm.data.readers.reader_image_folder |
timm.data.parsers.parser_image_in_tar | timm.data.readers.reader_image_in_tar |
timm.data.parsers.parser_image_tar | timm.data.readers.reader_image_tar |
timm.data.parsers.parser_tfds | timm.data.readers.reader_tfds |
timm.models.efficientnet_blocks | timm.models._efficientnet_blocks |
timm.models.efficientnet_builder | timm.models._efficientnet_builder |
timm.models.gluon_resnet | none with the same file name |
timm.models.gluon_xception | none with the same file name |
timm.models.layers.activations | timm.layers.activations |
timm.models.layers.activations_jit | none with the same file name |
timm.models.layers.activations_me | timm.layers.activations_me |
timm.models.layers.adaptive_avgmax_pool | timm.layers.adaptive_avgmax_pool |
timm.models.layers.attention_pool2d | timm.layers.attention_pool2d |
timm.models.layers.blur_pool | timm.layers.blur_pool |
timm.models.layers.bottleneck_attn | timm.layers.bottleneck_attn |
timm.models.layers.cbam | timm.layers.cbam |
timm.models.layers.classifier | timm.layers.classifier |
timm.models.layers.cond_conv2d | timm.layers.cond_conv2d |
timm.models.layers.config | timm.layers.config |
timm.models.layers.conv2d_same | timm.layers.conv2d_same |
timm.models.layers.conv_bn_act | timm.layers.conv_bn_act |
timm.models.layers.create_act | timm.layers.create_act |
timm.models.layers.create_attn | timm.layers.create_attn |
timm.models.layers.create_conv2d | timm.layers.create_conv2d |
timm.models.layers.create_norm | timm.layers.create_norm |
timm.models.layers.create_norm_act | timm.layers.create_norm_act |
timm.models.layers.drop | timm.layers.drop |
timm.models.layers.eca | timm.layers.eca |
timm.models.layers.evo_norm | timm.layers.evo_norm |
timm.models.layers.fast_norm | timm.layers.fast_norm |
timm.models.layers.filter_response_norm | timm.layers.filter_response_norm |
timm.models.layers.gather_excite | timm.layers.gather_excite |
timm.models.layers.global_context | timm.layers.global_context |
timm.models.layers.halo_attn | timm.layers.halo_attn |
timm.models.layers.helpers | timm.layers.helpers |
timm.models.layers.inplace_abn | timm.layers.inplace_abn |
timm.models.layers.lambda_layer | timm.layers.lambda_layer |
timm.models.layers.linear | timm.layers.linear |
timm.models.layers.median_pool | timm.layers.median_pool |
timm.models.layers.mixed_conv2d | timm.layers.mixed_conv2d |
timm.models.layers.ml_decoder | timm.layers.ml_decoder |
timm.models.layers.mlp | timm.layers.mlp |
timm.models.layers.non_local_attn | timm.layers.non_local_attn |
timm.models.layers.norm | timm.layers.norm |
timm.models.layers.norm_act | timm.layers.norm_act |
timm.models.layers.padding | timm.layers.padding |
timm.models.layers.patch_embed | timm.layers.patch_embed |
timm.models.layers.pool2d_same | timm.layers.pool2d_same |
timm.models.layers.pos_embed | timm.layers.pos_embed |
timm.models.layers.selective_kernel | timm.layers.selective_kernel |
timm.models.layers.separable_conv | timm.layers.separable_conv |
timm.models.layers.space_to_depth | timm.layers.space_to_depth |
timm.models.layers.split_attn | timm.layers.split_attn |
timm.models.layers.split_batchnorm | timm.layers.split_batchnorm |
timm.models.layers.squeeze_excite | timm.layers.squeeze_excite |
timm.models.layers.std_conv | timm.layers.std_conv |
timm.models.layers.test_time_pool | timm.layers.test_time_pool |
timm.models.layers.trace_utils | timm.layers.trace_utils |
timm.models.layers.weight_init | timm.layers.weight_init |
timm.models.poolformer | none with the same file name |
Modules removed in other releases
| Module | Gone in | Same file in 1.0.31 |
|---|---|---|
timm.layers.activations_jit | 1.0.3 | none with the same file name |
timm.data.parsers.constants | 0.6.5 | timm.data.constants |
timm.models.layers.involution | 0.5.4 | none with the same file name |
timm.models.layers.swin_attn | 0.5.4 | none with the same file name |
timm.optim.novograd | 0.5.4 | none with the same file name |
timm.models.layers.create_self_attn | 0.4.12 | none with the same file name |
timm.models.layers.se | 0.4.12 | none with the same file name |
timm.models.layers.anti_aliasing | 0.4.9 | none with the same file name |
timm.models.adaptive_avgmax_pool | 0.2.1 | timm.layers.adaptive_avgmax_pool |
timm.models.conv2d_same | 0.2.1 | timm.layers.conv2d_same |
timm.models.gen_efficientnet | 0.2.1 | none with the same file name |
timm.models.median_pool | 0.2.1 | timm.layers.median_pool |
timm.models.model_factory | 0.2.1 | none with the same file name |
timm.models.test_time_pool | 0.2.1 | timm.layers.test_time_pool |
79 of the 382 modules that have existed are gone from 1.0.31. Old paths such as timm.models.helpers and timm.models.registry still exist as mapping files that re-export the underscored modules.
The error appears when I load a saved model. What then?
A model saved whole with torch.save(model, path) stores the module path of every class, and loading it imports those paths. A model saved under timm 0.6.13 or older names modules such as timm.models.layers.norm, so loading it with timm 0.9.0 or later raises ModuleNotFoundError from inside pickle (the traceback shows find_class). Load it once with pip install "timm<0.9.0", save model.state_dict(), and from then on build the model with timm.create_model and load the state dict.
How was this read, and how was it checked?
From the source of each release tag, with Python's ast module; no release was installed or imported. timm imports eagerly, so a module's names are everything it binds at module level, including what from timm.layers.x import * brings in. Dates come from PyPI.
Checks, by a second reading: (1) each of the 28 top-level names is found as plain text in __init__.py (or the modules it star-imports) in every release of its range (1,090 name-and-release pairs). (2) A regular expression finds 43,256 definitions in 2,351 file versions; all are among the names read. (3) timm.models.layers was read a second time with regular expressions in all 38 releases where it is a mapping; the names match, apart from torch, nn and F, which a star import without __all__ also passes along. (4) 8 known facts hold, among them the reports under Sources.
Limits
- Nothing was installed or run. "Has it" means the import statement resolves in the source.
- Releases on PyPI without a git tag (the early 0.1.x releases with even numbers and 0.3.0 to 0.3.2) are read from their wheels, with the same rules, and the lookup prints them under the range where they differ from the tagged release before them; the ranges themselves use the tagged releases only.
- A name that works through the 0.9 mapping also prints a FutureWarning; the lookup does not mark that.
Questions
How do I fix "No module named 'timm.models.layers.norm'"?
timm 0.9.0 (2023-05-12) removed the submodules of timm.models.layers; the files moved to timm.layers (timm.layers.norm). The error usually comes from loading a model that was saved whole with torch.save(model) under timm 0.6.13 or older: pickle stores the old module path. Either install pip install "timm<0.9.0" to load it, or load it once there and save model.state_dict() instead, which does not depend on module paths.
How do I fix "No module named 'timm.layers'"?
Your timm is older than 0.9.0. Upgrade with pip install -U "timm>=0.9.0", or, if you must stay on 0.6, import the same names from timm.models.layers.
How do I fix "ModuleNotFoundError: No module named 'timm'"?
That exact message, with nothing after timm, means the Python that runs your code has no timm installed at all; no release removed the top-level package. Install it into that same interpreter with python -m pip install timm (the PyPI package and the import name are both timm). In a notebook, ComfyUI or another program that ships its own Python, run pip with that program's python executable, because the pip on your PATH can belong to a different environment. If the message names a submodule, such as timm.layers or timm.models.layers.norm, timm is installed and the two questions above apply.
Does "from timm.models.layers import X" still work?
For the names that existed when timm.models.layers was moved, yes: timm keeps it as a mapping that warns "Importing from timm.models.layers is deprecated, please import via timm.layers". 127 public names added to timm.layers since then are not in the mapping, so for those the old path fails; import them from timm.layers.
Why does this page read every timm release and not one per minor version?
timm has stayed at 1.0 since 2024 and ships its changes in patch releases (1.0.3 to 1.0.31), so a module or name can appear or go in any of them.
Sources
- huggingface/pytorch-image-models, release tags v0.1.1 to v1.0.31: every
.pyfile under timm/, including the mapping in timm/models/layers/__init__.py; release dates from PyPI. - Reports: No module named 'timm.layers', No module named 'timm.models.layers.norm' (fast.ai forums), the same error while unpickling a model.
The same data as JSON: timm.json, licensed CC BY 4.0.
Related: "cannot import name ... from 'transformers'" · "... from 'huggingface_hub'" · "... from 'datasets'" · "... from 'diffusers'".