@@ -110,6 +110,9 @@ def __init__(
110110 # IPAdapter options
111111 use_ipadapter : bool = False ,
112112 ipadapter_config : Optional [Union [Dict [str , Any ], List [Dict [str , Any ]]]] = None ,
113+ # Concurrency options
114+ controlnet_max_parallel : Optional [int ] = None ,
115+ controlnet_block_add_when_parallel : bool = True ,
113116 ):
114117 """
115118 Initializes the StreamDiffusionWrapper.
@@ -198,6 +201,9 @@ def __init__(
198201 self .enable_pytorch_fallback = enable_pytorch_fallback
199202 self .use_ipadapter = use_ipadapter
200203 self .ipadapter_config = ipadapter_config
204+ # Concurrency settings
205+ self .controlnet_max_parallel = controlnet_max_parallel
206+ self .controlnet_block_add_when_parallel = controlnet_block_add_when_parallel
201207
202208 if mode == "txt2img" :
203209 if cfg_type != "none" :
@@ -1482,6 +1488,17 @@ def _load_model(
14821488 from streamdiffusion .modules .controlnet_module import ControlNetModule , ControlNetConfig
14831489 cn_module = ControlNetModule (device = self .device , dtype = self .dtype )
14841490 cn_module .install (stream )
1491+ # Apply configured max parallel if provided
1492+ try :
1493+ if self .controlnet_max_parallel is not None :
1494+ setattr (cn_module , '_max_parallel_controlnets' , int (self .controlnet_max_parallel ))
1495+ except Exception :
1496+ pass
1497+ # Expose add-blocking policy on stream
1498+ try :
1499+ setattr (stream , 'controlnet_block_add_when_parallel' , bool (self .controlnet_block_add_when_parallel ))
1500+ except Exception :
1501+ pass
14851502 # Normalize to list of configs
14861503 configs = controlnet_config if isinstance (controlnet_config , list ) else [controlnet_config ]
14871504 for cfg in configs :
0 commit comments