Skip to content

Commit 144dfe4

Browse files
authored
Merge branch 'v2.3' into bugfix/lora-incompatibility-handling
2 parents 2cd0e03 + 5dbc63e commit 144dfe4

File tree

8 files changed

+156
-215
lines changed

8 files changed

+156
-215
lines changed

installer/lib/installer.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,12 @@ def app_venv(self, path: str = None):
132132

133133
# Prefer to copy python executables
134134
# so that updates to system python don't break InvokeAI
135-
if not venv_dir.exists():
136-
try:
137-
venv.create(venv_dir, with_pip=True)
138-
# If installing over an existing environment previously created with symlinks,
139-
# the executables will fail to copy. Keep symlinks in that case
140-
except shutil.SameFileError:
141-
venv.create(venv_dir, with_pip=True, symlinks=True)
135+
try:
136+
venv.create(venv_dir, with_pip=True)
137+
# If installing over an existing environment previously created with symlinks,
138+
# the executables will fail to copy. Keep symlinks in that case
139+
except shutil.SameFileError:
140+
venv.create(venv_dir, with_pip=True, symlinks=True)
142141

143142
# upgrade pip in Python 3.9 environments
144143
if int(platform.python_version_tuple()[1]) == 9:

ldm/invoke/CLI.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
import traceback
66
from argparse import Namespace
7+
from packaging import version
78
from pathlib import Path
89
from typing import Union
910

@@ -25,6 +26,7 @@
2526
from .globals import Globals, global_config_dir
2627
from .image_util import make_grid
2728
from .log import write_log
29+
from .model_manager import ModelManager
2830
from .pngwriter import PngWriter, retrieve_metadata, write_metadata
2931
from .readline import Completer, get_completer
3032
from ..util import url_attachment_name
@@ -64,6 +66,9 @@ def main():
6466
Globals.sequential_guidance = args.sequential_guidance
6567
Globals.ckpt_convert = True # always true as of 2.3.4 for LoRA support
6668

69+
# run any post-install patches needed
70+
run_patches()
71+
6772
print(f">> Internet connectivity is {Globals.internet_available}")
6873

6974
if not args.conf:
@@ -108,6 +113,9 @@ def main():
108113
if opt.lora_path:
109114
Globals.lora_models_dir = opt.lora_path
110115

116+
# migrate legacy models
117+
ModelManager.migrate_models()
118+
111119
# load the infile as a list of lines
112120
if opt.infile:
113121
try:
@@ -1291,6 +1299,62 @@ def retrieve_last_used_model()->str:
12911299
with open(model_file_path,'r') as f:
12921300
return f.readline()
12931301

1302+
# This routine performs any patch-ups needed after installation
1303+
def run_patches():
1304+
install_missing_config_files()
1305+
version_file = Path(Globals.root,'.version')
1306+
if version_file.exists():
1307+
with open(version_file,'r') as f:
1308+
root_version = version.parse(f.readline() or 'v2.3.2')
1309+
else:
1310+
root_version = version.parse('v2.3.2')
1311+
app_version = version.parse(ldm.invoke.__version__)
1312+
if root_version < app_version:
1313+
try:
1314+
do_version_update(root_version, ldm.invoke.__version__)
1315+
with open(version_file,'w') as f:
1316+
f.write(ldm.invoke.__version__)
1317+
except:
1318+
print("** Update failed. Will try again on next launch")
1319+
1320+
def install_missing_config_files():
1321+
"""
1322+
install ckpt configuration files that may have been added to the
1323+
distro after original root directory configuration
1324+
"""
1325+
import invokeai.configs as conf
1326+
from shutil import copyfile
1327+
1328+
root_configs = Path(global_config_dir(), 'stable-diffusion')
1329+
repo_configs = Path(conf.__path__[0], 'stable-diffusion')
1330+
for src in repo_configs.iterdir():
1331+
dest = root_configs / src.name
1332+
if not dest.exists():
1333+
copyfile(src,dest)
1334+
1335+
def do_version_update(root_version: version.Version, app_version: Union[str, version.Version]):
1336+
"""
1337+
Make any updates to the launcher .sh and .bat scripts that may be needed
1338+
from release to release. This is not an elegant solution. Instead, the
1339+
launcher should be moved into the source tree and installed using pip.
1340+
"""
1341+
if root_version < version.Version('v2.3.4'):
1342+
dest = Path(Globals.root,'loras')
1343+
dest.mkdir(exist_ok=True)
1344+
if root_version < version.Version('v2.3.3'):
1345+
if sys.platform == "linux":
1346+
print('>> Downloading new version of launcher script and its config file')
1347+
from ldm.util import download_with_progress_bar
1348+
url_base = f'https://raw.githubusercontent.com/invoke-ai/InvokeAI/v{str(app_version)}/installer/templates/'
1349+
1350+
dest = Path(Globals.root,'invoke.sh.in')
1351+
assert download_with_progress_bar(url_base+'invoke.sh.in',dest)
1352+
dest.replace(Path(Globals.root,'invoke.sh'))
1353+
os.chmod(Path(Globals.root,'invoke.sh'), 0o0755)
1354+
1355+
dest = Path(Globals.root,'dialogrc')
1356+
assert download_with_progress_bar(url_base+'dialogrc',dest)
1357+
dest.replace(Path(Globals.root,'.dialogrc'))
12941358

12951359
if __name__ == '__main__':
12961360
main()

ldm/invoke/config/invokeai_configure.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from shutil import get_terminal_size
2222

2323
import npyscreen
24+
import torch
2425
import transformers
2526
from diffusers import AutoencoderKL
2627
from huggingface_hub import HfFolder
@@ -663,19 +664,8 @@ def initialize_rootdir(root: str, yes_to_all: bool = False):
663664
configs_src = Path(configs.__path__[0])
664665
configs_dest = Path(root) / "configs"
665666
if not os.path.samefile(configs_src, configs_dest):
666-
shutil.copytree(configs_src,
667-
configs_dest,
668-
dirs_exist_ok=True,
669-
copy_function=shutil.copyfile,
670-
)
671-
# Fix up directory permissions so that they are writable
672-
# This can happen when running under Nix environment which
673-
# makes the runtime directory template immutable.
674-
for root,dirs,files in os.walk(os.path.join(root,name)):
675-
for d in dirs:
676-
Path(root,d).chmod(0o775)
677-
for f in files:
678-
Path(root,d).chmod(0o644)
667+
shutil.copytree(configs_src, configs_dest, dirs_exist_ok=True)
668+
679669

680670
# -------------------------------------
681671
def run_console_ui(

ldm/invoke/config/invokeai_update.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,8 @@ def invokeai_is_running()->bool:
4242
except psutil.AccessDenied:
4343
continue
4444
return False
45-
46-
def do_post_install():
47-
'''
48-
Run postinstallation script.
49-
'''
50-
print("Looking for postinstallation script to run on this version...")
51-
try:
52-
from ldm.invoke.config.post_install.py import post_install
53-
post_install()
54-
except:
55-
print("Postinstallation script not available for this version of InvokeAI")
5645

46+
5747
def welcome(versions: dict):
5848

5949
@group()
@@ -117,7 +107,6 @@ def main():
117107
print(f':heavy_check_mark: Upgrade successful')
118108
else:
119109
print(f':exclamation: [bold red]Upgrade failed[/red bold]')
120-
do_post_install()
121110

122111
if __name__ == "__main__":
123112
try:

ldm/invoke/config/model_install_backend.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,19 +398,7 @@ def update_config_file(successfully_downloaded: dict, config_file: Path):
398398
if config_file is default_config_file() and not config_file.parent.exists():
399399
configs_src = Dataset_path.parent
400400
configs_dest = default_config_file().parent
401-
shutil.copytree(configs_src,
402-
configs_dest,
403-
dirs_exist_ok=True,
404-
copy_function=shutil.copyfile,
405-
)
406-
# Fix up directory permissions so that they are writable
407-
# This can happen when running under Nix environment which
408-
# makes the runtime directory template immutable.
409-
for root,dirs,files in os.walk(default_config_file().parent):
410-
for d in dirs:
411-
Path(root,d).chmod(0o775)
412-
for f in files:
413-
Path(root,d).chmod(0o644)
401+
shutil.copytree(configs_src, configs_dest, dirs_exist_ok=True)
414402

415403
yaml = new_config_file_contents(successfully_downloaded, config_file)
416404

ldm/invoke/config/post_install.py

Lines changed: 0 additions & 168 deletions
This file was deleted.

0 commit comments

Comments
 (0)