mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
restart server redesign
This commit is contained in:
+6
-9
@@ -1,14 +1,14 @@
|
||||
import sys
|
||||
import contextlib
|
||||
import torch
|
||||
from modules import shared
|
||||
from modules import cmd_args, shared
|
||||
try:
|
||||
import intel_extension_for_pytorch as ipex
|
||||
import intel_extension_for_pytorch as ipex # pylint: disable=import-error, unused-import
|
||||
except:
|
||||
pass
|
||||
|
||||
if sys.platform == "darwin":
|
||||
from modules import mac_specific
|
||||
from modules import mac_specific # pylint: disable=ungrouped-imports
|
||||
|
||||
|
||||
def has_mps() -> bool:
|
||||
@@ -17,11 +17,10 @@ def has_mps() -> bool:
|
||||
else:
|
||||
return mac_specific.has_mps
|
||||
|
||||
def extract_device_id(args, name):
|
||||
def extract_device_id(args, name): # pylint: disable=redefined-outer-name
|
||||
for x in range(len(args)):
|
||||
if name in args[x]:
|
||||
return args[x + 1]
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@@ -48,7 +47,7 @@ def get_optimal_device_name():
|
||||
if has_mps():
|
||||
return "mps"
|
||||
try:
|
||||
import torch_directml
|
||||
import torch_directml # pylint: disable=import-error
|
||||
if torch_directml.is_available():
|
||||
return get_dml_device_string()
|
||||
else:
|
||||
@@ -110,9 +109,7 @@ def set_cuda_params():
|
||||
dtype_vae = torch.float32
|
||||
unet_needs_upcast = shared.opts.upcast_sampling
|
||||
|
||||
|
||||
from modules.cmd_args import parser
|
||||
args = parser.parse_args()
|
||||
args = cmd_args.parser.parse_args()
|
||||
if args.use_ipex:
|
||||
cpu = torch.device("xpu") #Use XPU instead of CPU. %20 Perf improvement on weak CPUs.
|
||||
print("Using XPU instead of CPU.")
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import platform
|
||||
from packaging import version
|
||||
import torch
|
||||
try:
|
||||
import intel_extension_for_pytorch as ipex
|
||||
import intel_extension_for_pytorch as ipex # pylint: disable=import-error, unused-import
|
||||
except:
|
||||
pass
|
||||
import platform
|
||||
from modules.sd_hijack_utils import CondFunc
|
||||
from packaging import version
|
||||
|
||||
|
||||
# has_mps is only available in nightly pytorch (for now) and macOS 12.3+.
|
||||
@@ -22,7 +22,7 @@ has_mps = check_for_mps()
|
||||
|
||||
|
||||
# MPS workaround for https://github.com/pytorch/pytorch/issues/89784
|
||||
def cumsum_fix(input, cumsum_func, *args, **kwargs):
|
||||
def cumsum_fix(input, cumsum_func, *args, **kwargs): # pylint: disable=redefined-builtin
|
||||
if input.device.type == 'mps':
|
||||
output_dtype = kwargs.get('dtype', input.dtype)
|
||||
if output_dtype == torch.int64:
|
||||
@@ -46,14 +46,14 @@ if has_mps:
|
||||
# MPS workaround for https://github.com/pytorch/pytorch/issues/79383
|
||||
CondFunc('torch.Tensor.to', lambda orig_func, self, *args, **kwargs: orig_func(self.contiguous(), *args, **kwargs),
|
||||
lambda _, self, *args, **kwargs: self.device.type != 'mps' and (args and isinstance(args[0], torch.device) and args[0].type == 'mps' or isinstance(kwargs.get('device'), torch.device) and kwargs['device'].type == 'mps'))
|
||||
# MPS workaround for https://github.com/pytorch/pytorch/issues/80800
|
||||
# MPS workaround for https://github.com/pytorch/pytorch/issues/80800
|
||||
CondFunc('torch.nn.functional.layer_norm', lambda orig_func, *args, **kwargs: orig_func(*([args[0].contiguous()] + list(args[1:])), **kwargs),
|
||||
lambda _, *args, **kwargs: args and isinstance(args[0], torch.Tensor) and args[0].device.type == 'mps')
|
||||
# MPS workaround for https://github.com/pytorch/pytorch/issues/90532
|
||||
CondFunc('torch.Tensor.numpy', lambda orig_func, self, *args, **kwargs: orig_func(self.detach(), *args, **kwargs), lambda _, self, *args, **kwargs: self.requires_grad)
|
||||
elif version.parse(torch.__version__) > version.parse("1.13.1"):
|
||||
cumsum_needs_int_fix = not torch.Tensor([1,2]).to(torch.device("mps")).equal(torch.ShortTensor([1,1]).to(torch.device("mps")).cumsum(0))
|
||||
cumsum_fix_func = lambda orig_func, input, *args, **kwargs: cumsum_fix(input, orig_func, *args, **kwargs)
|
||||
cumsum_fix_func = lambda orig_func, input, *args, **kwargs: cumsum_fix(input, orig_func, *args, **kwargs) # pylint: disable=unnecessary-lambda-assignment
|
||||
CondFunc('torch.cumsum', cumsum_fix_func, None)
|
||||
CondFunc('torch.Tensor.cumsum', cumsum_fix_func, None)
|
||||
CondFunc('torch.narrow', lambda orig_func, *args, **kwargs: orig_func(*args, **kwargs).clone(), None)
|
||||
|
||||
+1
-2
@@ -4,7 +4,6 @@ import sys
|
||||
from collections import namedtuple
|
||||
import gradio as gr
|
||||
from modules import paths, script_callbacks, extensions, script_loading, scripts_postprocessing, errors
|
||||
from installer import log
|
||||
|
||||
AlwaysVisible = object()
|
||||
|
||||
@@ -219,7 +218,7 @@ def load_scripts():
|
||||
for _key, script_class in module.__dict__.items():
|
||||
if type(script_class) != type:
|
||||
continue
|
||||
log.debug(f'Registering script: {scriptfile.path}')
|
||||
# log.debug(f'Registering script: {scriptfile.path}')
|
||||
if issubclass(script_class, Script):
|
||||
scripts_data.append(ScriptClassData(script_class, scriptfile.path, scriptfile.basedir, module))
|
||||
elif issubclass(script_class, scripts_postprocessing.ScriptPostprocessing):
|
||||
|
||||
+5
-4
@@ -697,19 +697,20 @@ mem_mon = modules.memmon.MemUsageMonitor("MemMon", device, opts)
|
||||
mem_mon.start()
|
||||
|
||||
|
||||
def restart_server():
|
||||
def restart_server(restart=True):
|
||||
if demo is None:
|
||||
return
|
||||
log.info('Server shutdown requested')
|
||||
try:
|
||||
import logging
|
||||
log.setLevel(logging.DEBUG if cmd_opts.debug else logging.CRITICAL)
|
||||
demo.server.wants_restart = restart
|
||||
demo.server.should_exit = True
|
||||
demo.server.force_exit = True
|
||||
demo.close(verbose=False)
|
||||
demo.server.close()
|
||||
except:
|
||||
pass
|
||||
log.info('Server shutdown')
|
||||
if restart:
|
||||
log.info('Server will restart')
|
||||
|
||||
|
||||
def listfiles(dirname):
|
||||
|
||||
+6
-11
@@ -1229,38 +1229,32 @@ def create_ui():
|
||||
|
||||
def run_settings(*args):
|
||||
changed = []
|
||||
|
||||
for key, value, comp in zip(opts.data_labels.keys(), args, components):
|
||||
assert comp == dummy_component or opts.same_type(value, opts.data_labels[key].default), f"Bad value for setting {key}: {value}; expecting {type(opts.data_labels[key].default).__name__}"
|
||||
|
||||
for key, value, comp in zip(opts.data_labels.keys(), args, components):
|
||||
if comp == dummy_component:
|
||||
continue
|
||||
|
||||
if opts.set(key, value):
|
||||
changed.append(key)
|
||||
|
||||
try:
|
||||
opts.save(shared.config_filename)
|
||||
except RuntimeError:
|
||||
return opts.dumpjson(), f'{len(changed)} settings changed without save: {", ".join(changed)}.'
|
||||
return opts.dumpjson(), f'{len(changed)} settings changed{": " if len(changed) > 0 else ""}{", ".join(changed)}.'
|
||||
return opts.dumpjson(), f'{len(changed)} Settings changed without save: {", ".join(changed)}'
|
||||
return opts.dumpjson(), f'{len(changed)} Settings changed{": " if len(changed) > 0 else ""}{", ".join(changed)}'
|
||||
|
||||
def run_settings_single(value, key):
|
||||
if not opts.same_type(value, opts.data_labels[key].default):
|
||||
return gr.update(visible=True), opts.dumpjson()
|
||||
|
||||
if not opts.set(key, value):
|
||||
return gr.update(value=getattr(opts, key)), opts.dumpjson()
|
||||
|
||||
opts.save(shared.config_filename)
|
||||
|
||||
return get_value_for_setting(key), opts.dumpjson()
|
||||
|
||||
with gr.Blocks(analytics_enabled=False) as settings_interface:
|
||||
with gr.Row():
|
||||
settings_submit = gr.Button(value="Apply settings", variant='primary', elem_id="settings_submit")
|
||||
restart_submit = gr.Button(value="Restart UI", variant='primary', elem_id="restart_submit")
|
||||
restart_submit = gr.Button(value="Restart server", variant='primary', elem_id="restart_submit")
|
||||
shutdown_submit = gr.Button(value="Shutdown server", variant='primary', elem_id="shutdown_submit")
|
||||
preview_theme = gr.Button(value="Preview theme", variant='primary', elem_id="settings_preview_theme")
|
||||
unload_sd_model = gr.Button(value='Unload checkpoint', variant='primary', elem_id="sett_unload_sd_model")
|
||||
reload_sd_model = gr.Button(value='Reload checkpoint', variant='primary', elem_id="sett_reload_sd_model")
|
||||
@@ -1392,7 +1386,8 @@ def create_ui():
|
||||
inputs=components,
|
||||
outputs=[text_settings, result],
|
||||
)
|
||||
restart_submit.click(fn=shared.restart_server, _js="restart_reload")
|
||||
restart_submit.click(fn=lambda x: shared.restart_server(restart=True), _js="restart_reload")
|
||||
shutdown_submit.click(fn=lambda x: shared.restart_server(restart=False), _js="restart_reload")
|
||||
|
||||
for i, k, item in quicksettings_list:
|
||||
component = component_dict[k]
|
||||
|
||||
Reference in New Issue
Block a user