From d0c7eeba6234f8d3214bd10d9b2349838d14a71c Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Fri, 16 Dec 2022 18:56:48 +0000 Subject: [PATCH 1/2] add --version to invoke.py arguments This commit allows invoke.py to print out its name and version number when given the --version argument. I had to move some status messages around in order to make the output clean. There is still an early message about initializing patchmatch that interferes with a clean print of the version, and in fact the --no-patchmatch argument is not doing anything. This will be the subject of a subsequent PR. --- installer/create_installer.sh | 2 +- ldm/generate.py | 3 +-- ldm/invoke/CLI.py | 6 +----- ldm/invoke/__init__.py | 2 ++ ldm/invoke/args.py | 26 ++++++++++++++++++-------- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/installer/create_installer.sh b/installer/create_installer.sh index 4be13e3fed0..3e2f339f578 100755 --- a/installer/create_installer.sh +++ b/installer/create_installer.sh @@ -3,7 +3,7 @@ cd "$(dirname "$0")" VERSION=$(grep ^VERSION ../setup.py | awk '{ print $3 }' | sed "s/'//g" ) -VERSION="$VERSION-p1" +VERSION="$VERSION-p3" echo "Be certain that you're in the 'installer' directory before continuing." read -p "Press any key to continue, or CTRL-C to exit..." diff --git a/ldm/generate.py b/ldm/generate.py index db367171355..5feb221c2af 100644 --- a/ldm/generate.py +++ b/ldm/generate.py @@ -42,6 +42,7 @@ from ldm.invoke.seamless import configure_model_padding from ldm.invoke.txt2mask import Txt2Mask, SegmentedGrayscale from ldm.invoke.concepts_lib import Concepts +from ldm.invoke.generator.inpaint import infill_methods def fix_func(orig): if hasattr(torch.backends, 'mps') and torch.backends.mps.is_available(): @@ -265,8 +266,6 @@ def img2img(self, prompt, **kwargs): ), 'call to img2img() must include the init_img argument' return self.prompt2png(prompt, outdir, **kwargs) - from ldm.invoke.generator.inpaint import infill_methods - def prompt2image( self, # these are common diff --git a/ldm/invoke/CLI.py b/ldm/invoke/CLI.py index 6fc441aac6b..4c4b69ef3d0 100644 --- a/ldm/invoke/CLI.py +++ b/ldm/invoke/CLI.py @@ -8,8 +8,8 @@ import traceback import yaml -from ldm.generate import Generate from ldm.invoke.globals import Globals +from ldm.generate import Generate from ldm.invoke.prompt_parser import PromptParser from ldm.invoke.readline import get_completer, Completer from ldm.invoke.args import Args, metadata_dumps, metadata_from_png, dream_cmd_from_png @@ -27,7 +27,6 @@ def main(): """Initialize command-line parsers and the diffusion model""" global infile - print('* Initializing, be patient...') opt = Args() args = opt.parse_args() @@ -45,9 +44,6 @@ def main(): print('--max_loaded_models must be >= 1; using 1') args.max_loaded_models = 1 - # alert - setting a global here - Globals.try_patchmatch = args.patchmatch - if not args.conf: if not os.path.exists(os.path.join(Globals.root,'configs','models.yaml')): print(f"\n** Error. The file {os.path.join(Globals.root,'configs','models.yaml')} could not be found.") diff --git a/ldm/invoke/__init__.py b/ldm/invoke/__init__.py index f9a95b03435..083fe50b0ce 100644 --- a/ldm/invoke/__init__.py +++ b/ldm/invoke/__init__.py @@ -1 +1,3 @@ +__app_id__= 'invoke-ai/InvokeAI' +__app_name__= 'InvokeAI' __version__='2.2.4' diff --git a/ldm/invoke/args.py b/ldm/invoke/args.py index 98a75c98867..db547a56cc7 100644 --- a/ldm/invoke/args.py +++ b/ldm/invoke/args.py @@ -93,6 +93,7 @@ import base64 import functools import warnings +import ldm.invoke import ldm.invoke.pngwriter from ldm.invoke.globals import Globals from ldm.invoke.prompt_parser import split_weighted_subprompts @@ -117,10 +118,6 @@ 'float16', ] -# is there a way to pick this up during git commits? -APP_ID = 'invoke-ai/InvokeAI' -APP_VERSION = 'v2.2.4' - class ArgFormatter(argparse.RawTextHelpFormatter): # use defined argument order to display usage def _format_usage(self, usage, actions, groups, prefix): @@ -172,15 +169,22 @@ def parse_args(self): '''Parse the shell switches and store.''' try: sysargs = sys.argv[1:] - # pre-parse to get the root directory; ignore the rest + # pre-parse before we do any initialization to get root directory + # and intercept --version request switches = self._arg_parser.parse_args(sysargs) + if switches.version: + print(f'{ldm.invoke.__app_name__} {ldm.invoke.__version__}') + sys.exit(0) + + print('* Initializing, be patient...') Globals.root = os.path.abspath(switches.root_dir or Globals.root) + Globals.try_patchmatch = switches.patchmatch # now use root directory to find the init file initfile = os.path.expanduser(os.path.join(Globals.root,Globals.initfile)) legacyinit = os.path.expanduser('~/.invokeai') if os.path.exists(initfile): - print(f'>> Initialization file {initfile} found. Loading...') + print(f'>> Initialization file {initfile} found. Loading...',file=sys.stderr) sysargs.insert(0,f'@{initfile}') elif os.path.exists(legacyinit): print(f'>> WARNING: Old initialization file found at {legacyinit}. This location is deprecated. Please move it to {Globals.root}/invokeai.init.') @@ -405,6 +409,7 @@ def _create_arg_parser(self): """, fromfile_prefix_chars='@', ) + general_group = parser.add_argument_group('General') model_group = parser.add_argument_group('Model selection') file_group = parser.add_argument_group('Input/output') web_server_group = parser.add_argument_group('Web server') @@ -414,6 +419,11 @@ def _create_arg_parser(self): deprecated_group.add_argument('--laion400m') deprecated_group.add_argument('--weights') # deprecated + general_group.add_argument( + '--version','-V', + action='store_true', + help='Print InvokeAI version number' + ) model_group.add_argument( '--root_dir', default=None, @@ -1055,8 +1065,8 @@ def metadata_dumps(opt, 'model' : 'stable diffusion', 'model_id' : opt.model, 'model_hash' : model_hash, - 'app_id' : APP_ID, - 'app_version' : APP_VERSION, + 'app_id' : ldm.invoke.__app_id__, + 'app_version' : ldm.invoke.__version__, } # # add some RFC266 fields that are generated internally, and not as From 4a00f338a52e5f0f3a5e0003f63c58c5f9206819 Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Fri, 16 Dec 2022 19:30:53 +0000 Subject: [PATCH 2/2] export APP_ID and APP_VERSION Needed to support the web backend. --- ldm/invoke/args.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ldm/invoke/args.py b/ldm/invoke/args.py index db547a56cc7..5a1d71c0799 100644 --- a/ldm/invoke/args.py +++ b/ldm/invoke/args.py @@ -98,6 +98,10 @@ from ldm.invoke.globals import Globals from ldm.invoke.prompt_parser import split_weighted_subprompts +APP_ID = ldm.invoke.__app_id__ +APP_NAME = ldm.invoke.__app_name__ +APP_VERSION = ldm.invoke.__version__ + SAMPLER_CHOICES = [ 'ddim', 'k_dpm_2_a',