Skip to content

Commit 4151fbf

Browse files
authored
Add error message on union controlnet (#4081)
1 parent 6045ed3 commit 4151fbf

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

comfy/cldm/cldm.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from ..ldm.modules.attention import SpatialTransformer
1414
from ..ldm.modules.diffusionmodules.openaimodel import UNetModel, TimestepEmbedSequential, ResBlock, Downsample
1515
from ..ldm.util import exists
16+
from .control_types import UNION_CONTROLNET_TYPES
1617
from collections import OrderedDict
1718
import comfy.ops
1819
from comfy.ldm.modules.attention import optimized_attention
@@ -390,6 +391,18 @@ def forward(self, x, hint, timesteps, context, y=None, **kwargs):
390391
if self.control_add_embedding is not None: #Union Controlnet
391392
control_type = kwargs.get("control_type", [])
392393

394+
if any([c >= self.num_control_type for c in control_type]):
395+
max_type = max(control_type)
396+
max_type_name = {
397+
v: k for k, v in UNION_CONTROLNET_TYPES.items()
398+
}[max_type]
399+
raise ValueError(
400+
f"Control type {max_type_name}({max_type}) is out of range for the number of control types" +
401+
f"({self.num_control_type}) supported.\n" +
402+
"Please consider using the ProMax ControlNet Union model.\n" +
403+
"https://huggingface.co/xinsir/controlnet-union-sdxl-1.0/tree/main"
404+
)
405+
393406
emb += self.control_add_embedding(control_type, emb.dtype, emb.device)
394407
if len(control_type) > 0:
395408
if len(hint.shape) < 5:

comfy/cldm/control_types.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
UNION_CONTROLNET_TYPES = {
2+
"auto": -1,
3+
"openpose": 0,
4+
"depth": 1,
5+
"hed/pidi/scribble/ted": 2,
6+
"canny/lineart/anime_lineart/mlsd": 3,
7+
"normal": 4,
8+
"segment": 5,
9+
"tile": 6,
10+
"repaint": 7,
11+
}

comfy_extras/nodes_controlnet.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
2-
UNION_CONTROLNET_TYPES = {"auto": -1,
3-
"openpose": 0,
4-
"depth": 1,
5-
"hed/pidi/scribble/ted": 2,
6-
"canny/lineart/anime_lineart/mlsd": 3,
7-
"normal": 4,
8-
"segment": 5,
9-
"tile": 6,
10-
"repaint": 7,
11-
}
1+
from comfy.cldm.control_types import UNION_CONTROLNET_TYPES
122

133
class SetUnionControlNetType:
144
@classmethod

0 commit comments

Comments
 (0)