almost all of backend migrated; restoration next

This commit is contained in:
Lincoln Stein 2023-03-02 13:28:17 -05:00
parent 1a7371ea17
commit 3f0b0f3250
76 changed files with 141 additions and 120 deletions

5
.gitignore vendored
View File

@ -213,11 +213,6 @@ gfpgan/
# config file (will be created by installer)
configs/models.yaml
# weights (will be created by installer)
# models/ldm/stable-diffusion-v1/*.ckpt
# models/clipseg
# models/gfpgan
# ignore initfile
.invokeai

View File

@ -11,10 +11,10 @@ if [[ -v "VIRTUAL_ENV" ]]; then
exit -1
fi
VERSION=$(cd ..; python -c "from ldm.invoke import __version__ as version; print(version)")
VERSION=$(cd ..; python -c "from invokeai.version import __version__ as version; print(version)")
PATCH=""
VERSION="v${VERSION}${PATCH}"
LATEST_TAG="v2.3-latest"
LATEST_TAG="v3.0-latest"
echo Building installer for version $VERSION
echo "Be certain that you're in the 'installer' directory before continuing."

View File

@ -3,5 +3,6 @@ Initialization file for invokeai.backend
'''
# this is causing circular import issues
# from .invoke_ai_web_server import InvokeAIWebServer
from .model_manager import ModelManager

View File

@ -2,5 +2,4 @@
Initialization file for the invokeai.generator package
'''
from .base import Generator
from .diffusers_pipeline import PipelineIntermediateState, StableDiffusionGeneratorPipeline
from .inpaint import infill_methods

View File

@ -22,8 +22,8 @@ from pytorch_lightning import seed_everything
from tqdm import trange
import invokeai.assets.web as web_assets
from ..ldm.models.diffusion.ddpm import DiffusionWrapper
from ..ldm.util import rand_perlin_2d
from ..stable_diffusion.diffusion.ddpm import DiffusionWrapper
from ..util import rand_perlin_2d
downsampling = 8
CAUTION_IMG = 'caution.png'

View File

@ -6,8 +6,10 @@ import torch
from diffusers import logging
from .base import Generator
from .diffusers_pipeline import StableDiffusionGeneratorPipeline, ConditioningData
from ..ldm.models.diffusion import PostprocessingSettings
from ..stable_diffusion import (StableDiffusionGeneratorPipeline,
ConditioningData,
PostprocessingSettings
)
class Img2Img(Generator):
def __init__(self, model, precision):

View File

@ -11,11 +11,12 @@ import numpy as np
import torch
from PIL import Image, ImageFilter, ImageOps, ImageChops
from .diffusers_pipeline import image_resized_to_grid_as_tensor, StableDiffusionGeneratorPipeline, \
ConditioningData
from ..stable_diffusion.diffusers_pipeline import (image_resized_to_grid_as_tensor,
StableDiffusionGeneratorPipeline,
ConditioningData
)
from .img2img import Img2Img
from ldm.invoke.patchmatch import PatchMatch
from ..ldm.util import debug_image
from ..image_util import PatchMatch, debug_image
def infill_methods()->list[str]:

View File

@ -5,8 +5,10 @@ import PIL.Image
import torch
from .base import Generator
from .diffusers_pipeline import StableDiffusionGeneratorPipeline, ConditioningData
from ..ldm.models import PostprocessingSettings
from ..stable_diffusion import (PostprocessingSettings,
StableDiffusionGeneratorPipeline,
ConditioningData
)
class Txt2Img(Generator):
def __init__(self, model, precision):

View File

@ -0,0 +1,28 @@
'''
Initialization file for invokeai.backend.image_util methods.
'''
from .patchmatch import PatchMatch
from .txt2mask import Txt2Mask
from .util import InitImageResizer, make_grid
from .pngwriter import (PngWriter,
PromptFormatter,
retrieve_metadata,
write_metadata,
)
def debug_image(
debug_image, debug_text, debug_show=True, debug_result=False, debug_status=False
):
if not debug_status:
return
image_copy = debug_image.copy().convert("RGBA")
ImageDraw.Draw(image_copy).text((5, 5), debug_text, (255, 0, 0))
if debug_show:
image_copy.show()
if debug_result:
return image_copy

View File

@ -23,16 +23,21 @@ from werkzeug.utils import secure_filename
from invokeai.backend.modules.get_canvas_generation_mode import (
get_canvas_generation_mode,
)
from invokeai.backend.modules.parameters import parameters_to_command
from .modules.parameters import parameters_to_command
from .prompting import (get_tokens_for_prompt_object,
get_prompt_structure,
get_tokenizer
)
from .image_util import PngWriter, retrieve_metadata
from .generator import infill_methods
from .stable_diffusion import PipelineIntermediateState
from ldm.generate import Generate
from ldm.invoke.args import Args, APP_ID, APP_VERSION, calculate_init_img_hash
from invokeai.backend.ldm.conditioning import get_tokens_for_prompt_object, get_prompt_structure, get_tokenizer
from .generator import infill_methods, PipelineIntermediateState
from ldm.invoke.globals import ( Globals, global_converted_ckpts_dir,
global_models_dir
)
from ldm.invoke.merge_diffusers import merge_diffusion_models
from ldm.invoke.pngwriter import PngWriter, retrieve_metadata
# Loading Arguments
opt = Args()

View File

@ -1,10 +0,0 @@
'''
Initialization file for the invokeai.backend.models package
'''
from .model_manager import ModelManager, SDLegacyType
from .diffusion import InvokeAIDiffuserComponent
from .diffusion.ddim import DDIMSampler
from .diffusion.ksampler import KSampler
from .diffusion.plms import PLMSSampler
from .diffusion.cross_attention_map_saving import AttentionMapSaver
from .diffusion.shared_invokeai_diffusion import PostprocessingSettings

View File

@ -1,10 +0,0 @@
'''
Initialization file for the invokeai.models package
'''
from .model_manager import ModelManager, SDLegacyType
from .diffusion.shared_invokeai_diffusion import InvokeAIDiffuserComponent
from .diffusion.ddim import DDIMSampler
from .diffusion.ksampler import KSampler
from .diffusion.plms import PLMSSampler
from .diffusion.cross_attention_map_saving import AttentionMapSaver
from .diffusion.shared_invokeai_diffusion import PostprocessingSettings

View File

@ -31,15 +31,14 @@ from omegaconf import OmegaConf
from omegaconf.dictconfig import DictConfig
from picklescan.scanner import scan_file_path
from ..devices import CPU_DEVICE
from .devices import CPU_DEVICE
from ldm.invoke.globals import Globals, global_cache_dir
from ..util import (
from .util import (
ask_user,
download_with_resume,
url_attachment_name,
)
from ...generator.diffusers_pipeline import StableDiffusionGeneratorPipeline
from .stable_diffusion import StableDiffusionGeneratorPipeline
class SDLegacyType(Enum):
V1 = 1

View File

@ -0,0 +1,7 @@
'''
Initialization file for invokeai.backend.prompting
'''
from .conditioning import (get_uc_and_c_and_ec,
split_weighted_subprompts,
get_tokens_for_prompt_object,
get_prompt_structure, get_tokenizer)

View File

@ -13,8 +13,8 @@ from transformers import CLIPTokenizer, CLIPTextModel
from compel import Compel
from compel.prompt_parser import FlattenedPrompt, Blend, Fragment, CrossAttentionControlSubstitute, PromptParser
from .devices import torch_dtype
from .models import InvokeAIDiffuserComponent
from ..devices import torch_dtype
from ..stable_diffusion import InvokeAIDiffuserComponent
from ldm.invoke.globals import Globals
def get_tokenizer(model) -> CLIPTokenizer:

View File

@ -0,0 +1,16 @@
'''
Initialization file for the invokeai.backend.stable_diffusion package
'''
from .diffusion import InvokeAIDiffuserComponent
from .diffusion.ddim import DDIMSampler
from .diffusion.ksampler import KSampler
from .diffusion.plms import PLMSSampler
from .diffusion.cross_attention_map_saving import AttentionMapSaver
from .diffusion.shared_invokeai_diffusion import PostprocessingSettings
from .textual_inversion_manager import TextualInversionManager
from .concepts_lib import HuggingFaceConceptsLibrary
from .diffusers_pipeline import (StableDiffusionGeneratorPipeline,
ConditioningData,
PipelineIntermediateState,
StableDiffusionGeneratorPipeline
)

View File

@ -7,7 +7,7 @@ import torch.nn.functional as F
from torch import nn, einsum
from einops import rearrange, repeat
from ..models.diffusion import InvokeAICrossAttentionMixin
from .diffusion import InvokeAICrossAttentionMixin
from .diffusionmodules.util import checkpoint
def exists(val):

View File

@ -5,8 +5,8 @@ from contextlib import contextmanager
from taming.modules.vqvae.quantize import VectorQuantizer2 as VectorQuantizer
from ..modules.diffusionmodules.model import Encoder, Decoder
from ..modules.distributions.distributions import (
from .diffusionmodules.model import Encoder, Decoder
from .distributions.distributions import (
DiagonalGaussianDistribution,
)

View File

@ -27,11 +27,10 @@ from transformers import CLIPFeatureExtractor, CLIPTextModel, CLIPTokenizer
from typing_extensions import ParamSpec
from ldm.invoke.globals import Globals
from ..ldm.models.diffusion import InvokeAIDiffuserComponent, PostprocessingSettings
from ..ldm.modules.textual_inversion_manager import TextualInversionManager
from ..ldm.devices import normalize_device, CPU_DEVICE
from ..ldm.offloading import LazilyLoadedModelGroup, FullyLoadedModelGroup, ModelGroup
from ..ldm.models.diffusion import AttentionMapSaver
from ..stable_diffusion.diffusion import InvokeAIDiffuserComponent, PostprocessingSettings, AttentionMapSaver
from ..stable_diffusion.textual_inversion_manager import TextualInversionManager
from ..stable_diffusion.offloading import LazilyLoadedModelGroup, FullyLoadedModelGroup, ModelGroup
from ..devices import normalize_device, CPU_DEVICE
from compel import EmbeddingsProvider
@dataclass

View File

@ -3,7 +3,7 @@
import torch
from .shared_invokeai_diffusion import InvokeAIDiffuserComponent
from .sampler import Sampler
from ...modules.diffusionmodules.util import noise_like
from ..diffusionmodules.util import noise_like
class DDIMSampler(Sampler):
def __init__(self, model, schedule='linear', device=None, **kwargs):

View File

@ -22,7 +22,7 @@ from pytorch_lightning.utilities.distributed import rank_zero_only
from omegaconf import ListConfig
import urllib
from ...modules.textual_inversion_manager import TextualInversionManager
from ..textual_inversion_manager import TextualInversionManager
from ...util import (
log_txt_as_img,
exists,
@ -33,8 +33,8 @@ from ...util import (
count_params,
instantiate_from_config,
)
from ...modules.ema import LitEma
from ...modules.distributions.distributions import (
from ..ema import LitEma
from ..distributions.distributions import (
normal_kl,
DiagonalGaussianDistribution,
)
@ -43,7 +43,7 @@ from ..autoencoder import (
IdentityFirstStage,
AutoencoderKL,
)
from ...modules.diffusionmodules.util import (
from ..diffusionmodules.util import (
make_beta_schedule,
extract_into_tensor,
noise_like,

View File

@ -7,7 +7,7 @@ from functools import partial
from ...devices import choose_torch_device
from .shared_invokeai_diffusion import InvokeAIDiffuserComponent
from .sampler import Sampler
from ...modules.diffusionmodules.util import noise_like
from ..diffusionmodules.util import noise_like
class PLMSSampler(Sampler):

View File

@ -10,7 +10,7 @@ from functools import partial
from ...devices import choose_torch_device
from .shared_invokeai_diffusion import InvokeAIDiffuserComponent
from ...modules.diffusionmodules.util import (
from ..diffusionmodules.util import (
make_ddim_sampling_parameters,
make_ddim_timesteps,
noise_like,

View File

Before

Width:  |  Height:  |  Size: 431 KiB

After

Width:  |  Height:  |  Size: 431 KiB

View File

@ -9,7 +9,7 @@ from picklescan.scanner import scan_file_path
from transformers import CLIPTextModel, CLIPTokenizer
from compel.embeddings_provider import BaseTextualInversionManager
from ..concepts_lib import HuggingFaceConceptsLibrary
from .concepts_lib import HuggingFaceConceptsLibrary
@dataclass

View File

@ -17,7 +17,6 @@ from tqdm import tqdm
from .devices import torch_dtype
def log_txt_as_img(wh, xc, size=10):
# wh a tuple of (width, height)
# xc a list of captions to plot
@ -280,22 +279,6 @@ def ask_user(question: str, answers: list):
return valid_response
def debug_image(
debug_image, debug_text, debug_show=True, debug_result=False, debug_status=False
):
if not debug_status:
return
image_copy = debug_image.copy().convert("RGBA")
ImageDraw.Draw(image_copy).text((5, 5), debug_text, (255, 0, 0))
if debug_show:
image_copy.show()
if debug_result:
return image_copy
# -------------------------------------
def download_with_resume(url: str, dest: Path, access_token: str = None) -> Path:
'''

View File

@ -1,8 +1,15 @@
from ._version import __version__
'''
initialization file for invokeai
'''
import invokeai
from .invokeai_version import __version__
__app_id__= 'invoke-ai/InvokeAI'
__app_name__= 'InvokeAI'
# copy these attributes into the invokeai namespace
setattr(invokeai,'__version__',__version__)
setattr(invokeai,'__app_id__',__app_id__)
setattr(invokeai,'__app_name__',__app_name__)
def _ignore_xformers_triton_message_on_windows():
import logging

View File

@ -25,19 +25,17 @@ from omegaconf import OmegaConf
from PIL import Image, ImageOps
from pytorch_lightning import logging, seed_everything
import invokeai.backend.ldm.conditioning
from invokeai.backend.ldm.models import (ModelManager,DDIMSampler, KSampler, PLMSSampler)
from invokeai.backend import ModelManager
from invokeai.backend.prompting import get_uc_and_c_and_ec
from invokeai.backend.stable_diffusion import (DDIMSampler, KSampler, PLMSSampler)
from invokeai.backend.generator import infill_methods
from ldm.invoke.args import metadata_from_png
from invokeai.backend.ldm.concepts_lib import HuggingFaceConceptsLibrary
from invokeai.backend.ldm.conditioning import get_uc_and_c_and_ec
from invokeai.backend.ldm.devices import choose_precision, choose_torch_device
from invokeai.backend.stable_diffusion.concepts_lib import HuggingFaceConceptsLibrary
from invokeai.backend.devices import choose_precision, choose_torch_device
from invokeai.backend.image_util import InitImageResizer, PngWriter, Txt2Mask
from ldm.invoke.globals import Globals, global_cache_dir
from ldm.invoke.image_util import InitImageResizer
from ldm.invoke.pngwriter import PngWriter
from ldm.invoke.args import metadata_from_png
from ldm.invoke.seamless import configure_model_padding
from ldm.invoke.txt2mask import Txt2Mask
def fix_func(orig):
if hasattr(torch.backends, "mps") and torch.backends.mps.is_available():

View File

@ -16,19 +16,18 @@ if sys.platform == "darwin":
import pyparsing # type: ignore
import ldm.invoke
import invokeai.version
from ..generate import Generate
from .args import (Args, dream_cmd_from_png, metadata_dumps,
metadata_from_png)
from invokeai.backend.generator import PipelineIntermediateState
from invokeai.backend.stable_diffusion import PipelineIntermediateState
from invokeai.backend.image_util import make_grid, PngWriter, retrieve_metadata, write_metadata
from invokeai.backend import ModelManager
from .globals import Globals
from .image_util import make_grid
from .log import write_log
from invokeai.backend.ldm.models import ModelManager
from .pngwriter import PngWriter, retrieve_metadata, write_metadata
from .readline import Completer, get_completer
from invokeai.backend.ldm.util import url_attachment_name
from invokeai.backend.util import url_attachment_name
# global used in multiple functions (fix)
infile = None
@ -75,7 +74,7 @@ def main():
opt, FileNotFoundError(f"The file {config_file} could not be found.")
)
print(f">> {ldm.invoke.__app_name__}, version {ldm.invoke.__version__}")
print(f">> {invokeai.__app_name__}, version {invokeai.__version__}")
print(f'>> InvokeAI runtime directory is "{Globals.root}"')
# loading here to avoid long delays on startup

View File

@ -8,7 +8,7 @@ from pathlib import Path
from queue import Queue
from typing import Dict
from PIL.Image import Image
from ...pngwriter import PngWriter
from invokeai.backend.image_util import PngWriter
class ImageType(str, Enum):

View File

@ -95,15 +95,15 @@ from argparse import Namespace
from pathlib import Path
from typing import List
import ldm.invoke
import ldm.invoke.pngwriter
from invokeai.backend.ldm.conditioning import split_weighted_subprompts
from invokeai.backend.image_util import retrieve_metadata
import invokeai.version
from ldm.invoke.globals import Globals
from invokeai.backend.prompting import split_weighted_subprompts
APP_ID = ldm.invoke.__app_id__
APP_NAME = ldm.invoke.__app_name__
APP_VERSION = ldm.invoke.__version__
APP_ID = invokeai.version.__app_id__
APP_NAME = invokeai.version.__app_name__
APP_VERSION = invokeai.version.__version__
SAMPLER_CHOICES = [
'ddim',
@ -182,7 +182,7 @@ class Args(object):
# and intercept --version request
switches = self._arg_parser.parse_args(sysargs)
if switches.version:
print(f'{ldm.invoke.__app_name__} {ldm.invoke.__version__}')
print(f'{APP_NAME} {APP_VERSION}')
sys.exit(0)
print('* Initializing, be patient...')
@ -1170,8 +1170,8 @@ def metadata_dumps(opt,
'model' : 'stable diffusion',
'model_id' : opt.model,
'model_hash' : model_hash,
'app_id' : ldm.invoke.__app_id__,
'app_version' : ldm.invoke.__version__,
'app_id' : APP_ID,
'app_version' : APP_VERSION,
}
# # add some RFC266 fields that are generated internally, and not as
@ -1242,7 +1242,7 @@ def args_from_png(png_file_path) -> list[Args]:
data.
'''
try:
meta = ldm.invoke.pngwriter.retrieve_metadata(png_file_path)
meta = retrieve_metadata(png_file_path)
except AttributeError:
return [legacy_metadata_load({},png_file_path)]

View File

@ -22,7 +22,7 @@ from npyscreen import widget
from omegaconf import OmegaConf
from shutil import get_terminal_size
from invokeai.backend.ldm.devices import choose_precision, choose_torch_device
from invokeai.backend.devices import choose_precision, choose_torch_device
from ..globals import Globals, global_config_dir
from .model_install_backend import (Dataset_path, default_config_file,
default_dataset, get_root,

View File

@ -18,9 +18,9 @@ from tqdm import tqdm
from typing import List
import invokeai.configs as configs
from invokeai.backend.generator import StableDiffusionGeneratorPipeline
from invokeai.backend.stable_diffusion import StableDiffusionGeneratorPipeline
from ..globals import Globals, global_cache_dir, global_config_dir
from invokeai.backend.ldm.models import ModelManager
from invokeai.backend import ModelManager
warnings.filterwarnings("ignore")

View File

@ -23,7 +23,7 @@ from omegaconf import OmegaConf
from ldm.invoke.config.widgets import FloatTitleSlider
from ldm.invoke.globals import (Globals, global_cache_dir, global_config_file,
global_models_dir, global_set_root)
from invokeai.backend.ldm.models import ModelManager
from invokeai.backend import ModelManager
DEST_MERGED_MODEL_DIR = "merged_models"

View File

@ -12,8 +12,8 @@ import os
import re
import atexit
from ldm.invoke.args import Args
from invokeai.backend.ldm.concepts_lib import HuggingFaceConceptsLibrary
from ldm.invoke.globals import Globals
from invokeai.backend.stable_diffusion import HuggingFaceConceptsLibrary
# ---------------readline utilities---------------------
try:

View File

@ -125,15 +125,15 @@ dependencies = [
"Discord" = "https://discord.gg/ZmtBAhwWhy"
[tool.setuptools.dynamic]
version = { attr = "ldm.invoke.__version__" }
version = { attr = "invokeai.version.__version__" }
[tool.setuptools.packages.find]
"where" = ["."]
"include" = [
"invokeai.assets.web*",
"invokeai.assets.web*","invokeai.version*",
"invokeai.generator*","invokeai.backend*",
"invokeai.frontend.dist*", "invokeai.configs*",
"ldm*"
"ldm*",
]
[tool.setuptools.package-data]

View File

@ -4,7 +4,7 @@ from typing import Union
import torch
from ldm.modules.textual_inversion_manager import TextualInversionManager
from invokeai.backend.stable_diffusion import TextualInversionManager
KNOWN_WORDS = ['a', 'b', 'c']