mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
chore: black / flake lint errors
This commit is contained in:
parent
a1398dec91
commit
4196c669a0
@ -38,7 +38,8 @@ class ControlNetModel(ModelMixin, ConfigMixin, FromOriginalControlnetMixin):
|
|||||||
Whether to flip the sin to cos in the time embedding.
|
Whether to flip the sin to cos in the time embedding.
|
||||||
freq_shift (`int`, defaults to 0):
|
freq_shift (`int`, defaults to 0):
|
||||||
The frequency shift to apply to the time embedding.
|
The frequency shift to apply to the time embedding.
|
||||||
down_block_types (`tuple[str]`, defaults to `("CrossAttnDownBlock2D", "CrossAttnDownBlock2D", "CrossAttnDownBlock2D", "DownBlock2D")`):
|
down_block_types (`tuple[str]`, defaults to `("CrossAttnDownBlock2D", "CrossAttnDownBlock2D", \
|
||||||
|
"CrossAttnDownBlock2D", "DownBlock2D")`):
|
||||||
The tuple of downsample blocks to use.
|
The tuple of downsample blocks to use.
|
||||||
only_cross_attention (`Union[bool, Tuple[bool]]`, defaults to `False`):
|
only_cross_attention (`Union[bool, Tuple[bool]]`, defaults to `False`):
|
||||||
block_out_channels (`tuple[int]`, defaults to `(320, 640, 1280, 1280)`):
|
block_out_channels (`tuple[int]`, defaults to `(320, 640, 1280, 1280)`):
|
||||||
@ -140,7 +141,9 @@ class ControlNetModel(ModelMixin, ConfigMixin, FromOriginalControlnetMixin):
|
|||||||
# If `num_attention_heads` is not defined (which is the case for most models)
|
# If `num_attention_heads` is not defined (which is the case for most models)
|
||||||
# it will default to `attention_head_dim`. This looks weird upon first reading it and it is.
|
# it will default to `attention_head_dim`. This looks weird upon first reading it and it is.
|
||||||
# The reason for this behavior is to correct for incorrectly named variables that were introduced
|
# The reason for this behavior is to correct for incorrectly named variables that were introduced
|
||||||
# when this library was created. The incorrect naming was only discovered much later in https://github.com/huggingface/diffusers/issues/2011#issuecomment-1547958131
|
# when this library was created...
|
||||||
|
# The incorrect naming was only discovered much ...
|
||||||
|
# later in https://github.com/huggingface/diffusers/issues/2011#issuecomment-1547958131
|
||||||
# Changing `attention_head_dim` to `num_attention_heads` for 40,000+ configurations is too backwards breaking
|
# Changing `attention_head_dim` to `num_attention_heads` for 40,000+ configurations is too backwards breaking
|
||||||
# which is why we correct for the naming here.
|
# which is why we correct for the naming here.
|
||||||
num_attention_heads = num_attention_heads or attention_head_dim
|
num_attention_heads = num_attention_heads or attention_head_dim
|
||||||
@ -148,17 +151,20 @@ class ControlNetModel(ModelMixin, ConfigMixin, FromOriginalControlnetMixin):
|
|||||||
# Check inputs
|
# Check inputs
|
||||||
if len(block_out_channels) != len(down_block_types):
|
if len(block_out_channels) != len(down_block_types):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Must provide the same number of `block_out_channels` as `down_block_types`. `block_out_channels`: {block_out_channels}. `down_block_types`: {down_block_types}."
|
f"Must provide the same number of `block_out_channels` as `down_block_types`. \
|
||||||
|
`block_out_channels`: {block_out_channels}. `down_block_types`: {down_block_types}."
|
||||||
)
|
)
|
||||||
|
|
||||||
if not isinstance(only_cross_attention, bool) and len(only_cross_attention) != len(down_block_types):
|
if not isinstance(only_cross_attention, bool) and len(only_cross_attention) != len(down_block_types):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Must provide the same number of `only_cross_attention` as `down_block_types`. `only_cross_attention`: {only_cross_attention}. `down_block_types`: {down_block_types}."
|
f"Must provide the same number of `only_cross_attention` as `down_block_types`. \
|
||||||
|
`only_cross_attention`: {only_cross_attention}. `down_block_types`: {down_block_types}."
|
||||||
)
|
)
|
||||||
|
|
||||||
if not isinstance(num_attention_heads, int) and len(num_attention_heads) != len(down_block_types):
|
if not isinstance(num_attention_heads, int) and len(num_attention_heads) != len(down_block_types):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Must provide the same number of `num_attention_heads` as `down_block_types`. `num_attention_heads`: {num_attention_heads}. `down_block_types`: {down_block_types}."
|
f"Must provide the same number of `num_attention_heads` as `down_block_types`. \
|
||||||
|
`num_attention_heads`: {num_attention_heads}. `down_block_types`: {down_block_types}."
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(transformer_layers_per_block, int):
|
if isinstance(transformer_layers_per_block, int):
|
||||||
@ -195,7 +201,8 @@ class ControlNetModel(ModelMixin, ConfigMixin, FromOriginalControlnetMixin):
|
|||||||
self.encoder_hid_proj = nn.Linear(encoder_hid_dim, cross_attention_dim)
|
self.encoder_hid_proj = nn.Linear(encoder_hid_dim, cross_attention_dim)
|
||||||
elif encoder_hid_dim_type == "text_image_proj":
|
elif encoder_hid_dim_type == "text_image_proj":
|
||||||
# image_embed_dim DOESN'T have to be `cross_attention_dim`. To not clutter the __init__ too much
|
# image_embed_dim DOESN'T have to be `cross_attention_dim`. To not clutter the __init__ too much
|
||||||
# they are set to `cross_attention_dim` here as this is exactly the required dimension for the currently only use
|
# they are set to `cross_attention_dim` here as this is exactly the required dimension ...
|
||||||
|
# for the currently only use
|
||||||
# case when `addition_embed_type == "text_image_proj"` (Kadinsky 2.1)`
|
# case when `addition_embed_type == "text_image_proj"` (Kadinsky 2.1)`
|
||||||
self.encoder_hid_proj = TextImageProjection(
|
self.encoder_hid_proj = TextImageProjection(
|
||||||
text_embed_dim=encoder_hid_dim,
|
text_embed_dim=encoder_hid_dim,
|
||||||
@ -243,8 +250,10 @@ class ControlNetModel(ModelMixin, ConfigMixin, FromOriginalControlnetMixin):
|
|||||||
text_time_embedding_from_dim, time_embed_dim, num_heads=addition_embed_type_num_heads
|
text_time_embedding_from_dim, time_embed_dim, num_heads=addition_embed_type_num_heads
|
||||||
)
|
)
|
||||||
elif addition_embed_type == "text_image":
|
elif addition_embed_type == "text_image":
|
||||||
# text_embed_dim and image_embed_dim DON'T have to be `cross_attention_dim`. To not clutter the __init__ too much
|
# text_embed_dim and image_embed_dim DON'T have to be `cross_attention_dim`.
|
||||||
# they are set to `cross_attention_dim` here as this is exactly the required dimension for the currently only use
|
# To not clutter the __init__ too much
|
||||||
|
# they are set to `cross_attention_dim` here as this is exactly the required dimension...
|
||||||
|
# for the currently only use
|
||||||
# case when `addition_embed_type == "text_image"` (Kadinsky 2.1)`
|
# case when `addition_embed_type == "text_image"` (Kadinsky 2.1)`
|
||||||
self.add_embedding = TextImageTimeEmbedding(
|
self.add_embedding = TextImageTimeEmbedding(
|
||||||
text_embed_dim=cross_attention_dim, image_embed_dim=cross_attention_dim, time_embed_dim=time_embed_dim
|
text_embed_dim=cross_attention_dim, image_embed_dim=cross_attention_dim, time_embed_dim=time_embed_dim
|
||||||
@ -666,12 +675,14 @@ class ControlNetModel(ModelMixin, ConfigMixin, FromOriginalControlnetMixin):
|
|||||||
elif self.config.addition_embed_type == "text_time":
|
elif self.config.addition_embed_type == "text_time":
|
||||||
if "text_embeds" not in added_cond_kwargs:
|
if "text_embeds" not in added_cond_kwargs:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"{self.__class__} has the config param `addition_embed_type` set to 'text_time' which requires the keyword argument `text_embeds` to be passed in `added_cond_kwargs`"
|
f"{self.__class__} has the config param `addition_embed_type` set to 'text_time' which \
|
||||||
|
requires the keyword argument `text_embeds` to be passed in `added_cond_kwargs`"
|
||||||
)
|
)
|
||||||
text_embeds = added_cond_kwargs.get("text_embeds")
|
text_embeds = added_cond_kwargs.get("text_embeds")
|
||||||
if "time_ids" not in added_cond_kwargs:
|
if "time_ids" not in added_cond_kwargs:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"{self.__class__} has the config param `addition_embed_type` set to 'text_time' which requires the keyword argument `time_ids` to be passed in `added_cond_kwargs`"
|
f"{self.__class__} has the config param `addition_embed_type` set to 'text_time' which \
|
||||||
|
requires the keyword argument `time_ids` to be passed in `added_cond_kwargs`"
|
||||||
)
|
)
|
||||||
time_ids = added_cond_kwargs.get("time_ids")
|
time_ids = added_cond_kwargs.get("time_ids")
|
||||||
time_embeds = self.add_time_proj(time_ids.flatten())
|
time_embeds = self.add_time_proj(time_ids.flatten())
|
||||||
@ -774,7 +785,7 @@ try:
|
|||||||
import xformers
|
import xformers
|
||||||
|
|
||||||
xformers_available = True
|
xformers_available = True
|
||||||
except:
|
except Exception:
|
||||||
xformers_available = False
|
xformers_available = False
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user