huggingface/pytorch-image-models · error · ValueError
Invalid local_mbconv_norm={local_mbconv_norm!r}; expected on
Error message
Invalid local_mbconv_norm={local_mbconv_norm!r}; expected one of {tuple(_LOCAL_MBCONV_NORM_MODES)}. What it means
CPoTBone (cpubone.py) validates the local_mbconv_norm argument against a fixed set of modes (_LOCAL_MBCONV_NORM_MODES, e.g. 'none', 'first', 'last', 'all' style keys mapping to which MBConv sub-blocks get norm). Any string outside that tuple raises ValueError at construction time.
Source
Thrown at timm/models/cpubone.py:39
from ._features import feature_take_indices
from ._features_fx import register_notrace_module
from ._manipulate import checkpoint_seq
from ._registry import register_model, generate_default_cfgs
__all__ = ['CPUBone']
_LOCAL_MBCONV_NORM_MODES = {
# mode: (expand, depthwise, project)
'proj': (False, False, True),
'depth_proj': (False, True, True),
'all': (True, True, True),
}
def _check_local_mbconv_norm(local_mbconv_norm: str) -> None:
if local_mbconv_norm not in _LOCAL_MBCONV_NORM_MODES:
raise ValueError(
f'Invalid local_mbconv_norm={local_mbconv_norm!r}; '
f'expected one of {tuple(_LOCAL_MBCONV_NORM_MODES)}.'
)
def _check_global_pool(global_pool: str) -> None:
assert global_pool in ("", "avg"), "CPUBone only supports average or disabled pooling"
def remap_legacy_state_dict(state_dict: Dict[str, torch.Tensor]) -> Dict[str, torch.Tensor]:
"""Remap keys from original CPUBone checkpoints to the current model layout."""
remapped = {}
for k, v in state_dict.items():
# conv_proj was nn.Sequential([conv, bn]) → now ConvLayer with .conv / .bn
k = k.replace(".conv_proj.0.", ".conv_proj.conv.")
k = k.replace(".conv_proj.1.", ".conv_proj.norm.")
# pwise was a single-element nn.Sequential → now a plain nn.Conv2d
k = k.replace(".pwise.0.", ".pwise.")View on GitHub (pinned to 9a5261e31b)
Solutions
- Print tuple(_LOCAL_MBCONV_NORM_MODES) from timm.models.cpubone and use one of those exact keys
- Check the model's pretrained cfg / docs for the default value and revert to it
- Update timm if the mode you want exists in a newer release
Example fix
# before
model = timm.create_model('cputbone_s', local_mbconv_norm='first-last')
# after
from timm.models.cpubone import _LOCAL_MBCONV_NORM_MODES
model = timm.create_model('cputbone_s', local_mbconv_norm=list(_LOCAL_MBCONV_NORM_MODES)[0]) Defensive patterns
Strategy: validation
Validate before calling
from timm.models.cpubone import _LOCAL_MBCONV_NORM_MODES
if cfg['local_mbconv_norm'] not in _LOCAL_MBCONV_NORM_MODES:
raise ValueError(f"local_mbconv_norm must be one of {tuple(_LOCAL_MBCONV_NORM_MODES)}")
model = timm.create_model('cputbone_s', **cfg) Type guard
def is_valid_local_mbconv_norm(v: str) -> bool:
from timm.models.cpubone import _LOCAL_MBCONV_NORM_MODES
return v in _LOCAL_MBCONV_NORM_MODES Prevention
- Import valid mode names from the module rather than hardcoding strings
- Validate string-enum config fields at load time
- Add schema validation for experiment configs
When it happens
Trigger: Instantiating cputbone_s or CPoTBone with local_mbconv_norm set to an unrecognized string (e.g. 'first-last', 'norm', typo like 'fisrt').
Common situations: Hand-writing config YAML/JSON for backbone experiments; copying a norm-mode name from a different model family; version drift if valid mode names changed between timm releases.
Related errors
- Input image must have positive dimensions, got H={height}, W
- All scheduled batch sizes must be positive integers.
- num_batches must be a positive integer when specified.
- A progressive schedule requires at least two choices.
- schedule_epochs must be a positive integer for a progressive
AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27).
Data as JSON: /api/errors/acbf6e705799bff0.
Report an issue: GitHub.