Compare commits

..

27 Commits

Author SHA1 Message Date
e52e7418bb close #3304 2023-04-29 20:07:21 -04:00
73be58a0b5 fix issue #3293 2023-04-29 11:37:07 -04:00
5a7d11bca8 remove debugging statement 2023-04-27 08:21:26 -04:00
5bbf7fe34a [Bugfix] Renames in 0.15.0 diffusers (#3184)
Link to PR in diffusers repository:
https://github.com/huggingface/diffusers/pull/2691

Imports:
`diffusers.models.cross_attention ->
diffusers.models.attention_processor`

Unions:
`AttnProcessor -> AttentionProcessor`

Classes:
| Old name | New name |
| --- | --- |
| CrossAttention | Attention |
| CrossAttnProcessor | AttnProcessor |
| XFormersCrossAttnProcessor | XFormersAttnProcessor |
| CrossAttnAddedKVProcessor | AttnAddedKVProcessor |
| LoRACrossAttnProcessor | LoRAAttnProcessor |
| LoRAXFormersCrossAttnProcessor | LoRAXFormersAttnProcessor |
| FlaxCrossAttention | FlaxAttention |
| AttendExciteCrossAttnProcessor | AttendExciteAttnProcessor |
| Pix2PixZeroCrossAttnProcessor | Pix2PixZeroAttnProcessor |


Also config values no longer sets as attributes of object:
https://github.com/huggingface/diffusers/pull/2849
2023-04-27 11:38:27 +01:00
bfb968bbe8 Merge branch 'v2.3' into fix/new_diffusers_names 2023-04-26 23:54:37 +01:00
6db72f83a2 bump version number to 2.3.5-rc1 (#3267)
Bump version number for 2.3.5 release candidate.
2023-04-26 23:53:53 +01:00
432e526999 Revert merge changes 2023-04-25 14:49:08 +03:00
830740b93b remove redundant/buggy restore_default_attention() method 2023-04-25 07:05:07 -04:00
ff3f289342 Merge branch 'v2.3' into fix/new_diffusers_names 2023-04-25 13:21:26 +03:00
34abbb3589 Merge branch 'v2.3' into release/v2.3.5 2023-04-25 04:33:09 +01:00
c0eb1a9921 increase sha256 chunksize when calculating model hash (#3162)
- Thanks to @abdBarho, who discovered that increasing the chunksize
dramatically decreases the amount of time to calculate the hash.
2023-04-25 04:25:55 +01:00
2ddd0301f4 bump version number to 2.3.5-rc1 2023-04-24 23:24:33 -04:00
ce6629b6f5 Merge branch 'v2.3' into enhance/increase-sha256-chunksize 2023-04-25 03:58:30 +01:00
0f3c456d59 merge with v2.3 2023-04-24 22:51:48 -04:00
a45b3387c0 Merge branch 'v2.3' into enhance/increase-sha256-chunksize 2023-04-25 03:22:43 +01:00
2a2c86896a pull in diffusers 0.15.1
- Change diffusers dependency to `diffusers~=0.15.0` which *should*
  enforce  non-breaking changes.
2023-04-20 13:29:20 -04:00
aabe79686e Merge branch 'v2.3' into fix/new_diffusers_names 2023-04-20 17:20:33 +01:00
216b1c3a4a Merge branch 'v2.3' into fix/new_diffusers_names 2023-04-18 19:37:25 -04:00
47883860a6 Merge branch 'v2.3' into enhance/increase-sha256-chunksize 2023-04-13 23:00:34 -04:00
8f17d17208 Merge branch 'v2.3' into fix/new_diffusers_names 2023-04-13 22:44:05 -04:00
c6ecf3afc5 pin diffusers to 0.15.*, and fix deprecation warning on unet.in_channels 2023-04-13 22:38:50 -04:00
0bc5dcc663 Refactor 2023-04-13 16:05:04 +03:00
16c97ca0cb Fix num_train_timesteps in config 2023-04-12 23:57:45 +03:00
e24dd97b80 Fix that config attributes no longer accessible as object attributes 2023-04-12 23:40:14 +03:00
5a54039dd7 Fix imports for diffusers 0.15.0
Imports:
`diffusers.models.cross_attention -> diffusers.models.attention_processor`

Unions:
`AttnProcessor -> AttentionProcessor`

Classes:
| Old name | New name|
| --- | --- |
| CrossAttention | Attention |
| CrossAttnProcessor | AttnProcessor |
| XFormersCrossAttnProcessor | XFormersAttnProcessor |
| CrossAttnAddedKVProcessor | AttnAddedKVProcessor |
| LoRACrossAttnProcessor | LoRAAttnProcessor |
| LoRAXFormersCrossAttnProcessor | LoRAXFormersAttnProcessor |

Same names in this class:
`SlicedAttnProcessor, SlicedAttnAddedKVProcessor`
2023-04-12 22:54:25 +03:00
9385edb453 Merge branch 'v2.3' into enhance/increase-sha256-chunksize 2023-04-11 18:51:44 -04:00
66364501d5 increase sha256 chunksize when calculating model hash
- Thanks to @abdBarho, who discovered that increasing the chunksize
  dramatically decreases the amount of time to calculate the hash.
2023-04-09 16:39:16 -04:00
9 changed files with 34 additions and 23 deletions

2
.gitignore vendored
View File

@ -233,5 +233,3 @@ installer/install.sh
installer/update.bat
installer/update.sh
# no longer stored in source directory
models

View File

@ -1 +1 @@
__version__='2.3.5-rc1'
__version__='2.3.5-rc3'

View File

@ -111,7 +111,6 @@ def install_requested_models(
if len(external_models)>0:
print("== INSTALLING EXTERNAL MODELS ==")
for path_url_or_repo in external_models:
print(f'DEBUG: path_url_or_repo = {path_url_or_repo}')
try:
model_manager.heuristic_import(
path_url_or_repo,

View File

@ -400,8 +400,15 @@ class StableDiffusionGeneratorPipeline(StableDiffusionPipeline):
@property
def _submodels(self) -> Sequence[torch.nn.Module]:
module_names, _, _ = self.extract_init_dict(dict(self.config))
values = [getattr(self, name) for name in module_names.keys()]
return [m for m in values if isinstance(m, torch.nn.Module)]
submodels = []
for name in module_names.keys():
if hasattr(self, name):
value = getattr(self, name)
else:
value = getattr(self.config, name)
if isinstance(value, torch.nn.Module):
submodels.append(value)
return submodels
def image_from_embeddings(self, latents: torch.Tensor, num_inference_steps: int,
conditioning_data: ConditioningData,
@ -472,7 +479,7 @@ class StableDiffusionGeneratorPipeline(StableDiffusionPipeline):
step_count=len(self.scheduler.timesteps)
):
yield PipelineIntermediateState(run_id=run_id, step=-1, timestep=self.scheduler.num_train_timesteps,
yield PipelineIntermediateState(run_id=run_id, step=-1, timestep=self.scheduler.config.num_train_timesteps,
latents=latents)
batch_size = latents.shape[0]
@ -756,7 +763,7 @@ class StableDiffusionGeneratorPipeline(StableDiffusionPipeline):
@property
def channels(self) -> int:
"""Compatible with DiffusionWrapper"""
return self.unet.in_channels
return self.unet.config.in_channels
def decode_latents(self, latents):
# Explicit call to get the vae loaded, since `decode` isn't the forward method.

View File

@ -1156,7 +1156,7 @@ class ModelManager(object):
return self.device.type == "cuda"
def _diffuser_sha256(
self, name_or_path: Union[str, Path], chunksize=4096
self, name_or_path: Union[str, Path], chunksize=16777216
) -> Union[str, bytes]:
path = None
if isinstance(name_or_path, Path):

View File

@ -14,7 +14,6 @@ from torch import nn
from compel.cross_attention_control import Arguments
from diffusers.models.unet_2d_condition import UNet2DConditionModel
from diffusers.models.cross_attention import AttnProcessor
from ldm.invoke.devices import torch_dtype
@ -163,7 +162,7 @@ class Context:
class InvokeAICrossAttentionMixin:
"""
Enable InvokeAI-flavoured CrossAttention calculation, which does aggressive low-memory slicing and calls
Enable InvokeAI-flavoured Attention calculation, which does aggressive low-memory slicing and calls
through both to an attention_slice_wrangler and a slicing_strategy_getter for custom attention map wrangling
and dymamic slicing strategy selection.
"""
@ -178,7 +177,7 @@ class InvokeAICrossAttentionMixin:
Set custom attention calculator to be called when attention is calculated
:param wrangler: Callback, with args (module, suggested_attention_slice, dim, offset, slice_size),
which returns either the suggested_attention_slice or an adjusted equivalent.
`module` is the current CrossAttention module for which the callback is being invoked.
`module` is the current Attention module for which the callback is being invoked.
`suggested_attention_slice` is the default-calculated attention slice
`dim` is -1 if the attenion map has not been sliced, or 0 or 1 for dimension-0 or dimension-1 slicing.
If `dim` is >= 0, `offset` and `slice_size` specify the slice start and length.
@ -326,7 +325,7 @@ def setup_cross_attention_control_attention_processors(unet: UNet2DConditionMode
def get_cross_attention_modules(model, which: CrossAttentionType) -> list[tuple[str, InvokeAICrossAttentionMixin]]:
from ldm.modules.attention import CrossAttention # avoid circular import
from ldm.modules.attention import CrossAttention # avoid circular import # TODO: rename as in diffusers?
cross_attention_class: type = InvokeAIDiffusersCrossAttention if isinstance(model,UNet2DConditionModel) else CrossAttention
which_attn = "attn1" if which is CrossAttentionType.SELF else "attn2"
attention_module_tuples = [(name,module) for name, module in model.named_modules() if
@ -432,7 +431,7 @@ def get_mem_free_total(device):
class InvokeAIDiffusersCrossAttention(diffusers.models.attention.CrossAttention, InvokeAICrossAttentionMixin):
class InvokeAIDiffusersCrossAttention(diffusers.models.attention.Attention, InvokeAICrossAttentionMixin):
def __init__(self, **kwargs):
super().__init__(**kwargs)
@ -457,8 +456,8 @@ class InvokeAIDiffusersCrossAttention(diffusers.models.attention.CrossAttention,
"""
# base implementation
class CrossAttnProcessor:
def __call__(self, attn: CrossAttention, hidden_states, encoder_hidden_states=None, attention_mask=None):
class AttnProcessor:
def __call__(self, attn: Attention, hidden_states, encoder_hidden_states=None, attention_mask=None):
batch_size, sequence_length, _ = hidden_states.shape
attention_mask = attn.prepare_attention_mask(attention_mask, sequence_length)
@ -487,7 +486,7 @@ from dataclasses import field, dataclass
import torch
from diffusers.models.cross_attention import CrossAttention, CrossAttnProcessor, SlicedAttnProcessor
from diffusers.models.attention_processor import Attention, AttnProcessor, SlicedAttnProcessor
@dataclass
@ -532,7 +531,7 @@ class SlicedSwapCrossAttnProcesser(SlicedAttnProcessor):
# TODO: dynamically pick slice size based on memory conditions
def __call__(self, attn: CrossAttention, hidden_states, encoder_hidden_states=None, attention_mask=None,
def __call__(self, attn: Attention, hidden_states, encoder_hidden_states=None, attention_mask=None,
# kwargs
swap_cross_attn_context: SwapCrossAttnContext=None):

View File

@ -5,7 +5,6 @@ from typing import Callable, Optional, Union, Any
import numpy as np
import torch
from diffusers import UNet2DConditionModel
from typing_extensions import TypeAlias

View File

@ -9,7 +9,7 @@ from safetensors.torch import load_file
from torch.utils.hooks import RemovableHandle
from transformers import CLIPTextModel
from ..invoke.globals import global_lora_models_dir
from ..invoke.globals import global_lora_models_dir, Globals
from ..invoke.devices import choose_torch_device
"""
@ -456,16 +456,25 @@ class LoRA:
class KohyaLoraManager:
lora_path = Path(global_lora_models_dir())
vector_length_cache_path = lora_path / '.vectorlength.cache'
def __init__(self, pipe):
self.vector_length_cache_path = self.lora_path / '.vectorlength.cache'
self.unet = pipe.unet
self.wrapper = LoRAModuleWrapper(pipe.unet, pipe.text_encoder)
self.text_encoder = pipe.text_encoder
self.device = torch.device(choose_torch_device())
self.dtype = pipe.unet.dtype
@classmethod
@property
def lora_path(cls)->Path:
return Path(global_lora_models_dir())
@classmethod
@property
def vector_length_cache_path(cls)->Path:
return cls.lora_path / '.vectorlength.cache'
def load_lora_module(self, name, path_file, multiplier: float = 1.0):
print(f" | Found lora {name} at {path_file}")
if path_file.suffix == ".safetensors":

View File

@ -34,7 +34,7 @@ dependencies = [
"clip_anytorch",
"compel~=1.1.0",
"datasets",
"diffusers[torch]==0.14",
"diffusers[torch]~=0.15.0",
"dnspython==2.2.1",
"einops",
"eventlet",