mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
parent
af36fe8c1e
commit
7a67fd6a06
@ -15,12 +15,10 @@ from diffusers import AutoencoderKL, AutoencoderTiny
|
|||||||
from diffusers.configuration_utils import ConfigMixin
|
from diffusers.configuration_utils import ConfigMixin
|
||||||
from diffusers.image_processor import VaeImageProcessor
|
from diffusers.image_processor import VaeImageProcessor
|
||||||
from diffusers.models.adapter import T2IAdapter
|
from diffusers.models.adapter import T2IAdapter
|
||||||
from diffusers.models.attention_processor import (
|
from diffusers.models.attention_processor import (AttnProcessor2_0,
|
||||||
AttnProcessor2_0,
|
LoRAAttnProcessor2_0,
|
||||||
LoRAAttnProcessor2_0,
|
LoRAXFormersAttnProcessor,
|
||||||
LoRAXFormersAttnProcessor,
|
XFormersAttnProcessor)
|
||||||
XFormersAttnProcessor,
|
|
||||||
)
|
|
||||||
from diffusers.models.unets.unet_2d_condition import UNet2DConditionModel
|
from diffusers.models.unets.unet_2d_condition import UNet2DConditionModel
|
||||||
from diffusers.schedulers import DPMSolverSDEScheduler
|
from diffusers.schedulers import DPMSolverSDEScheduler
|
||||||
from diffusers.schedulers import SchedulerMixin as Scheduler
|
from diffusers.schedulers import SchedulerMixin as Scheduler
|
||||||
@ -29,22 +27,17 @@ from pydantic import field_validator
|
|||||||
from torchvision.transforms.functional import resize as tv_resize
|
from torchvision.transforms.functional import resize as tv_resize
|
||||||
from transformers import CLIPVisionModelWithProjection
|
from transformers import CLIPVisionModelWithProjection
|
||||||
|
|
||||||
from invokeai.app.invocations.constants import LATENT_SCALE_FACTOR, SCHEDULER_NAME_VALUES
|
from invokeai.app.invocations.constants import (LATENT_SCALE_FACTOR,
|
||||||
from invokeai.app.invocations.fields import (
|
SCHEDULER_NAME_VALUES)
|
||||||
ConditioningField,
|
from invokeai.app.invocations.fields import (ConditioningField,
|
||||||
DenoiseMaskField,
|
DenoiseMaskField,
|
||||||
FieldDescriptions,
|
FieldDescriptions, ImageField,
|
||||||
ImageField,
|
Input, InputField, LatentsField,
|
||||||
Input,
|
OutputField, UIType, WithBoard,
|
||||||
InputField,
|
WithMetadata)
|
||||||
LatentsField,
|
|
||||||
OutputField,
|
|
||||||
UIType,
|
|
||||||
WithBoard,
|
|
||||||
WithMetadata,
|
|
||||||
)
|
|
||||||
from invokeai.app.invocations.ip_adapter import IPAdapterField
|
from invokeai.app.invocations.ip_adapter import IPAdapterField
|
||||||
from invokeai.app.invocations.primitives import DenoiseMaskOutput, ImageOutput, LatentsOutput
|
from invokeai.app.invocations.primitives import (DenoiseMaskOutput,
|
||||||
|
ImageOutput, LatentsOutput)
|
||||||
from invokeai.app.invocations.t2i_adapter import T2IAdapterField
|
from invokeai.app.invocations.t2i_adapter import T2IAdapterField
|
||||||
from invokeai.app.services.shared.invocation_context import InvocationContext
|
from invokeai.app.services.shared.invocation_context import InvocationContext
|
||||||
from invokeai.app.util.controlnet_utils import prepare_control_image
|
from invokeai.app.util.controlnet_utils import prepare_control_image
|
||||||
@ -52,28 +45,21 @@ from invokeai.backend.ip_adapter.ip_adapter import IPAdapter, IPAdapterPlus
|
|||||||
from invokeai.backend.lora import LoRAModelRaw
|
from invokeai.backend.lora import LoRAModelRaw
|
||||||
from invokeai.backend.model_manager import BaseModelType, LoadedModel
|
from invokeai.backend.model_manager import BaseModelType, LoadedModel
|
||||||
from invokeai.backend.model_patcher import ModelPatcher
|
from invokeai.backend.model_patcher import ModelPatcher
|
||||||
from invokeai.backend.stable_diffusion import PipelineIntermediateState, set_seamless
|
from invokeai.backend.stable_diffusion import (PipelineIntermediateState,
|
||||||
|
set_seamless)
|
||||||
from invokeai.backend.stable_diffusion.diffusion.conditioning_data import (
|
from invokeai.backend.stable_diffusion.diffusion.conditioning_data import (
|
||||||
BasicConditioningInfo,
|
BasicConditioningInfo, IPAdapterConditioningInfo, IPAdapterData, Range,
|
||||||
IPAdapterConditioningInfo,
|
SDXLConditioningInfo, TextConditioningData, TextConditioningRegions)
|
||||||
IPAdapterData,
|
|
||||||
Range,
|
|
||||||
SDXLConditioningInfo,
|
|
||||||
TextConditioningData,
|
|
||||||
TextConditioningRegions,
|
|
||||||
)
|
|
||||||
from invokeai.backend.util.mask import to_standard_float_mask
|
from invokeai.backend.util.mask import to_standard_float_mask
|
||||||
from invokeai.backend.util.silence_warnings import SilenceWarnings
|
from invokeai.backend.util.silence_warnings import SilenceWarnings
|
||||||
|
|
||||||
from ...backend.stable_diffusion.diffusers_pipeline import (
|
from ...backend.stable_diffusion.diffusers_pipeline import (
|
||||||
ControlNetData,
|
ControlNetData, StableDiffusionGeneratorPipeline, T2IAdapterData,
|
||||||
StableDiffusionGeneratorPipeline,
|
image_resized_to_grid_as_tensor)
|
||||||
T2IAdapterData,
|
|
||||||
image_resized_to_grid_as_tensor,
|
|
||||||
)
|
|
||||||
from ...backend.stable_diffusion.schedulers import SCHEDULER_MAP
|
from ...backend.stable_diffusion.schedulers import SCHEDULER_MAP
|
||||||
from ...backend.util.devices import choose_precision, choose_torch_device
|
from ...backend.util.devices import choose_precision, choose_torch_device
|
||||||
from .baseinvocation import BaseInvocation, BaseInvocationOutput, invocation, invocation_output
|
from .baseinvocation import (BaseInvocation, BaseInvocationOutput, invocation,
|
||||||
|
invocation_output)
|
||||||
from .controlnet_image_processors import ControlField
|
from .controlnet_image_processors import ControlField
|
||||||
from .model import ModelIdentifierField, UNetField, VAEField
|
from .model import ModelIdentifierField, UNetField, VAEField
|
||||||
|
|
||||||
|
@ -156,6 +156,7 @@ class CustomAttnProcessor2_0(AttnProcessor2_0):
|
|||||||
# Expected ip_hidden_state shape: (batch_size, num_ip_images, ip_seq_len, ip_image_embedding)
|
# Expected ip_hidden_state shape: (batch_size, num_ip_images, ip_seq_len, ip_image_embedding)
|
||||||
|
|
||||||
if self._ip_adapter_attention_weights["skip"]:
|
if self._ip_adapter_attention_weights["skip"]:
|
||||||
|
|
||||||
ip_key = ipa_weights.to_k_ip(ip_hidden_states)
|
ip_key = ipa_weights.to_k_ip(ip_hidden_states)
|
||||||
ip_value = ipa_weights.to_v_ip(ip_hidden_states)
|
ip_value = ipa_weights.to_v_ip(ip_hidden_states)
|
||||||
|
|
||||||
|
@ -33,8 +33,10 @@ class UNetAttentionPatcher:
|
|||||||
# "attn1" processors do not use IP-Adapters.
|
# "attn1" processors do not use IP-Adapters.
|
||||||
attn_procs[name] = CustomAttnProcessor2_0()
|
attn_procs[name] = CustomAttnProcessor2_0()
|
||||||
else:
|
else:
|
||||||
|
|
||||||
ip_adapter_attention_weights: IPAdapterAttentionWeights = {"ip_adapter_weights": [], "skip": False}
|
ip_adapter_attention_weights: IPAdapterAttentionWeights = {"ip_adapter_weights": [], "skip": False}
|
||||||
for ip_adapter in self._ip_adapters:
|
for ip_adapter in self._ip_adapters:
|
||||||
|
|
||||||
ip_adapter_weight = ip_adapter["ip_adapter"].attn_weights.get_attention_processor_weights(idx)
|
ip_adapter_weight = ip_adapter["ip_adapter"].attn_weights.get_attention_processor_weights(idx)
|
||||||
skip = False
|
skip = False
|
||||||
for block in ip_adapter["target_blocks"]:
|
for block in ip_adapter["target_blocks"]:
|
||||||
|
Loading…
Reference in New Issue
Block a user