From 65a76a086b116ae018db3b96ce48f3464b6c9ae8 Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Tue, 5 Sep 2023 11:54:28 +1200 Subject: [PATCH] cleanup: Some basic cleanup --- invokeai/backend/ip_adapter/__init__.py | 2 +- invokeai/backend/ip_adapter/ip_adapter.py | 6 ++---- invokeai/backend/ip_adapter/resampler.py | 3 ++- invokeai/backend/ip_adapter/utils.py | 11 +++++------ 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/invokeai/backend/ip_adapter/__init__.py b/invokeai/backend/ip_adapter/__init__.py index 852ee25813..68cb7069a5 100644 --- a/invokeai/backend/ip_adapter/__init__.py +++ b/invokeai/backend/ip_adapter/__init__.py @@ -1 +1 @@ -from .ip_adapter import IPAdapter, IPAdapterXL, IPAdapterPlus +from .ip_adapter import IPAdapter, IPAdapterPlus, IPAdapterXL diff --git a/invokeai/backend/ip_adapter/ip_adapter.py b/invokeai/backend/ip_adapter/ip_adapter.py index 81bc6db847..b8f55fb59c 100644 --- a/invokeai/backend/ip_adapter/ip_adapter.py +++ b/invokeai/backend/ip_adapter/ip_adapter.py @@ -1,13 +1,11 @@ # copied from https://github.com/tencent-ailab/IP-Adapter (Apache License 2.0) # and modified as needed -import os from typing import List import torch -from diffusers import StableDiffusionPipeline -from transformers import CLIPVisionModelWithProjection, CLIPImageProcessor from PIL import Image +from transformers import CLIPImageProcessor, CLIPVisionModelWithProjection # FIXME: Getting errors when trying to use PyTorch 2.0 versions of IPAttnProcessor and AttnProcessor # so for now falling back to the default versions @@ -16,7 +14,7 @@ from PIL import Image # from .attention_processor import IPAttnProcessor2_0 as IPAttnProcessor, AttnProcessor2_0 as AttnProcessor # else: # from .attention_processor import IPAttnProcessor, AttnProcessor -from .attention_processor import IPAttnProcessor, AttnProcessor +from .attention_processor import AttnProcessor, IPAttnProcessor from .resampler import Resampler diff --git a/invokeai/backend/ip_adapter/resampler.py b/invokeai/backend/ip_adapter/resampler.py index 38c4b06dcf..3d326568a0 100644 --- a/invokeai/backend/ip_adapter/resampler.py +++ b/invokeai/backend/ip_adapter/resampler.py @@ -1,6 +1,7 @@ # copied from https://github.com/tencent-ailab/IP-Adapter (Apache License 2.0) -# tencent ailab comment: modified from https://github.com/mlfoundations/open_flamingo/blob/main/open_flamingo/src/helpers.py +# tencent ailab comment: modified from +# https://github.com/mlfoundations/open_flamingo/blob/main/open_flamingo/src/helpers.py import math import torch diff --git a/invokeai/backend/ip_adapter/utils.py b/invokeai/backend/ip_adapter/utils.py index 049d8163c2..d43cf12154 100644 --- a/invokeai/backend/ip_adapter/utils.py +++ b/invokeai/backend/ip_adapter/utils.py @@ -1,18 +1,16 @@ # copied from https://github.com/tencent-ailab/IP-Adapter (Apache License 2.0) # and modified as needed -import inspect -import warnings -from typing import Any, Callable, Dict, List, Optional, Tuple, Union +from typing import Any, Callable, Dict, List, Optional, Union import numpy as np import PIL.Image import torch import torch.nn.functional as F -from diffusers.utils import is_compiled_module -from diffusers.pipelines.controlnet.multicontrolnet import MultiControlNetModel from diffusers.models import ControlNetModel +from diffusers.pipelines.controlnet.multicontrolnet import MultiControlNetModel from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput +from diffusers.utils import is_compiled_module def is_torch2_available(): @@ -59,7 +57,8 @@ def generate( prompt (`str` or `List[str]`, *optional*): The prompt or prompts to guide the image generation. If not defined, one has to pass `prompt_embeds`. instead. - image (`torch.FloatTensor`, `PIL.Image.Image`, `np.ndarray`, `List[torch.FloatTensor]`, `List[PIL.Image.Image]`, `List[np.ndarray]`,: + image (`torch.FloatTensor`, `PIL.Image.Image`, `np.ndarray`, `List[torch.FloatTensor]`, `List[PIL.Image.Image]`, + `List[np.ndarray]`,: `List[List[torch.FloatTensor]]`, `List[List[np.ndarray]]` or `List[List[PIL.Image.Image]]`): The ControlNet input condition. ControlNet uses this input condition to generate guidance to Unet. If the type is specified as `Torch.FloatTensor`, it is passed to ControlNet as is. `PIL.Image.Image` can