{"record":{"id":"703eb54d54d58822","repo":"lllyasviel/ControlNet","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":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"cldm/cldm.py","lineNumber":106,"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.dims = dims\n        self.image_size = image_size\n        self.in_channels = in_channels\n        self.model_channels = model_channels\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        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            assert all(map(lambda i: self.num_res_blocks[i] >= num_attention_blocks[i], range(len(num_attention_blocks))))\n            print(f\"Constructor of UNetModel received num_attention_blocks={num_attention_blocks}. \"\n                  f\"This option has LESS priority than attention_resolutions {attention_resolutions}, \"\n                  f\"i.e., in cases where num_attention_blocks[i] > 0 but 2**i not in attention_resolutions, \"\n                  f\"attention will still not be set.\")\n\n        self.attention_resolutions = attention_resolutions\n        self.dropout = dropout\n        self.channel_mult = channel_mult\n        self.conv_resample = conv_resample\n        self.use_checkpoint = use_checkpoint","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/lllyasviel/ControlNet/blob/ed85cd1e25a5ed592f7d8178495b4483de0331bf/cldm/cldm.py#L88-L124","documentation":"In ControlNet's LatentDiffusion (cldm.py), num_res_blocks may be an int (same count at every resolution level) or a per-level list whose length must equal channel_mult. This ValueError enforces that 1:1 correspondence.","triggerScenarios":"Instantiating the ControlUNetModel with num_res_blocks as a list shorter/longer than channel_mult, e.g. channel_mult=(1,2,4,4) with num_res_blocks=[2,2,2].","commonSituations":"Editing ControlNet configs (train-img2img, control sd v15 yaml) and changing channel_mult without updating num_res_blocks; copying configs between models with different depth.","solutions":["Match lengths: num_res_blocks=[2,2,2,2] for channel_mult of length 4","Or pass a single int (e.g. num_res_blocks=2) for a constant count","Recount levels after any channel_mult edit"],"exampleFix":"# before\nchannel_mult=(1,2,4,4), num_res_blocks=[2,2,2]\n# after\nchannel_mult=(1,2,4,4), num_res_blocks=[2,2,2,2]","handlingStrategy":"validation","validationCode":"if not isinstance(num_res_blocks, int):\n    assert len(num_res_blocks) == len(channel_mult), 'num_res_blocks must match channel_mult length'","typeGuard":"def num_res_blocks_ok(nrb, channel_mult) -> bool:\n    return isinstance(nrb, int) or (isinstance(nrb, (list, tuple)) and len(nrb) == len(channel_mult))","tryCatchPattern":null,"preventionTips":["When editing channel_mult in YAML, recount num_res_blocks in the same commit","Prefer int form unless per-level asymmetry is required"],"tags":["controlnet","config","unet","value-error"],"backgroundTag":"config-length-mismatch","analyzedSha":"ed85cd1e25a5ed592f7d8178495b4483de0331bf","analyzedAt":"2026-08-27T12:58:54.167Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}