Stability-AI/generative-models · error · ValueError

unsupported dimensions: {dims}

Error message

unsupported dimensions: {dims}

What it means

conv_nd is a factory helper in sgm/modules/diffusionmodules/util.py that maps a dimensionality integer (1, 2, or 3) to nn.Conv1d/Conv2d/Conv3d. If the dims argument is anything else (0, 4, a string, None), it raises ValueError('unsupported dimensions: {dims}'). The library only supports 1D/2D/3D convolutions, so any other value is rejected at module construction time.

Source

Thrown at sgm/modules/diffusionmodules/util.py:319

        return x * torch.sigmoid(x)


class GroupNorm32(nn.GroupNorm):
    def forward(self, x):
        return super().forward(x.float()).type(x.dtype)


def conv_nd(dims, *args, **kwargs):
    """
    Create a 1D, 2D, or 3D convolution module.
    """
    if dims == 1:
        return nn.Conv1d(*args, **kwargs)
    elif dims == 2:
        return nn.Conv2d(*args, **kwargs)
    elif dims == 3:
        return nn.Conv3d(*args, **kwargs)
    raise ValueError(f"unsupported dimensions: {dims}")


def linear(*args, **kwargs):
    """
    Create a linear module.
    """
    return nn.Linear(*args, **kwargs)


def avg_pool_nd(dims, *args, **kwargs):
    """
    Create a 1D, 2D, or 3D average pooling module.
    """
    if dims == 1:
        return nn.AvgPool1d(*args, **kwargs)
    elif dims == 2:
        return nn.AvgPool2d(*args, **kwargs)
    elif dims == 3:

View on GitHub (pinned to e8cd657656)

Solutions

  1. Set dims to 1, 2, or 3 in the model config (for video models typically dims=3, for image models dims=2).
  2. Ensure the value is an int, not a string or None: cast with int(dims) before constructing the module.
  3. Check the config source for typos or missing defaults (e.g. omegaconf null values).

Example fix

// before
net = conv_nd(cfg.dims, 3, 64, 3)  # cfg.dims == "4"
// after
dims = int(cfg.dims)
assert dims in (1, 2, 3), f"dims must be 1, 2 or 3, got {dims}"
net = conv_nd(dims, 3, 64, 3)
Defensive patterns

Strategy: validation

Validate before calling

dims = int(config.get("dims", 2))
if dims not in (1, 2, 3):
    raise ValueError(f"dims must be 1, 2 or 3, got {dims!r}")

Type guard

def is_valid_dims(d) -> bool:
    return isinstance(d, int) and d in (1, 2, 3)

Try / catch

try:
    conv = conv_nd(dims, in_ch, out_ch, 3)
except ValueError as e:
    logger.error("bad dims for conv_nd: %s", e)
    conv = conv_nd(2, in_ch, out_ch, 3)  # sane default

Prevention

When it happens

Trigger: Calling conv_nd(dims, ...) with dims not in {1,2,3} — e.g. passing dims=4, a string like '2d', or None — typically via Conv2DWrap or UNetModel/MultiViewEncoder construction where the dims config value is malformed.

Common situations: Config YAML where model.params.dims is mistyped (e.g. '2' as a string instead of 2), copied configs edited for a hypothetical 4D model, or None leaking from an optional config field.

Related errors


AI-assisted analysis of Stability-AI/generative-models@e8cd657656 (2026-08-29). Data as JSON: /api/errors/85c74a6ea460b61b. Report an issue: GitHub.