diff --git a/invokeai/app/invocations/ip_adapter.py b/invokeai/app/invocations/ip_adapter.py index ff025011cb..d9fb7a78e5 100644 --- a/invokeai/app/invocations/ip_adapter.py +++ b/invokeai/app/invocations/ip_adapter.py @@ -64,8 +64,9 @@ class IPAdapterInvocation(BaseInvocation): ) # weight: float = InputField(default=1.0, description="The weight of the IP-Adapter.", ui_type=UIType.Float) - weight: Union[float, List[float]] = InputField(default=1, ge=0, description="The weight given to the IP-Adapter", - ui_type=UIType.Float, title="Weight") + weight: Union[float, List[float]] = InputField( + default=1, ge=0, description="The weight given to the IP-Adapter", ui_type=UIType.Float, title="Weight" + ) begin_step_percent: float = InputField( default=0, ge=-1, le=2, description="When the IP-Adapter is first applied (% of total steps)" diff --git a/invokeai/backend/stable_diffusion/diffusers_pipeline.py b/invokeai/backend/stable_diffusion/diffusers_pipeline.py index f57a152315..c45094b9b0 100644 --- a/invokeai/backend/stable_diffusion/diffusers_pipeline.py +++ b/invokeai/backend/stable_diffusion/diffusers_pipeline.py @@ -423,7 +423,8 @@ class StableDiffusionGeneratorPipeline(StableDiffusionPipeline): # As it is now, the IP-Adapter will silently be skipped. weight = ip_adapter_data.weight[0] if isinstance(ip_adapter_data.weight, List) else ip_adapter_data.weight attn_ctx = ip_adapter_data.ip_adapter_model.apply_ip_adapter_attention( - unet=self.invokeai_diffuser.model, scale=weight, + unet=self.invokeai_diffuser.model, + scale=weight, ) self.use_ip_adapter = True else: @@ -510,10 +511,14 @@ class StableDiffusionGeneratorPipeline(StableDiffusionPipeline): latent_model_input = self.scheduler.scale_model_input(latents, timestep) # handle IP-Adapter - if self.use_ip_adapter and ip_adapter_data is not None: # somewhat redundant but logic is clearer + if self.use_ip_adapter and ip_adapter_data is not None: # somewhat redundant but logic is clearer first_adapter_step = math.floor(ip_adapter_data.begin_step_percent * total_step_count) last_adapter_step = math.ceil(ip_adapter_data.end_step_percent * total_step_count) - weight = ip_adapter_data.weight[step_index] if isinstance(ip_adapter_data.weight, List) else ip_adapter_data.weight + weight = ( + ip_adapter_data.weight[step_index] + if isinstance(ip_adapter_data.weight, List) + else ip_adapter_data.weight + ) if step_index >= first_adapter_step and step_index <= last_adapter_step: # only apply IP-Adapter if current step is within the IP-Adapter's begin/end step range # ip_adapter_data.ip_adapter_model.set_scale(ip_adapter_data.weight)