{"record":{"id":"85c74a6ea460b61b","repo":"Stability-AI/generative-models","slug":"unsupported-dimensions-dims","errorCode":null,"errorMessage":"unsupported dimensions: {dims}","messagePattern":"unsupported dimensions: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sgm/modules/diffusionmodules/util.py","lineNumber":319,"sourceCode":"        return x * torch.sigmoid(x)\n\n\nclass GroupNorm32(nn.GroupNorm):\n    def forward(self, x):\n        return super().forward(x.float()).type(x.dtype)\n\n\ndef conv_nd(dims, *args, **kwargs):\n    \"\"\"\n    Create a 1D, 2D, or 3D convolution module.\n    \"\"\"\n    if dims == 1:\n        return nn.Conv1d(*args, **kwargs)\n    elif dims == 2:\n        return nn.Conv2d(*args, **kwargs)\n    elif dims == 3:\n        return nn.Conv3d(*args, **kwargs)\n    raise ValueError(f\"unsupported dimensions: {dims}\")\n\n\ndef linear(*args, **kwargs):\n    \"\"\"\n    Create a linear module.\n    \"\"\"\n    return nn.Linear(*args, **kwargs)\n\n\ndef avg_pool_nd(dims, *args, **kwargs):\n    \"\"\"\n    Create a 1D, 2D, or 3D average pooling module.\n    \"\"\"\n    if dims == 1:\n        return nn.AvgPool1d(*args, **kwargs)\n    elif dims == 2:\n        return nn.AvgPool2d(*args, **kwargs)\n    elif dims == 3:","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/Stability-AI/generative-models/blob/e8cd657656fa5d61688191730d0e03242bf4ed44/sgm/modules/diffusionmodules/util.py#L301-L337","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set dims to 1, 2, or 3 in the model config (for video models typically dims=3, for image models dims=2).","Ensure the value is an int, not a string or None: cast with int(dims) before constructing the module.","Check the config source for typos or missing defaults (e.g. omegaconf null values)."],"exampleFix":"// before\nnet = conv_nd(cfg.dims, 3, 64, 3)  # cfg.dims == \"4\"\n// after\ndims = int(cfg.dims)\nassert dims in (1, 2, 3), f\"dims must be 1, 2 or 3, got {dims}\"\nnet = conv_nd(dims, 3, 64, 3)","handlingStrategy":"validation","validationCode":"dims = int(config.get(\"dims\", 2))\nif dims not in (1, 2, 3):\n    raise ValueError(f\"dims must be 1, 2 or 3, got {dims!r}\")","typeGuard":"def is_valid_dims(d) -> bool:\n    return isinstance(d, int) and d in (1, 2, 3)","tryCatchPattern":"try:\n    conv = conv_nd(dims, in_ch, out_ch, 3)\nexcept ValueError as e:\n    logger.error(\"bad dims for conv_nd: %s\", e)\n    conv = conv_nd(2, in_ch, out_ch, 3)  # sane default","preventionTips":["Keep dims as an int in config schemas; forbid strings/nulls.","Assert dims in (1,2,3) at config load time, before model construction.","Don't hand-edit dims in shared YAMLs; use typed config validation (omegaconf StructuredConfig)."],"tags":["pytorch","valueerror","configuration"],"backgroundTag":"unsupported-dimension-value","analyzedSha":"e8cd657656fa5d61688191730d0e03242bf4ed44","analyzedAt":"2026-08-29T11:23:43.234Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}