documentation tweaks; fixed initialization in a couple more places

This commit is contained in:
Lincoln Stein 2023-05-25 21:10:00 -04:00
parent 2273b3a8c8
commit e56965ad76
3 changed files with 35 additions and 12 deletions

View File

@ -51,18 +51,32 @@ in INVOKEAI_ROOT. You can replace supersede this by providing any
OmegaConf dictionary object initialization time: OmegaConf dictionary object initialization time:
omegaconf = OmegaConf.load('/tmp/init.yaml') omegaconf = OmegaConf.load('/tmp/init.yaml')
conf = InvokeAIAppConfig(conf=omegaconf) conf = InvokeAIAppConfig()
conf.parse_args(conf=omegaconf)
By default, InvokeAIAppConfig will parse the contents of `sys.argv` at InvokeAIAppConfig.parse_args() will parse the contents of `sys.argv`
initialization time. You may pass a list of strings in the optional at initialization time. You may pass a list of strings in the optional
`argv` argument to use instead of the system argv: `argv` argument to use instead of the system argv:
conf = InvokeAIAppConfig(arg=['--xformers_enabled']) conf.parse_args(argv=['--xformers_enabled'])
It is also possible to set a value at initialization time. This value It is also possible to set a value at initialization time. However, if
has highest priority. you call parse_args() it may be overwritten.
conf = InvokeAIAppConfig(xformers_enabled=True) conf = InvokeAIAppConfig(xformers_enabled=True)
conf.parse_args(argv=['--no-xformers'])
conf.xformers_enabled
# False
To avoid this, use `get_config()` to retrieve the application-wide
configuration object. This will retain any properties set at object
creation time:
conf = InvokeAIAppConfig.get_config(xformers_enabled=True)
conf.parse_args(argv=['--no-xformers'])
conf.xformers_enabled
# True
Any setting can be overwritten by setting an environment variable of Any setting can be overwritten by setting an environment variable of
form: "INVOKEAI_<setting>", as in: form: "INVOKEAI_<setting>", as in:
@ -76,16 +90,24 @@ Order of precedence (from highest):
4) config file options 4) config file options
5) pydantic defaults 5) pydantic defaults
Typical usage: Typical usage at the top level file:
from invokeai.app.services.config import InvokeAIAppConfig from invokeai.app.services.config import InvokeAIAppConfig
from invokeai.invocations.generate import TextToImageInvocation
# get global configuration and print its nsfw_checker value # get global configuration and print its nsfw_checker value
conf = InvokeAIAppConfig.get_config() conf = InvokeAIAppConfig.get_config()
conf.parse_args() conf.parse_args()
print(conf.nsfw_checker) print(conf.nsfw_checker)
Typical usage in a backend module:
from invokeai.app.services.config import InvokeAIAppConfig
# get global configuration and print its nsfw_checker value
conf = InvokeAIAppConfig.get_config()
print(conf.nsfw_checker)
Computed properties: Computed properties:
The InvokeAIAppConfig object has a series of properties that The InvokeAIAppConfig object has a series of properties that
@ -138,6 +160,7 @@ two configs are kept in separate sections of the config file:
legacy_conf_dir: configs/stable-diffusion legacy_conf_dir: configs/stable-diffusion
outdir: outputs outdir: outputs
... ...
''' '''
from __future__ import annotations from __future__ import annotations
import argparse import argparse

View File

@ -631,7 +631,7 @@ def edit_opts(program_opts: Namespace, invokeai_opts: Namespace) -> argparse.Nam
def default_startup_options(init_file: Path) -> Namespace: def default_startup_options(init_file: Path) -> Namespace:
opts = InvokeAIAppConfig(argv=[]) opts = InvokeAIAppConfig.get_config()
outdir = Path(opts.outdir) outdir = Path(opts.outdir)
if not outdir.is_absolute(): if not outdir.is_absolute():
opts.outdir = str(config.root / opts.outdir) opts.outdir = str(config.root / opts.outdir)
@ -696,7 +696,7 @@ def write_opts(opts: Namespace, init_file: Path):
""" """
# this will load current settings # this will load current settings
config = InvokeAIAppConfig() config = InvokeAIAppConfig.get_config()
for key,value in opts.__dict__.items(): for key,value in opts.__dict__.items():
if hasattr(config,key): if hasattr(config,key):
setattr(config,key,value) setattr(config,key,value)
@ -728,7 +728,7 @@ def write_default_options(program_opts: Namespace, initfile: Path):
# yaml format. # yaml format.
def migrate_init_file(legacy_format:Path): def migrate_init_file(legacy_format:Path):
old = legacy_parser.parse_args([f'@{str(legacy_format)}']) old = legacy_parser.parse_args([f'@{str(legacy_format)}'])
new = InvokeAIAppConfig(conf={}) new = InvokeAIAppConfig.get_config()
fields = list(get_type_hints(InvokeAIAppConfig).keys()) fields = list(get_type_hints(InvokeAIAppConfig).keys())
for attr in fields: for attr in fields:

View File

@ -88,7 +88,7 @@ def save_progress(
def parse_args(): def parse_args():
config = InvokeAIAppConfig(argv=[]) config = InvokeAIAppConfig.get_config()
parser = PagingArgumentParser( parser = PagingArgumentParser(
description="Textual inversion training" description="Textual inversion training"
) )