diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-08-28 12:03:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-28 12:03:46 +0000 |
commit | 9e14cac3182b53173f1c356f2f13bd1cb0cedc89 (patch) | |
tree | 12b4e04a8f17c4275c26bc23870cab0535e053e0 /modules/shared_init.py | |
parent | f898833ea38718e87b39ab090b2a2325638559cb (diff) | |
parent | 8632452627e1341bcd447dbec3c1516f319200a0 (diff) | |
download | stable-diffusion-webui-gfx803-9e14cac3182b53173f1c356f2f13bd1cb0cedc89.tar.gz stable-diffusion-webui-gfx803-9e14cac3182b53173f1c356f2f13bd1cb0cedc89.tar.bz2 stable-diffusion-webui-gfx803-9e14cac3182b53173f1c356f2f13bd1cb0cedc89.zip |
Merge branch 'dev' into patch-1
Diffstat (limited to 'modules/shared_init.py')
-rw-r--r-- | modules/shared_init.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/modules/shared_init.py b/modules/shared_init.py new file mode 100644 index 00000000..d3fb687e --- /dev/null +++ b/modules/shared_init.py @@ -0,0 +1,49 @@ +import os
+
+import torch
+
+from modules import shared
+from modules.shared import cmd_opts
+
+
+def initialize():
+ """Initializes fields inside the shared module in a controlled manner.
+
+ Should be called early because some other modules you can import mingt need these fields to be already set.
+ """
+
+ os.makedirs(cmd_opts.hypernetwork_dir, exist_ok=True)
+
+ from modules import options, shared_options
+ shared.options_templates = shared_options.options_templates
+ shared.opts = options.Options(shared_options.options_templates, shared_options.restricted_opts)
+ shared.restricted_opts = shared_options.restricted_opts
+ if os.path.exists(shared.config_filename):
+ shared.opts.load(shared.config_filename)
+
+ from modules import devices
+ devices.device, devices.device_interrogate, devices.device_gfpgan, devices.device_esrgan, devices.device_codeformer = \
+ (devices.cpu if any(y in cmd_opts.use_cpu for y in [x, 'all']) else devices.get_optimal_device() for x in ['sd', 'interrogate', 'gfpgan', 'esrgan', 'codeformer'])
+
+ devices.dtype = torch.float32 if cmd_opts.no_half else torch.float16
+ devices.dtype_vae = torch.float32 if cmd_opts.no_half or cmd_opts.no_half_vae else torch.float16
+
+ shared.device = devices.device
+ shared.weight_load_location = None if cmd_opts.lowram else "cpu"
+
+ from modules import shared_state
+ shared.state = shared_state.State()
+
+ from modules import styles
+ shared.prompt_styles = styles.StyleDatabase(shared.styles_filename)
+
+ from modules import interrogate
+ shared.interrogator = interrogate.InterrogateModels("interrogate")
+
+ from modules import shared_total_tqdm
+ shared.total_tqdm = shared_total_tqdm.TotalTQDM()
+
+ from modules import memmon, devices
+ shared.mem_mon = memmon.MemUsageMonitor("MemMon", devices.device, shared.opts)
+ shared.mem_mon.start()
+
|