{"record":{"id":"8a47938c1e3471f9","repo":"Comfy-Org/ComfyUI","slug":"provide-num-res-blocks-either-as-an-int-globally","errorCode":null,"errorMessage":"provide num_res_blocks either as an int (globally constant) or as a list/tuple (per-level) with the same length as channel_mult","messagePattern":"provide num_res_blocks either as an int \\(globally constant\\) or as a list/tuple \\(per-level\\) with the same length as channel_mult","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/modules/diffusionmodules/openaimodel.py","lineNumber":476,"sourceCode":"\n        if num_heads_upsample == -1:\n            num_heads_upsample = num_heads\n\n        if num_heads == -1:\n            assert num_head_channels != -1, 'Either num_heads or num_head_channels has to be set'\n\n        if num_head_channels == -1:\n            assert num_heads != -1, 'Either num_heads or num_head_channels has to be set'\n\n        self.in_channels = in_channels\n        self.model_channels = model_channels\n        self.out_channels = out_channels\n\n        if isinstance(num_res_blocks, int):\n            self.num_res_blocks = len(channel_mult) * [num_res_blocks]\n        else:\n            if len(num_res_blocks) != len(channel_mult):\n                raise ValueError(\"provide num_res_blocks either as an int (globally constant) or \"\n                                 \"as a list/tuple (per-level) with the same length as channel_mult\")\n            self.num_res_blocks = num_res_blocks\n\n        if disable_self_attentions is not None:\n            # should be a list of booleans, indicating whether to disable self-attention in TransformerBlocks or not\n            assert len(disable_self_attentions) == len(channel_mult)\n        if num_attention_blocks is not None:\n            assert len(num_attention_blocks) == len(self.num_res_blocks)\n\n        transformer_depth = transformer_depth[:]\n        transformer_depth_output = transformer_depth_output[:]\n\n        self.dropout = dropout\n        self.channel_mult = channel_mult\n        self.conv_resample = conv_resample\n        self.num_classes = num_classes\n        self.use_checkpoint = use_checkpoint\n        self.dtype = dtype","sourceCodeStart":458,"sourceCodeEnd":494,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/modules/diffusionmodules/openaimodel.py#L458-L494","documentation":"Raised by UNetModel (openaimodel.py) when num_res_blocks is given as a list/tuple whose length differs from channel_mult. The constructor accepts either one int (applied to all levels) or a per-level sequence that must align 1:1 with channel_mult; a mismatch means the config is ambiguous and construction aborts.","triggerScenarios":"Passing num_res_blocks=[2,2,2,2] with channel_mult=[1,2,4,6] (length 4 vs 3), or a truncated/extended per-level list from an edited config.","commonSituations":"Hand-tuning SD-style UNet configs for depth; porting configs between model variants (base vs depth variants list different channel_mult lengths); diffusers-to-ComfyUI config conversions dropping or adding a level.","solutions":["Make len(num_res_blocks) == len(channel_mult), or pass a single int","Diff the config against the original checkpoint's config to find which level list drifted","If you added a channel_mult level, add the matching num_res_blocks entry"],"exampleFix":"# before\nUNetModel(channel_mult=(1, 2, 4, 8), num_res_blocks=[2, 2, 2])\n# after\nUNetModel(channel_mult=(1, 2, 4, 8), num_res_blocks=[2, 2, 2, 2])","handlingStrategy":"validation","validationCode":"if isinstance(num_res_blocks, (list, tuple)) and len(num_res_blocks) != len(channel_mult):\n    raise ValueError(f'num_res_blocks len {len(num_res_blocks)} != channel_mult len {len(channel_mult)}')\nmodel = UNetModel(num_res_blocks=num_res_blocks, channel_mult=channel_mult)","typeGuard":"def num_res_blocks_valid(nrb, channel_mult) -> bool:\n    return isinstance(nrb, int) or len(nrb) == len(channel_mult)","tryCatchPattern":null,"preventionTips":["Validate per-level config lists (num_res_blocks, channel_mult, attentions) for equal length before constructing UNets","When editing configs, change levels in all aligned lists together"],"tags":["unet","config","validation","model-loading"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}