huggingface/pytorch-image-models · error · NotImplementedError

Unsupported model {mode}

Error message

Unsupported model {mode}

What it means

MViTv2's patch embedding supports several modes (e.g. 'sweep' / 'max' overlapping-window aggregation, and plain conv) selected by the mode argument; any other string falls through to NotImplementedError(f'Unsupported model {mode}') at construction time.

Source

Thrown at timm/models/mvitv2.py:291

                    padding=padding_kv,
                    groups=dim_conv,
                    bias=False,
                    **dd,
                )
                self.norm_k = norm_layer(dim_conv, **dd)
                self.pool_v = nn.Conv2d(
                    dim_conv,
                    dim_conv,
                    kernel_kv,
                    stride=stride_kv,
                    padding=padding_kv,
                    groups=dim_conv,
                    bias=False,
                    **dd,
                )
                self.norm_v = norm_layer(dim_conv, **dd)
        else:
            raise NotImplementedError(f"Unsupported model {mode}")

        # relative pos embedding
        self.rel_pos_type = rel_pos_type
        if self.rel_pos_type == 'spatial':
            assert feat_size[0] == feat_size[1]
            size = feat_size[0]
            q_size = size // stride_q[1] if len(stride_q) > 0 else size
            kv_size = size // stride_kv[1] if len(stride_kv) > 0 else size
            rel_sp_dim = 2 * max(q_size, kv_size) - 1

            self.rel_pos_h = nn.Parameter(torch.zeros(rel_sp_dim, self.head_dim, **dd))
            self.rel_pos_w = nn.Parameter(torch.zeros(rel_sp_dim, self.head_dim, **dd))
            trunc_normal_tf_(self.rel_pos_h, std=0.02)
            trunc_normal_tf_(self.rel_pos_w, std=0.02)

        self.residual_pooling = residual_pooling

    def forward(self, x, feat_size: List[int]):

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Use one of the supported modes declared in the branches above line 291 (check timm/models/mvitv2.py, typically 'sweep' or 'max')
  2. Create the model through mvitv2_tiny/small/base/base_224 factories, which set mode correctly
  3. Normalize/validate config strings (strip, lower-case) before passing to the constructor

Example fix

# before
embed = PatchEmbedding(..., mode='avg')
# after
embed = PatchEmbedding(..., mode='max')
Defensive patterns

Strategy: validation

Validate before calling

allowed_modes = {'sweep', 'max'}  # per timm.models.mvitv2 branches
mode = cfg.get('mode', 'sweep').strip().lower()
assert mode in allowed_modes, f'unsupported mvitv2 patch-embed mode: {mode}'
embed = PatchEmbedding(..., mode=mode)

Type guard

def is_valid_mvitv2_mode(mode: str) -> bool:
    return isinstance(mode, str) and mode.strip().lower() in {'sweep', 'max'}

Try / catch

try:
    model = timm.create_model('mvitv2_small', **cfg)
except NotImplementedError as e:
    if 'Unsupported model' in str(e):
        cfg['mode'] = 'sweep'
        model = timm.create_model('mvitv2_small', **cfg)
    else:
        raise

Prevention

When it happens

Trigger: Building mvitv2 or the PatchEmbedding class directly with mode set to an unrecognized value (typo like 'avg', 'pool', or empty string), typically in custom configs.

Common situations: Porting MViTv2 configs from another repo where mode names differ; hand-editing video/backbone YAML; whitespace or case differences ('Sweep' vs 'sweep') in config-driven mode names.

Related errors


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