huggingface/pytorch-image-models · warning

Overwriting {model_name} in registry with {fn.__module__}.{m

Error message

Overwriting {model_name} in registry with {fn.__module__}.{model_name}. This is because the name being registered conflicts with an existing name. Please check if this is not expected.

What it means

timm's model registry warns whenever a model name is registered twice, overwriting the previous entrypoint. This happens when two @register_model-decorated functions share the same name (often across different modules). The registry silently keeps only the last one, which may not be what you want.

Source

Thrown at timm/models/_registry.py:90

    return out


def register_model(fn: Callable[..., Any]) -> Callable[..., Any]:
    # lookup containing module
    mod = sys.modules[fn.__module__]
    module_name_split = fn.__module__.split('.')
    module_name = module_name_split[-1] if len(module_name_split) else ''

    # add model to __all__ in module
    model_name = fn.__name__
    if hasattr(mod, '__all__'):
        mod.__all__.append(model_name)
    else:
        mod.__all__ = [model_name]  # type: ignore

    # add entries to registry dict/sets
    if model_name in _model_entrypoints:
        warnings.warn(
            f'Overwriting {model_name} in registry with {fn.__module__}.{model_name}. This is because the name being '
            'registered conflicts with an existing name. Please check if this is not expected.',
            stacklevel=2,
        )
    _model_entrypoints[model_name] = fn
    _model_to_module[model_name] = module_name
    _module_to_models[module_name].add(model_name)
    if hasattr(mod, 'default_cfgs') and model_name in mod.default_cfgs:
        # this will catch all models that have entrypoint matching cfg key, but miss any aliasing
        # entrypoints or non-matching combos
        default_cfg = mod.default_cfgs[model_name]
        if not isinstance(default_cfg, DefaultCfg):
            # new style default cfg dataclass w/ multiple entries per model-arch
            assert isinstance(default_cfg, dict)
            # old style cfg dict per model-arch
            pretrained_cfg = PretrainedCfg(**default_cfg)
            default_cfg = DefaultCfg(tags=deque(['']), cfgs={'': pretrained_cfg})

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Rename your custom model function (the registry key is the function name) so it does not collide with the built-in name
  2. If overriding is intentional, filter/suppress the warning with warnings.filterwarnings around the import
  3. Check timm.list_models() and the module of the registered entrypoint (timm.models._registry) to identify which module is overwriting which

Example fix

// before
@register_model
def vit_small_patch16_224(pretrained=False, **kwargs):  # collides with timm
    ...
// after
@register_model
def my_vit_small_patch16_224(pretrained=False, **kwargs):
    ...
Defensive patterns

Strategy: validation

Validate before calling

import timm
from timm.models._registry import _model_entrypoints
name = 'vit_small_patch16_224'
if name in _model_entrypoints:
    print('already registered by', _model_entrypoints[name].__module__)  # rename yours if it's not yours

Prevention

When it happens

Trigger: Two functions decorated with @register_model produce the same model_name (e.g. defining a custom 'vit_small_patch16_224' while timm already registers one); re-registering an existing timm model under its own name; plugin packages colliding with built-in names.

Common situations: Custom model forks that keep the original function name, duplicated modules both imported, refactors that copy a model file and import both copies, or downstream libraries overriding timm models unintentionally.

Related errors


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