{"record":{"id":"1c81f92d9a7cf4b3","repo":"huggingface/pytorch-image-models","slug":"overwriting-model-name-in-registry-with-fn-mo","errorCode":null,"errorMessage":"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.","messagePattern":"Overwriting (.+?) in registry with (.+?)\\.(.+?)\\. This is because the name being registered conflicts with an existing name\\. Please check if this is not expected\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"timm/models/_registry.py","lineNumber":90,"sourceCode":"    return out\n\n\ndef register_model(fn: Callable[..., Any]) -> Callable[..., Any]:\n    # lookup containing module\n    mod = sys.modules[fn.__module__]\n    module_name_split = fn.__module__.split('.')\n    module_name = module_name_split[-1] if len(module_name_split) else ''\n\n    # add model to __all__ in module\n    model_name = fn.__name__\n    if hasattr(mod, '__all__'):\n        mod.__all__.append(model_name)\n    else:\n        mod.__all__ = [model_name]  # type: ignore\n\n    # add entries to registry dict/sets\n    if model_name in _model_entrypoints:\n        warnings.warn(\n            f'Overwriting {model_name} in registry with {fn.__module__}.{model_name}. This is because the name being '\n            'registered conflicts with an existing name. Please check if this is not expected.',\n            stacklevel=2,\n        )\n    _model_entrypoints[model_name] = fn\n    _model_to_module[model_name] = module_name\n    _module_to_models[module_name].add(model_name)\n    if hasattr(mod, 'default_cfgs') and model_name in mod.default_cfgs:\n        # this will catch all models that have entrypoint matching cfg key, but miss any aliasing\n        # entrypoints or non-matching combos\n        default_cfg = mod.default_cfgs[model_name]\n        if not isinstance(default_cfg, DefaultCfg):\n            # new style default cfg dataclass w/ multiple entries per model-arch\n            assert isinstance(default_cfg, dict)\n            # old style cfg dict per model-arch\n            pretrained_cfg = PretrainedCfg(**default_cfg)\n            default_cfg = DefaultCfg(tags=deque(['']), cfgs={'': pretrained_cfg})\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/models/_registry.py#L72-L108","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Rename your custom model function (the registry key is the function name) so it does not collide with the built-in name","If overriding is intentional, filter/suppress the warning with warnings.filterwarnings around the import","Check timm.list_models() and the module of the registered entrypoint (timm.models._registry) to identify which module is overwriting which"],"exampleFix":"// before\n@register_model\ndef vit_small_patch16_224(pretrained=False, **kwargs):  # collides with timm\n    ...\n// after\n@register_model\ndef my_vit_small_patch16_224(pretrained=False, **kwargs):\n    ...","handlingStrategy":"validation","validationCode":"import timm\nfrom timm.models._registry import _model_entrypoints\nname = 'vit_small_patch16_224'\nif name in _model_entrypoints:\n    print('already registered by', _model_entrypoints[name].__module__)  # rename yours if it's not yours","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give custom models unique names distinct from timm's catalog","Check timm.list_models(filter='your_prefix') after registering","Treat this warning as a build-time signal in CI: fail on new warnings"],"tags":["timm","registry","duplicate","model-registration"],"backgroundTag":"duplicate-registry-entry","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}