huggingface/pytorch-image-models · error · RuntimeError
Model architecture ({arch_name}) has no pretrained cfg regis
Error message
Model architecture ({arch_name}) has no pretrained cfg registered. What it means
timm's pretrained-configuration lookup could not find any pretrained cfg registered for the given architecture name. Every model registered via register_model has a default pretrained cfg (usually tagged 'default'); if the name is not in _model_default_cfgs at all and allow_unregistered is False, this RuntimeError is raised. It typically means the model name is misspelled, the model was never registered, or timm was imported in a way that skipped model registration.
Source
Thrown at timm/models/_registry.py:336
assert isinstance(module_names, (tuple, list, set))
return any(arch_name in _module_to_models[n] for n in module_names)
def is_model_pretrained(model_name: str) -> bool:
return model_name in _model_has_pretrained
def get_pretrained_cfg(model_name: str, allow_unregistered: bool = True) -> Optional[PretrainedCfg]:
if model_name in _model_pretrained_cfgs:
return deepcopy(_model_pretrained_cfgs[model_name])
arch_name, tag = split_model_name_tag(model_name)
if arch_name in _model_default_cfgs:
# if model arch exists, but the tag is wrong, error out
raise RuntimeError(f'Invalid pretrained tag ({tag}) for {arch_name}.')
if allow_unregistered:
# if model arch doesn't exist, it has no pretrained_cfg registered, allow a default to be created
return None
raise RuntimeError(f'Model architecture ({arch_name}) has no pretrained cfg registered.')
def get_pretrained_cfg_value(model_name: str, cfg_key: str) -> Optional[Any]:
""" Get a specific model default_cfg value by key. None if key doesn't exist.
"""
cfg = get_pretrained_cfg(model_name, allow_unregistered=False)
return getattr(cfg, cfg_key, None)
def get_arch_pretrained_cfgs(model_name: str) -> Dict[str, PretrainedCfg]:
""" Get all pretrained cfgs for a given architecture.
"""
arch_name, _ = split_model_name_tag(model_name)
model_names = _model_with_tags[arch_name]
cfgs = {m: _model_pretrained_cfgs[m] for m in model_names}
return cfgs
View on GitHub (pinned to 9a5261e31b)
Solutions
- Verify the exact name via timm.list_models() (optionally with a filter like timm.list_models('*coat*')) and correct the string
- If it is a custom model, pass pretrained_cfgs (or a default cfg) when calling register_model
- Pass allow_unregistered=True if you intentionally want a cfg-less model (only valid through APIs that expose the flag)
- Pin/upgrade timm to a version that contains the model you expect
Example fix
# before
model = timm.create_model('resnet50v', pretrained=True)
# after
import timm
print([m for m in timm.list_models('*resnet50*')])
model = timm.create_model('resnet50s', pretrained=True) Defensive patterns
Strategy: validation
Validate before calling
import timm
valid = set(timm.list_models(pretrained=True))
if name not in valid:
close = timm.list_models(f'{name[:6]}*')
raise KeyError(f'{name} unknown; candidates: {close}')
model = timm.create_model(name, pretrained=True) Type guard
def is_registered_timm_model(name: str) -> bool:
import timm
return name in set(timm.list_models()) Try / catch
try:
cfg = timm.resolve_pretrained_cfg(name)
except RuntimeError as e:
# fall back to offline/custom weights or corrected name
suggestions = timm.list_models(name[:5] + '*')
name = suggestions[0]
cfg = timm.resolve_pretrained_cfg(name) Prevention
- Keep an allowlist of model names generated from timm.list_models() in config validation
- Pin the timm version in requirements so model-name availability is stable
- Run a smoke-test at app startup that resolves pretrained cfgs for all configured models
When it happens
Trigger: Calling timm.create_model('nonexistent_or_typo_arch', pretrained=True), timm.resolve_pretrained_cfg('bad_name'), or timm.get_pretrained_cfg_value('bad_name', 'input_size') where the arch string does not match any registered model.
Common situations: Typos in model names ('resnet50' vs 'resnet_50'), referencing a model removed/renamed in a newer timm release, custom models registered with register_model but no pretrained_cfgs argument, or partial imports that bypass timm.models register decorators.
Related errors
- batch_sizes must contain at least one value.
- Cannot initialize position embeddings without grid_size.Plea
- Unknown rope_type: {cfg.rope_type}
- Invalid net configuration
- Unrecognized union:
AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27).
Data as JSON: /api/errors/68cf0d6c092e08ea.
Report an issue: GitHub.