{"record":{"id":"4e43767650b352ed","repo":"Comfy-Org/ComfyUI","slug":"the-number-of-controls-is-not-equal-to-the-number","errorCode":null,"errorMessage":"The number of controls is not equal to the number of skip connections.","messagePattern":"The number of controls is not equal to the number of skip connections\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/hydit/models.py","lineNumber":392,"sourceCode":"            else:\n                skip = None\n\n            if (\"double_block\", layer) in blocks_replace:\n                def block_wrap(args):\n                    out = {}\n                    out[\"img\"] = block(args[\"img\"], args[\"vec\"], args[\"txt\"], args[\"pe\"], args[\"skip\"])\n                    return out\n\n                out = blocks_replace[(\"double_block\", layer)]({\"img\": x, \"txt\": text_states, \"vec\": c, \"pe\": freqs_cis_img, \"skip\": skip}, {\"original_block\": block_wrap})\n                x = out[\"img\"]\n            else:\n                x = block(x, c, text_states, freqs_cis_img, skip)   # (N, L, D)\n\n\n            if layer < (self.depth // 2 - 1):\n                skips.append(x)\n        if controls is not None and len(controls) != 0:\n            raise ValueError(\"The number of controls is not equal to the number of skip connections.\")\n\n        # ========================= Final layer =========================\n        x = self.final_layer(x, c)                              # (N, L, patch_size ** 2 * out_channels)\n        x = self.unpatchify(x, th, tw)                          # (N, out_channels, H, W)\n\n        if return_dict:\n            return {'x': x}\n        if self.learn_sigma:\n            return x[:,:self.out_channels // 2,:oh,:ow]\n        return x[:,:,:oh,:ow]\n\n    def unpatchify(self, x, h, w):\n        \"\"\"\n        x: (N, T, patch_size**2 * C)\n        imgs: (N, H, W, C)\n        \"\"\"\n        c = self.unpatchify_channels\n        p = self.x_embedder.patch_size[0]","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/hydit/models.py#L374-L410","documentation":"After the U-Net-style skip pass over HYDiT blocks, if ControlNet outputs remain unconsumed the counts did not line up: each control output is popped and added to one skip connection in the decoder half, and leftovers mean the ControlNet depth does not match the DiT depth.","triggerScenarios":"Attaching a ControlNet whose 'output' list is longer than depth//2 - 1 skip connections (e.g. a 40-layer controlnet on a shallower DiT), or a depth/config mismatch between the controlnet checkpoint and the loaded DiT.","commonSituations":"Loading a ControlNet trained for HunYuanDiT v1.x onto a different-sized DiT (different depth), or applying a control signal computed for another model version.","solutions":["Use a ControlNet checkpoint that matches the loaded DiT's depth (number of control outputs <= depth//2 - 1 and fully consumed)","Verify the DiT config depth and the controlnet's output count from its state dict before applying","Update to the matching DiT checkpoint version the ControlNet was trained against"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"n_control = len(control['output'])\nn_skips = model.depth // 2 - 1\nassert n_control <= n_skips, f\"controlnet too deep: {n_control} > {n_skips}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair ControlNets only with the DiT checkpoint version they were trained on","Check controlnet config depth against DiT depth before applying"],"tags":["hydit","controlnet","skip-connection","model-mismatch"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}