From f751dcd245174d6b86966d4a12c8774ac4f76e1b Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Thu, 23 Mar 2023 15:21:58 -0400 Subject: [PATCH 1/4] load embeddings after a ckpt legacy model is converted to diffusers - Fixes #2954 - Also improves diagnostic reporting during embedding loading. --- invokeai/backend/model_management/model_manager.py | 2 +- invokeai/backend/stable_diffusion/concepts_lib.py | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/invokeai/backend/model_management/model_manager.py b/invokeai/backend/model_management/model_manager.py index 9464057f71..c64560baf8 100644 --- a/invokeai/backend/model_management/model_manager.py +++ b/invokeai/backend/model_management/model_manager.py @@ -362,6 +362,7 @@ class ModelManager(object): raise NotImplementedError( f"Unknown model format {model_name}: {model_format}" ) + self._add_embeddings_to_model(model) # usage statistics toc = time.time() @@ -436,7 +437,6 @@ class ModelManager(object): height = width print(f" | Default image dimensions = {width} x {height}") - self._add_embeddings_to_model(pipeline) return pipeline, width, height, model_hash diff --git a/invokeai/backend/stable_diffusion/concepts_lib.py b/invokeai/backend/stable_diffusion/concepts_lib.py index 50ff6c16c9..28167a0bd5 100644 --- a/invokeai/backend/stable_diffusion/concepts_lib.py +++ b/invokeai/backend/stable_diffusion/concepts_lib.py @@ -6,7 +6,6 @@ The interface is through the Concepts() object. """ import os import re -import traceback from typing import Callable from urllib import error as ul_error from urllib import request @@ -15,7 +14,6 @@ from huggingface_hub import ( HfApi, HfFolder, ModelFilter, - ModelSearchArguments, hf_hub_url, ) @@ -84,7 +82,7 @@ class HuggingFaceConceptsLibrary(object): """ if not concept_name in self.list_concepts(): print( - f"This concept is not a local embedding trigger, nor is it a HuggingFace concept. Generation will continue without the concept." + f"{concept_name} is not a local embedding trigger, nor is it a HuggingFace concept. Generation will continue without the concept." ) return None return self.get_concept_file(concept_name.lower(), "learned_embeds.bin") @@ -236,7 +234,7 @@ class HuggingFaceConceptsLibrary(object): except ul_error.HTTPError as e: if e.code == 404: print( - f"This concept is not known to the Hugging Face library. Generation will continue without the concept." + f"Concept {concept_name} is not known to the Hugging Face library. Generation will continue without the concept." ) else: print( @@ -246,7 +244,7 @@ class HuggingFaceConceptsLibrary(object): return False except ul_error.URLError as e: print( - f"ERROR: {str(e)}. This may reflect a network issue. Generation will continue without the concept." + f"ERROR while downloading {concept_name}: {str(e)}. This may reflect a network issue. Generation will continue without the concept." ) os.rmdir(dest) return False From 02c58f22be2c386da360ec2c58eeda43a2a7eb18 Mon Sep 17 00:00:00 2001 From: Damian Stewart Date: Thu, 23 Mar 2023 22:34:54 +0100 Subject: [PATCH 2/4] upgrade compel for better .swap defaults and a bugfix --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4760035174..a8f3fcbbbe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ dependencies = [ "albumentations", "click", "clip_anytorch", # replacing "clip @ https://github.com/openai/CLIP/archive/eaa22acb90a5876642d0507623e859909230a52d.zip", - "compel==1.0.1", + "compel==1.0.4", "datasets", "diffusers[torch]~=0.14", "dnspython==2.2.1", From f329fddab9073b0bd882da4891691b34ac75cbfb Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Wed, 15 Mar 2023 01:17:23 -0400 Subject: [PATCH 3/4] make step_callback work again in generate() call This PR fixes #2951 and restores the step_callback argument in the refactored generate() method. Note that this issue states that "something is still wrong because steps and step are zero." However, I think this is confusion over the call signature of the callback, which since the diffusers merge has been `callback(state:PipelineIntermediateState)` This is the test script that I used to determine that `step` is being passed correctly: ``` from pathlib import Path from invokeai.backend import ModelManager, PipelineIntermediateState from invokeai.backend.globals import global_config_dir from invokeai.backend.generator import Txt2Img def my_callback(state:PipelineIntermediateState, total_steps:int): print(f'callback(step={state.step}/{total_steps})') def main(): manager = ModelManager(Path(global_config_dir()) / "models.yaml") model = manager.get_model('stable-diffusion-1.5') print ('=== TXT2IMG TEST ===') steps=30 output = next(Txt2Img(model).generate(prompt='banana sushi', iterations=None, steps=steps, step_callback=lambda x: my_callback(x,steps) ) ) print(f'image={output.image}, seed={output.seed}, steps={output.params.steps}') if __name__=='__main__': main() ``` --- invokeai/backend/__init__.py | 1 + invokeai/backend/generator/base.py | 1 + 2 files changed, 2 insertions(+) diff --git a/invokeai/backend/__init__.py b/invokeai/backend/__init__.py index 06066dd6b1..662700e9ba 100644 --- a/invokeai/backend/__init__.py +++ b/invokeai/backend/__init__.py @@ -10,6 +10,7 @@ from .generator import ( Img2Img, Inpaint ) +from .stable_diffusion.diffusers_pipeline import PipelineIntermediateState from .model_management import ModelManager from .safety_checker import SafetyChecker from .args import Args diff --git a/invokeai/backend/generator/base.py b/invokeai/backend/generator/base.py index 125f208b0a..e30b77ec33 100644 --- a/invokeai/backend/generator/base.py +++ b/invokeai/backend/generator/base.py @@ -154,6 +154,7 @@ class InvokeAIGenerator(metaclass=ABCMeta): for i in iteration_count: results = generator.generate(prompt, conditioning=(uc, c, extra_conditioning_info), + step_callback=step_callback, sampler=scheduler, **generator_args, ) From 92721a1d45365455579e96cfab35a7e4640fcaf5 Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Wed, 15 Mar 2023 01:39:37 -0400 Subject: [PATCH 4/4] do not reexport PipelineIntermediateState --- invokeai/backend/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/invokeai/backend/__init__.py b/invokeai/backend/__init__.py index 662700e9ba..06066dd6b1 100644 --- a/invokeai/backend/__init__.py +++ b/invokeai/backend/__init__.py @@ -10,7 +10,6 @@ from .generator import ( Img2Img, Inpaint ) -from .stable_diffusion.diffusers_pipeline import PipelineIntermediateState from .model_management import ModelManager from .safety_checker import SafetyChecker from .args import Args