From 3c570421d3a2eb24528b5f5bb615dcb0c7717e4a Mon Sep 17 00:00:00 2001 From: wfjsw Date: Tue, 18 Jul 2023 19:00:16 +0800 Subject: move start timer --- launch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index b103c8f3..e9667c88 100644 --- a/launch.py +++ b/launch.py @@ -1,4 +1,4 @@ -from modules import launch_utils +from modules import launch_utils, timer args = launch_utils.args @@ -25,6 +25,8 @@ start = launch_utils.start def main(): + timer.startup_timer.record("start") + if not args.skip_prepare_environment: prepare_environment() -- cgit v1.2.3 From 136c8859a49a35cbffe269aafc0bbdfca0b3561d Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Tue, 18 Jul 2023 20:11:30 +0300 Subject: add backwards compatibility --lyco-dir-backcompat option, use that for LyCORIS directory instead of hardcoded value prevent running preload.py for disabled extensions --- CHANGELOG.md | 4 +--- extensions-builtin/Lora/networks.py | 4 ++-- extensions-builtin/Lora/preload.py | 1 + extensions-builtin/Lora/ui_extra_networks_lora.py | 4 ++-- launch.py | 1 + modules/script_loading.py | 5 +++-- modules/shared.py | 3 ++- 7 files changed, 12 insertions(+), 10 deletions(-) (limited to 'launch.py') diff --git a/CHANGELOG.md b/CHANGELOG.md index 007010da..792529ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,9 +58,7 @@ * fix: check fill size none zero when resize (fixes #11425) * use submit and blur for quick settings textbox * save img2img batch with images.save_image() - * - - + * prevent running preload.py for disabled extensions ## 1.4.1 diff --git a/extensions-builtin/Lora/networks.py b/extensions-builtin/Lora/networks.py index 7b4c0312..af8188e3 100644 --- a/extensions-builtin/Lora/networks.py +++ b/extensions-builtin/Lora/networks.py @@ -11,7 +11,7 @@ import network_full import torch from typing import Union -from modules import shared, devices, sd_models, errors, scripts, sd_hijack, paths +from modules import shared, devices, sd_models, errors, scripts, sd_hijack module_types = [ network_lora.ModuleTypeLora(), @@ -399,7 +399,7 @@ def list_available_networks(): os.makedirs(shared.cmd_opts.lora_dir, exist_ok=True) candidates = list(shared.walk_files(shared.cmd_opts.lora_dir, allowed_extensions=[".pt", ".ckpt", ".safetensors"])) - candidates += list(shared.walk_files(os.path.join(paths.models_path, "LyCORIS"), allowed_extensions=[".pt", ".ckpt", ".safetensors"])) + candidates += list(shared.walk_files(shared.cmd_opts.lyco_dir_backcompat, allowed_extensions=[".pt", ".ckpt", ".safetensors"])) for filename in candidates: if os.path.isdir(filename): continue diff --git a/extensions-builtin/Lora/preload.py b/extensions-builtin/Lora/preload.py index 863dc5c0..50961be3 100644 --- a/extensions-builtin/Lora/preload.py +++ b/extensions-builtin/Lora/preload.py @@ -4,3 +4,4 @@ from modules import paths def preload(parser): parser.add_argument("--lora-dir", type=str, help="Path to directory with Lora networks.", default=os.path.join(paths.models_path, 'Lora')) + parser.add_argument("--lyco-dir-backcompat", type=str, help="Path to directory with LyCORIS networks (for backawards compatibility; can also use --lyco-dir).", default=os.path.join(paths.models_path, 'LyCORIS')) diff --git a/extensions-builtin/Lora/ui_extra_networks_lora.py b/extensions-builtin/Lora/ui_extra_networks_lora.py index 4b32098b..3629e5c0 100644 --- a/extensions-builtin/Lora/ui_extra_networks_lora.py +++ b/extensions-builtin/Lora/ui_extra_networks_lora.py @@ -3,7 +3,7 @@ import os import network import networks -from modules import shared, ui_extra_networks, paths +from modules import shared, ui_extra_networks from modules.ui_extra_networks import quote_js from ui_edit_user_metadata import LoraUserMetadataEditor @@ -72,7 +72,7 @@ class ExtraNetworksPageLora(ui_extra_networks.ExtraNetworksPage): yield item def allowed_directories_for_previews(self): - return [shared.cmd_opts.lora_dir, os.path.join(paths.models_path, "LyCORIS")] + return [shared.cmd_opts.lora_dir, shared.cmd_opts.lyco_dir_backcompat] def create_user_metadata_editor(self, ui, tabname): return LoraUserMetadataEditor(ui, tabname, self) diff --git a/launch.py b/launch.py index b103c8f3..1dbc4c6e 100644 --- a/launch.py +++ b/launch.py @@ -18,6 +18,7 @@ run_pip = launch_utils.run_pip check_run_python = launch_utils.check_run_python git_clone = launch_utils.git_clone git_pull_recursive = launch_utils.git_pull_recursive +list_extensions = launch_utils.list_extensions run_extension_installer = launch_utils.run_extension_installer prepare_environment = launch_utils.prepare_environment configure_for_tests = launch_utils.configure_for_tests diff --git a/modules/script_loading.py b/modules/script_loading.py index 306a1f35..0d55f193 100644 --- a/modules/script_loading.py +++ b/modules/script_loading.py @@ -12,11 +12,12 @@ def load_module(path): return module -def preload_extensions(extensions_dir, parser): +def preload_extensions(extensions_dir, parser, extension_list=None): if not os.path.isdir(extensions_dir): return - for dirname in sorted(os.listdir(extensions_dir)): + extensions = extension_list if extension_list is not None else os.listdir(extensions_dir) + for dirname in sorted(extensions): preload_script = os.path.join(extensions_dir, dirname, "preload.py") if not os.path.isfile(preload_script): continue diff --git a/modules/shared.py b/modules/shared.py index 6162938a..1ce7b49e 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -11,6 +11,7 @@ import gradio as gr import torch import tqdm +import launch import modules.interrogate import modules.memmon import modules.styles @@ -26,7 +27,7 @@ demo = None parser = cmd_args.parser -script_loading.preload_extensions(extensions_dir, parser) +script_loading.preload_extensions(extensions_dir, parser, extension_list=launch.list_extensions(launch.args.ui_settings_file)) script_loading.preload_extensions(extensions_builtin_dir, parser) if os.environ.get('IGNORE_CMD_ARGS_ERRORS', None) is None: -- cgit v1.2.3 From 33694baea1a886021e19da27b4ff41898428cbbd Mon Sep 17 00:00:00 2001 From: Jabasukuriputo Wang Date: Fri, 21 Jul 2023 17:15:44 +0800 Subject: avoid importing timer when it is not strictly needed --- launch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 370f2bf3..114466cf 100644 --- a/launch.py +++ b/launch.py @@ -1,4 +1,4 @@ -from modules import launch_utils, timer +from modules import launch_utils args = launch_utils.args @@ -26,6 +26,7 @@ start = launch_utils.start def main(): + from modules import timer timer.startup_timer.record("start") if not args.skip_prepare_environment: -- cgit v1.2.3 From 90eb731ff1d73fdc5872ff9682d5c88c9737ba38 Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Sat, 22 Jul 2023 12:21:05 +0300 Subject: start timer early anyway --- launch.py | 3 --- modules/launch_utils.py | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 114466cf..d46e9e27 100644 --- a/launch.py +++ b/launch.py @@ -1,6 +1,5 @@ from modules import launch_utils - args = launch_utils.args python = launch_utils.python git = launch_utils.git @@ -26,8 +25,6 @@ start = launch_utils.start def main(): - from modules import timer - timer.startup_timer.record("start") if not args.skip_prepare_environment: prepare_environment() diff --git a/modules/launch_utils.py b/modules/launch_utils.py index aaa671ab..18b444d4 100644 --- a/modules/launch_utils.py +++ b/modules/launch_utils.py @@ -10,6 +10,7 @@ from functools import lru_cache from modules import cmd_args, errors from modules.paths_internal import script_path, extensions_dir +from modules import timer # noqa:F401 args, _ = cmd_args.parser.parse_known_args() -- cgit v1.2.3 From c76a30af41e50932847230631d26bfa9635ebd62 Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Sat, 22 Jul 2023 13:49:29 +0300 Subject: more info for startup timings --- launch.py | 6 ++++-- modules/launch_utils.py | 26 +++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index d46e9e27..e4c2ce99 100644 --- a/launch.py +++ b/launch.py @@ -25,9 +25,11 @@ start = launch_utils.start def main(): + launch_utils.startup_timer.record("initial startup") - if not args.skip_prepare_environment: - prepare_environment() + with launch_utils.startup_timer.subcategory("prepare environment"): + if not args.skip_prepare_environment: + prepare_environment() if args.test_server: configure_for_tests() diff --git a/modules/launch_utils.py b/modules/launch_utils.py index 18b444d4..0178e1b0 100644 --- a/modules/launch_utils.py +++ b/modules/launch_utils.py @@ -10,7 +10,7 @@ from functools import lru_cache from modules import cmd_args, errors from modules.paths_internal import script_path, extensions_dir -from modules import timer # noqa:F401 +from modules.timer import startup_timer args, _ = cmd_args.parser.parse_known_args() @@ -224,8 +224,10 @@ def run_extensions_installers(settings_file): if not os.path.isdir(extensions_dir): return - for dirname_extension in list_extensions(settings_file): - run_extension_installer(os.path.join(extensions_dir, dirname_extension)) + with startup_timer.subcategory("run extensions installers"): + for dirname_extension in list_extensions(settings_file): + run_extension_installer(os.path.join(extensions_dir, dirname_extension)) + startup_timer.record(dirname_extension) re_requirement = re.compile(r"\s*([-_a-zA-Z0-9]+)\s*(?:==\s*([-+_.a-zA-Z0-9]+))?\s*") @@ -298,8 +300,11 @@ def prepare_environment(): if not args.skip_python_version_check: check_python_version() + startup_timer.record("checks") + commit = commit_hash() tag = git_tag() + startup_timer.record("git version info") print(f"Python {sys.version}") print(f"Version: {tag}") @@ -307,21 +312,27 @@ def prepare_environment(): if args.reinstall_torch or not is_installed("torch") or not is_installed("torchvision"): run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True) + startup_timer.record("install torch") if not args.skip_torch_cuda_test and not check_run_python("import torch; assert torch.cuda.is_available()"): raise RuntimeError( 'Torch is not able to use GPU; ' 'add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check' ) + startup_timer.record("torch GPU test") + if not is_installed("gfpgan"): run_pip(f"install {gfpgan_package}", "gfpgan") + startup_timer.record("install gfpgan") if not is_installed("clip"): run_pip(f"install {clip_package}", "clip") + startup_timer.record("install clip") if not is_installed("open_clip"): run_pip(f"install {openclip_package}", "open_clip") + startup_timer.record("install open_clip") if (not is_installed("xformers") or args.reinstall_xformers) and args.xformers: if platform.system() == "Windows": @@ -335,8 +346,11 @@ def prepare_environment(): elif platform.system() == "Linux": run_pip(f"install -U -I --no-deps {xformers_package}", "xformers") + startup_timer.record("install xformers") + if not is_installed("ngrok") and args.ngrok: run_pip("install ngrok", "ngrok") + startup_timer.record("install ngrok") os.makedirs(os.path.join(script_path, dir_repos), exist_ok=True) @@ -346,22 +360,28 @@ def prepare_environment(): git_clone(codeformer_repo, repo_dir('CodeFormer'), "CodeFormer", codeformer_commit_hash) git_clone(blip_repo, repo_dir('BLIP'), "BLIP", blip_commit_hash) + startup_timer.record("clone repositores") + if not is_installed("lpips"): run_pip(f"install -r \"{os.path.join(repo_dir('CodeFormer'), 'requirements.txt')}\"", "requirements for CodeFormer") + startup_timer.record("install CodeFormer requirements") if not os.path.isfile(requirements_file): requirements_file = os.path.join(script_path, requirements_file) if not requirements_met(requirements_file): run_pip(f"install -r \"{requirements_file}\"", "requirements") + startup_timer.record("install requirements") run_extensions_installers(settings_file=args.ui_settings_file) if args.update_check: version_check(commit) + startup_timer.record("check version") if args.update_all_extensions: git_pull_recursive(extensions_dir) + startup_timer.record("update extensions") if "--exit" in sys.argv: print("Exiting because of --exit argument") -- cgit v1.2.3