hpcaitech/Open-Sora · error · ValueError

Unsupported input dimension: {x.dim()}

Error message

Unsupported input dimension: {x.dim()}

What it means

PixelUnshuffleChannelAveragingDownSampleLayer.forward only handles 4D (B,C,H,W) and 5D (B,C,T,H,W) inputs; other rank tensors raise this ValueError. The branch chosen also depends on temporal_downsample, so an incorrectly shaped tensor (e.g. an unbroadcast feature map or a 3D tensor) fails this check.

Source

Thrown at opensora/models/dc_ae/models/nn/ops.py:227

            x = x.view(B, self.out_channels, group_size, H, W)
            x = x.mean(dim=2)
        elif x.dim() == 5:  # [B, C, T, H, W]
            _, _, T, _, _ = x.shape
            if self.temporal_downsample and T != 1:  # 3d pixel unshuffle
                x = pixel_unshuffle_3d(x, self.factor)
                assert self.in_channels * self.factor**3 % self.out_channels == 0
                group_size = self.in_channels * self.factor**3 // self.out_channels
            else:  # 2d pixel unshuffle
                x = x.permute(0, 2, 1, 3, 4)  # [B, T, C, H, W]
                x = F.pixel_unshuffle(x, self.factor)
                x = x.permute(0, 2, 1, 3, 4)  # [B, C, T, H, W]
                assert self.in_channels * self.factor**2 % self.out_channels == 0
                group_size = self.in_channels * self.factor**2 // self.out_channels
            B, C, T, H, W = x.shape
            x = x.view(B, self.out_channels, group_size, T, H, W)
            x = x.mean(dim=2)
        else:
            raise ValueError(f"Unsupported input dimension: {x.dim()}")
        return x

    def __repr__(self):
        return f"PixelUnshuffleChannelAveragingDownSampleLayer(in_channels={self.in_channels}, out_channels={self.out_channels}, factor={self.factor}), temporal_downsample={self.temporal_downsample}"


class ConvPixelShuffleUpSampleLayer(nn.Module):
    def __init__(
        self,
        in_channels: int,
        out_channels: int,
        kernel_size: int,
        factor: int,
    ):
        super().__init__()
        self.factor = factor
        out_ratio = factor**2
        self.conv = ConvLayer(

View on GitHub (pinned to 7ad6a96a13)

Solutions

  1. Ensure input is 4D (B,C,H,W) or 5D (B,C,T,H,W) with an explicit batch dimension
  2. Check upstream transforms for squeeze/view calls that drop a dimension
  3. For single samples pass x.unsqueeze(0)

Example fix

# before
x = frame_3d  # (C,H,W)
y = layer(x)
# after
x = frame_3d.unsqueeze(0)  # (1,C,H,W)
y = layer(x)
Defensive patterns

Strategy: type-guard

Validate before calling

if x.dim() not in (4, 5):
    raise ValueError(f'expected 4D/5D input, got {tuple(x.shape)}')

Type guard

def is_valid_offload_shape(x: torch.Tensor) -> bool:
    return x.dim() in (4, 5)

Prevention

When it happens

Trigger: Feeding a tensor with dim() != 4 and != 5 into the averaging shortcut layer, e.g. a per-frame 3D tensor or a 6D tensor from prior reshaping; occurs during encoder forward/downsample shortcut computation.

Common situations: Custom preprocessing that squeezes the batch or time dimension; feeding single images without a batch dim; intermediate reshapes that change tensor rank before the autoencoder.

Related errors


AI-assisted analysis of hpcaitech/Open-Sora@7ad6a96a13 (2026-08-28). Data as JSON: /api/errors/0090541f1f5b03c3. Report an issue: GitHub.