huggingface/pytorch-image-models · error · ValueError

The output channel {2 * self.output_size} is different from

Error message

The output channel {2 * self.output_size} is different from the input channel {input_size}.

What it means

For union='cat', the block concatenates vertical and horizontal RNN branch outputs, so the input channel dimension must equal exactly 2 * output_size. If input_size != 2*output_size the shapes cannot be concatenated consistently and init fails.

Source

Thrown at timm/models/sequencer.py:110

        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)

        self.rnn_v = RNNIdentity()
        self.rnn_h = RNNIdentity()

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Set output_size = input_size // 2 for the cat block
  2. Or switch union to 'add'/'vertical'/'horizontal' where output_size must equal input_size
  3. Revert to the pretrained variant's stock dims

Example fix

# before
SequencerBlock(dim, dim // 4, union='cat')
# after
SequencerBlock(dim, dim // 2, union='cat')
Defensive patterns

Strategy: validation

Validate before calling

if union == 'cat':
    assert input_size == 2 * output_size, 'cat requires input_size == 2 * output_size'

Prevention

When it happens

Trigger: Configuring a SequencerBlock(union='cat') where the preceding layer's dim (input_size) is not twice this block's output_size — e.g. hand-edited channel progression between stages.

Common situations: Customizing sequencer depths/dims without scaling paired stages so that channels double/halve correctly at cat junctions.

Related errors


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