From a60780379d72447a26fad441f5cdb1ccb3194761 Mon Sep 17 00:00:00 2001 From: Anatoly Belikov Date: Mon, 25 Sep 2023 19:50:43 +0300 Subject: [PATCH 1/5] handle case when controlnet is list --- src/diffusers/loaders.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/diffusers/loaders.py b/src/diffusers/loaders.py index f63532b84e7c..4b8ef3a02adc 100644 --- a/src/diffusers/loaders.py +++ b/src/diffusers/loaders.py @@ -2337,7 +2337,10 @@ def from_single_file(cls, pretrained_model_link_or_path, **kwargs): # Model type will be inferred from the checkpoint. if not isinstance(controlnet, (ControlNetModel, MultiControlNetModel)): - raise ValueError("ControlNet needs to be passed if loading from ControlNet pipeline.") + if isinstance(controlnet, (list, tuple)) and controlnet: + pass + else: + raise ValueError("ControlNet needs to be passed if loading from ControlNet pipeline.") elif "StableDiffusion" in pipeline_name: # Model type will be inferred from the checkpoint. pass From d8dbfc999e563e4c5dba89c235393fae28f8e706 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 27 Sep 2023 12:57:56 +0200 Subject: [PATCH 2/5] Update src/diffusers/loaders.py --- src/diffusers/loaders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/loaders.py b/src/diffusers/loaders.py index 4b8ef3a02adc..f939e2a01fa2 100644 --- a/src/diffusers/loaders.py +++ b/src/diffusers/loaders.py @@ -2336,7 +2336,7 @@ def from_single_file(cls, pretrained_model_link_or_path, **kwargs): from .pipelines.controlnet.multicontrolnet import MultiControlNetModel # Model type will be inferred from the checkpoint. - if not isinstance(controlnet, (ControlNetModel, MultiControlNetModel)): + if not (isinstance(controlnet, (ControlNetModel, MultiControlNetModel)) or isinstance(controlnet, (list, tuple)) and isinstance(controlnet[0], ControlNetModel)) if isinstance(controlnet, (list, tuple)) and controlnet: pass else: From ee89dbeef9a09ea4f1f0a32e5ab98350acf51e84 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 27 Sep 2023 12:58:03 +0200 Subject: [PATCH 3/5] Apply suggestions from code review --- src/diffusers/loaders.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/diffusers/loaders.py b/src/diffusers/loaders.py index f939e2a01fa2..2912fc2b4720 100644 --- a/src/diffusers/loaders.py +++ b/src/diffusers/loaders.py @@ -2337,10 +2337,6 @@ def from_single_file(cls, pretrained_model_link_or_path, **kwargs): # Model type will be inferred from the checkpoint. if not (isinstance(controlnet, (ControlNetModel, MultiControlNetModel)) or isinstance(controlnet, (list, tuple)) and isinstance(controlnet[0], ControlNetModel)) - if isinstance(controlnet, (list, tuple)) and controlnet: - pass - else: - raise ValueError("ControlNet needs to be passed if loading from ControlNet pipeline.") elif "StableDiffusion" in pipeline_name: # Model type will be inferred from the checkpoint. pass From 0b3328d20e6da86f21e1ca44bf6d2423178524e9 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Wed, 27 Sep 2023 12:58:38 +0200 Subject: [PATCH 4/5] Update src/diffusers/loaders.py --- src/diffusers/loaders.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/diffusers/loaders.py b/src/diffusers/loaders.py index 2912fc2b4720..532b665d361d 100644 --- a/src/diffusers/loaders.py +++ b/src/diffusers/loaders.py @@ -2336,7 +2336,8 @@ def from_single_file(cls, pretrained_model_link_or_path, **kwargs): from .pipelines.controlnet.multicontrolnet import MultiControlNetModel # Model type will be inferred from the checkpoint. - if not (isinstance(controlnet, (ControlNetModel, MultiControlNetModel)) or isinstance(controlnet, (list, tuple)) and isinstance(controlnet[0], ControlNetModel)) + if not (isinstance(controlnet, (ControlNetModel, MultiControlNetModel)) or isinstance(controlnet, (list, tuple)) and isinstance(controlnet[0], ControlNetModel)): + raise ValueError("ControlNet needs to be passed if loading from ControlNet pipeline.") elif "StableDiffusion" in pipeline_name: # Model type will be inferred from the checkpoint. pass From 019711ff750f3c504342e98e0d52d19774fc4292 Mon Sep 17 00:00:00 2001 From: Anatoly Belikov Date: Wed, 27 Sep 2023 23:02:39 +0300 Subject: [PATCH 5/5] typecheck comment --- src/diffusers/loaders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/loaders.py b/src/diffusers/loaders.py index 532b665d361d..6f03227ed678 100644 --- a/src/diffusers/loaders.py +++ b/src/diffusers/loaders.py @@ -2335,7 +2335,7 @@ def from_single_file(cls, pretrained_model_link_or_path, **kwargs): from .models.controlnet import ControlNetModel from .pipelines.controlnet.multicontrolnet import MultiControlNetModel - # Model type will be inferred from the checkpoint. + # list/tuple or a single instance of ControlNetModel or MultiControlNetModel if not (isinstance(controlnet, (ControlNetModel, MultiControlNetModel)) or isinstance(controlnet, (list, tuple)) and isinstance(controlnet[0], ControlNetModel)): raise ValueError("ControlNet needs to be passed if loading from ControlNet pipeline.") elif "StableDiffusion" in pipeline_name: