huggingface/pytorch-image-models · error · ValueError

Unrecognized union:

Error message

Unrecognized union: 

What it means

SequencerBlock's union argument must be one of 'add', 'cat', 'vertical', 'horizontal' (plus the dual-branch path handled above). Anything else raises 'Unrecognized union'.

Source

Thrown at timm/models/sequencer.py:106

        self.with_vertical = True
        self.with_horizontal = True
        self.with_fc = with_fc

        self.fc = None
        if with_fc:
            if union == "cat":
                self.fc = nn.Linear(2 * self.output_size, input_size, **dd)
            elif union == "add":
                self.fc = nn.Linear(self.output_size, input_size, **dd)
            elif union == "vertical":
                self.fc = nn.Linear(self.output_size, input_size, **dd)
                self.with_horizontal = False
            elif union == "horizontal":
                self.fc = nn.Linear(self.output_size, input_size, **dd)
                self.with_vertical = False
            else:
                raise ValueError("Unrecognized union: " + union)
        elif union == "cat":
            pass
            if 2 * self.output_size != input_size:
                raise ValueError(f"The output channel {2 * self.output_size} is different from the input channel {input_size}.")
        elif union == "add":
            pass
            if self.output_size != input_size:
                raise ValueError(f"The output channel {self.output_size} is different from the input channel {input_size}.")
        elif union == "vertical":
            if self.output_size != input_size:
                raise ValueError(f"The output channel {self.output_size} is different from the input channel {input_size}.")
            self.with_horizontal = False
        elif union == "horizontal":
            if self.output_size != input_size:
                raise ValueError(f"The output channel {self.output_size} is different from the input channel {input_size}.")
            self.with_vertical = False
        else:
            raise ValueError("Unrecognized union: " + union)

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Use only 'add', 'cat', 'vertical', or 'horizontal'
  2. Keep the stock union= configuration from the pretrained sequencer variants unless you retrain

Example fix

# before
union='concat'
# after
union='cat'
Defensive patterns

Strategy: validation

Validate before calling

assert union in ('add', 'cat', 'vertical', 'horizontal')

Type guard

def is_valid_union(u: str) -> bool:
    return u in {'add', 'cat', 'vertical', 'horizontal'}

Prevention

When it happens

Trigger: Instantiating Sequencer/SequencerBlock with union='concat', 'sum', or a typo; typically via custom model configs overriding the union sequence.

Common situations: Editing sequencer layer lists (the model alternates 'vertical'/'horizontal' unions by depth) and introducing an invalid string.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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