Skip to content

Commit

Permalink
[ip-adapter] make sure length of scale is same as number of ip-adap…
Browse files Browse the repository at this point in the history
…ters when using `set_ip_adapter_scale` (huggingface#6884)

add

Co-authored-by: yiyixuxu <yixu310@gmail,com>
  • Loading branch information
yiyixuxu and yiyixuxu authored Feb 7, 2024
1 parent 76696dc commit 97d004b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/diffusers/loaders/ip_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,16 @@ def load_ip_adapter(
unet._load_ip_adapter_weights(state_dicts)

def set_ip_adapter_scale(self, scale):
if not isinstance(scale, list):
scale = [scale]
unet = getattr(self, self.unet_name) if not hasattr(self, "unet") else self.unet
for attn_processor in unet.attn_processors.values():
if isinstance(attn_processor, (IPAdapterAttnProcessor, IPAdapterAttnProcessor2_0)):
if not isinstance(scale, list):
scale = [scale] * len(attn_processor.scale)
if len(attn_processor.scale) != len(scale):
raise ValueError(
f"`scale` should be a list of same length as the number if ip-adapters "
f"Expected {len(attn_processor.scale)} but got {len(scale)}."
)
attn_processor.scale = scale

def unload_ip_adapter(self):
Expand Down

0 comments on commit 97d004b

Please sign in to comment.