huggingface/pytorch-image-models · error · ValueError

Token mixer type: {} not supported

Error message

Token mixer type: {} not supported

What it means

FastViT's network constructor builds each stage block based on a token_mixer_type string (variants like 'conv', 'conv_rep', 'itpool', 'itp', 'attn', etc.). If a stage's token_mixer_type does not match any supported branch, ValueError('Token mixer type: {} not supported') is raised during model construction.

Source

Thrown at timm/models/fastvit.py:1157

                    proj_drop=proj_drop_rate,
                    drop_path=drop_path_rate[block_idx],
                    layer_scale_init_value=layer_scale_init_value,
                    inference_mode=inference_mode,
                    **dd,
                ))
            elif token_mixer_type == "attention":
                blocks.append(AttentionBlock(
                    dim_out,
                    mlp_ratio=mlp_ratio,
                    act_layer=act_layer,
                    norm_layer=norm_layer,
                    proj_drop=proj_drop_rate,
                    drop_path=drop_path_rate[block_idx],
                    layer_scale_init_value=layer_scale_init_value,
                    **dd,
                ))
            else:
                raise ValueError(
                    "Token mixer type: {} not supported".format(token_mixer_type)
                )
        self.blocks = nn.Sequential(*blocks)

    def forward(self, x):
        x = self.downsample(x)
        x = self.pos_emb(x)
        if self.grad_checkpointing and not torch.jit.is_scripting():
            x = checkpoint_seq(self.blocks, x)
        else:
            x = self.blocks(x)
        return x


class FastVit(nn.Module):
    fork_feat: torch.jit.Final[bool]

    """

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Inspect the supported mixer branches in timm/models/fastvit.py above line 1157 and correct the token_mixer_type string
  2. Use the stock fastvit_* factory functions instead of hand-editing architecture configs
  3. Diff your config against the default architecture dict in the same timm version

Example fix

# before
blocks.append(..., token_mixer_type='attention')  # typo
# after
blocks.append(..., token_mixer_type='attn')  # exact supported name
Defensive patterns

Strategy: validation

Validate before calling

import inspect, timm.models.fastvit as fv
src = inspect.getsource(fv)
# safer: hard check against known mixers
allowed = {'conv', 'conv_rep', 'itpool', 'itp', 'itp_rep', 'attn', 'attn_rep'}
assert cfg['token_mixer_type'] in allowed, f"unknown mixer {cfg['token_mixer_type']}"

Type guard

def is_valid_fastvit_mixer(t: str) -> bool:
    allowed = {'conv', 'conv_rep', 'itpool', 'itp', 'itp_rep', 'attn', 'attn_rep'}
    return t in allowed

Try / catch

try:
    model = timm.create_model('fastvit_t8', **cfg)
except ValueError as e:
    if 'not supported' in str(e):
        cfg['token_mixer_type'] = 'conv'  # safe fallback
        model = timm.create_model('fastvit_t8', **cfg)
    else:
        raise

Prevention

When it happens

Trigger: Building FastViT (e.g. fastvit_t8 or the FastViT class directly) with a modified architecture config containing an unknown token_mixer_type, or passing custom stage definitions where a mixer name is misspelled.

Common situations: Editing FastViT arch strings to prototype new mixer types; merging configs across timm versions where mixer names changed; string parsing bugs in YAML/JSON config that truncate or alter the token_mixer_type token.

Related errors


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