{"record":{"id":"4ce354fa36a4847b","repo":"Comfy-Org/ComfyUI","slug":"unsupported-dimensions-dims-4ce354","errorCode":null,"errorMessage":"unsupported dimensions: {dims}","messagePattern":"unsupported dimensions: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/modules/diffusionmodules/util.py","lineNumber":287,"sourceCode":"\ndef mean_flat(tensor):\n    \"\"\"\n    Take the mean over all non-batch dimensions.\n    \"\"\"\n    return tensor.mean(dim=list(range(1, len(tensor.shape))))\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:\n        return nn.AvgPool3d(*args, **kwargs)\n    raise ValueError(f\"unsupported dimensions: {dims}\")\n\n\nclass HybridConditioner(nn.Module):\n\n    def __init__(self, c_concat_config, c_crossattn_config):\n        super().__init__()\n        self.concat_conditioner = instantiate_from_config(c_concat_config)\n        self.crossattn_conditioner = instantiate_from_config(c_crossattn_config)\n\n    def forward(self, c_concat, c_crossattn):\n        c_concat = self.concat_conditioner(c_concat)\n        c_crossattn = self.crossattn_conditioner(c_crossattn)\n        return {'c_concat': [c_concat], 'c_crossattn': [c_crossattn]}\n\n\ndef noise_like(shape, device, repeat=False):\n    repeat_noise = lambda: torch.randn((1, *shape[1:]), device=device).repeat(shape[0], *((1,) * (len(shape) - 1)))\n    noise = lambda: torch.randn(shape, device=device)","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/modules/diffusionmodules/util.py#L269-L305","documentation":"avg_pool_nd is a factory helper used by ComfyUI's diffusionmodules (Upsample/Downsample blocks) that maps an integer 'dims' to the matching torch AvgPool{1,2,3}d module. It raises ValueError when 'dims' is anything other than the literal integers 1, 2, or 3. In practice the value comes from model YAML/config (e.g. the 'dims' key of a UNet/VAE config), so this error almost always means a malformed or unsupported config rather than bad tensor data.","triggerScenarios":"Calling comfy.ldm.modules.diffusionmodules.util.avg_pool_nd(dims, ...) with dims == 0, dims >= 4, a string like \"2\", or None. Happens transitively when instantiate_from_config builds an Upsample/Downsample whose parameters.dims is missing or mistyped, e.g. params: {dims: \"2\"} in the checkpoint's YAML config.","commonSituations":"Hand-edited or community-shared SD1.x/SD2.x UNet config YAML with a typo in the dims field; a config generated for a different codebase that uses \"dimensions\" or \"dim\" instead of \"dims\"; JSON configs that store dims as a string.","solutions":["Inspect the model's embedded config (the YAML inside the diffusion checkpoint) and verify the dims key under the Upsample/Downsample block parameters is the integer 2 for image models (3 for video models).","If dims arrived as a string, change the config value to an unquoted integer, e.g. dims: 2 not dims: \"2\".","If the checkpoint really targets a non-standard architecture ComfyUI does not support, re-export or download the correct checkpoint variant instead of patching dims.","Only if you are writing custom model code, validate dims at config-parse time and fail with a clearer message before model construction."],"exampleFix":"// before (config yaml)\nparams:\n  dims: \"2\"\n// after\nparams:\n  dims: 2","handlingStrategy":"validation","validationCode":"def build_pool(dims, *args, **kwargs):\n    if not isinstance(dims, int) or dims not in (1, 2, 3):\n        raise ValueError(f\"dims must be int 1, 2, or 3, got {dims!r} — check model config\")\n    return avg_pool_nd(dims, *args, **kwargs)","typeGuard":"def is_valid_pool_dims(dims) -> bool:\n    return isinstance(dims, int) and not isinstance(dims, bool) and dims in (1, 2, 3)","tryCatchPattern":null,"preventionTips":["Validate the 'dims' field of every Upsample/Downsample block when parsing model config YAML, before instantiate_from_config.","Keep model configs as Python/YAML integers, never quoted strings.","Use configs embedded in official checkpoints rather than hand-written ones."],"tags":["config","validation","diffusionmodules","model-loading"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}