huggingface/pytorch-image-models · error · ValueError

The output channel {self.output_size} is different from the

Error message

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

What it means

For union='add', the two RNN branches are summed, so output_size must equal input_size. A mismatch means the residual/add path would change channel count and construction aborts.

Source

Thrown at timm/models/sequencer.py:114

                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()

    def forward(self, x):
        B, H, W, C = x.shape

        if self.with_vertical:

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Set output_size = input_size for 'add' blocks
  2. Or use union='cat' with output_size = input_size // 2 when you need a width change

Example fix

# before
SequencerBlock(dim, dim * 2, union='add')
# after
SequencerBlock(dim, dim, union='add')
Defensive patterns

Strategy: validation

Validate before calling

if union == 'add':
    assert output_size == input_size, 'add requires output_size == input_size'

Prevention

When it happens

Trigger: SequencerBlock(union='add') with output_size != input_size, e.g. trying to change widths mid-stage while reusing an 'add' block config.

Common situations: Scaling sequencer widths per stage but copying a block template that uses union='add'.

Related errors


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