mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
Add --use-openvino
This commit is contained in:
@@ -41,6 +41,7 @@ group.add_argument("--profile", action='store_true', help="Run profiler, default
|
||||
group.add_argument("--disable-queue", action='store_true', help="Disable queues, default: %(default)s")
|
||||
group.add_argument('--debug', default = False, action='store_true', help = "Run installer with debug logging, default: %(default)s")
|
||||
group.add_argument('--use-directml', default = False, action='store_true', help = "Use DirectML if no compatible GPU is detected, default: %(default)s")
|
||||
group.add_argument("--use-openvino", default = False, action='store_true', help="Use Intel OpenVINO backend, default: %(default)s")
|
||||
group.add_argument("--use-ipex", default = False, action='store_true', help="Force use Intel OneAPI XPU backend, default: %(default)s")
|
||||
group.add_argument("--use-cuda", default=False, action='store_true', help="Force use nVidia CUDA backend, default: %(default)s")
|
||||
group.add_argument("--use-rocm", default=False, action='store_true', help="Force use AMD ROCm backend, default: %(default)s")
|
||||
|
||||
@@ -8,7 +8,6 @@ from torch._dynamo.backends.registry import register_backend
|
||||
from torch.fx.experimental.proxy_tensor import make_fx
|
||||
from torch._inductor.compile_fx import compile_fx
|
||||
from hashlib import sha256
|
||||
import modules.shared
|
||||
|
||||
class ModelState:
|
||||
def __init__(self):
|
||||
@@ -113,3 +112,15 @@ def get_cached_file_name(*args, model_hash_str, device, cache_root):
|
||||
file_name = None
|
||||
model_hash_str = None
|
||||
return file_name
|
||||
|
||||
def openvino_override_opts():
|
||||
from modules import shared
|
||||
if not shared.opts.cuda_compile:
|
||||
shared.log.warn("OpenVINO: Enabling Torch Compile")
|
||||
shared.opts.cuda_compile = True
|
||||
if shared.opts.cuda_compile_backend != "openvino_fx":
|
||||
shared.log.warn("OpenVINO: Setting Torch Compiler backend to OpenVINO FX")
|
||||
shared.opts.cuda_compile_backend = "openvino_fx"
|
||||
if shared.opts.sd_backend != "diffusers":
|
||||
shared.log.warn("OpenVINO: Setting backend to Diffusers")
|
||||
shared.opts.sd_backend = "diffusers"
|
||||
|
||||
+12
-9
@@ -184,8 +184,11 @@ class State:
|
||||
|
||||
state = State()
|
||||
state.server_start = time.time()
|
||||
|
||||
backend = Backend.DIFFUSERS if (cmd_opts.backend is not None) and (cmd_opts.backend.lower() == 'diffusers') else Backend.ORIGINAL # initial since we don't have opts loaded yet
|
||||
if cmd_opts.use_openvino:
|
||||
backend = Backend.DIFFUSERS
|
||||
cmd_opts.backend = 'diffusers'
|
||||
else:
|
||||
backend = Backend.DIFFUSERS if (cmd_opts.backend is not None) and (cmd_opts.backend.lower() == 'diffusers') else Backend.ORIGINAL # initial since we don't have opts loaded yet
|
||||
|
||||
|
||||
class OptionInfo:
|
||||
@@ -342,7 +345,7 @@ else: # cuda
|
||||
cross_attention_optimization_default ="Scaled-Dot-Product"
|
||||
|
||||
options_templates.update(options_section(('sd', "Stable Diffusion"), {
|
||||
"sd_backend": OptionInfo("original", "Stable Diffusion backend", gr.Radio, lambda: {"choices": ["original", "diffusers"] }),
|
||||
"sd_backend": OptionInfo("diffusers" if cmd_opts.use_openvino else "original", "Stable Diffusion backend", gr.Radio, lambda: {"choices": ["original", "diffusers"] }),
|
||||
"sd_checkpoint_autoload": OptionInfo(True, "Stable Diffusion checkpoint autoload on server start"),
|
||||
"sd_model_checkpoint": OptionInfo(default_checkpoint, "Stable Diffusion checkpoint", gr.Dropdown, lambda: {"choices": list_checkpoint_tiles()}, refresh=refresh_checkpoints),
|
||||
"sd_model_refiner": OptionInfo('None', "Stable Diffusion refiner", gr.Dropdown, lambda: {"choices": ['None'] + list_checkpoint_tiles()}, refresh=refresh_checkpoints),
|
||||
@@ -373,7 +376,7 @@ options_templates.update(options_section(('optimizations', "Optimizations"), {
|
||||
options_templates.update(options_section(('cuda', "Compute Settings"), {
|
||||
"memmon_poll_rate": OptionInfo(2, "VRAM usage polls per second during generation", gr.Slider, {"minimum": 0, "maximum": 40, "step": 1}),
|
||||
"precision": OptionInfo("Autocast", "Precision type", gr.Radio, lambda: {"choices": ["Autocast", "Full"]}),
|
||||
"cuda_dtype": OptionInfo("FP32" if sys.platform == "darwin" else "BF16" if devices.backend == "ipex" else "FP16", "Device precision type", gr.Radio, lambda: {"choices": ["FP32", "FP16", "BF16"]}),
|
||||
"cuda_dtype": OptionInfo("FP32" if sys.platform == "darwin" or cmd_opts.use_openvino else "BF16" if devices.backend == "ipex" else "FP16", "Device precision type", gr.Radio, lambda: {"choices": ["FP32", "FP16", "BF16"]}),
|
||||
"no_half": OptionInfo(False, "Use full precision for model (--no-half)", None, None, None),
|
||||
"no_half_vae": OptionInfo(False, "Use full precision for VAE (--no-half-vae)"),
|
||||
"upcast_sampling": OptionInfo(True if sys.platform == "darwin" else False, "Enable upcast sampling"),
|
||||
@@ -385,8 +388,8 @@ options_templates.update(options_section(('cuda', "Compute Settings"), {
|
||||
"cudnn_benchmark": OptionInfo(False, "Enable full-depth cuDNN benchmark feature"),
|
||||
# "cuda_allow_tf32": OptionInfo(True, "Allow TF32 math ops"),
|
||||
# "cuda_allow_tf16_reduced": OptionInfo(True, "Allow TF16 reduced precision math ops"),
|
||||
"cuda_compile": OptionInfo(False, "Enable model compile (experimental)"),
|
||||
"cuda_compile_backend": OptionInfo("none", "Model compile backend (experimental)", gr.Radio, lambda: {"choices": ['none', 'inductor', 'cudagraphs', 'aot_ts_nvfuser', 'hidet', 'ipex', 'openvino_fx']}),
|
||||
"cuda_compile": OptionInfo(True if cmd_opts.use_openvino else False, "Enable model compile (experimental)"),
|
||||
"cuda_compile_backend": OptionInfo("openvino_fx" if cmd_opts.use_openvino else "none", "Model compile backend (experimental)", gr.Radio, lambda: {"choices": ['none', 'inductor', 'cudagraphs', 'aot_ts_nvfuser', 'hidet', 'ipex', 'openvino_fx']}),
|
||||
"cuda_compile_mode": OptionInfo("default", "Model compile mode (experimental)", gr.Radio, lambda: {"choices": ['default', 'reduce-overhead', 'max-autotune']}),
|
||||
"cuda_compile_fullgraph": OptionInfo(False, "Model compile fullgraph"),
|
||||
"cuda_compile_verbose": OptionInfo(False, "Model compile verbose mode"),
|
||||
@@ -801,9 +804,9 @@ config_filename = cmd_opts.config
|
||||
opts.load(config_filename)
|
||||
cmd_opts = cmd_args.compatibility_args(opts, cmd_opts)
|
||||
if cmd_opts.backend is None:
|
||||
backend = Backend.DIFFUSERS if opts.data.get('sd_backend', 'original') == 'diffusers' else Backend.ORIGINAL
|
||||
backend = Backend.DIFFUSERS if cmd_opts.use_openvino or opts.data.get('sd_backend', 'original') == 'diffusers' else Backend.ORIGINAL
|
||||
else:
|
||||
backend = Backend.DIFFUSERS if cmd_opts.backend.lower() == 'diffusers' else Backend.ORIGINAL
|
||||
backend = Backend.DIFFUSERS if cmd_opts.use_openvino or cmd_opts.backend.lower() == 'diffusers' else Backend.ORIGINAL
|
||||
opts.data['sd_backend'] = 'diffusers' if backend == Backend.DIFFUSERS else 'original'
|
||||
opts.data['uni_pc_lower_order_final'] = opts.schedulers_use_loworder
|
||||
opts.data['uni_pc_order'] = opts.schedulers_solver_order
|
||||
@@ -997,7 +1000,7 @@ class Shared(sys.modules[__name__].__class__): # this class is here to provide s
|
||||
|
||||
@property
|
||||
def backend(self):
|
||||
return Backend.ORIGINAL if opts.data['sd_backend'] == 'original' else Backend.DIFFUSERS
|
||||
return Backend.ORIGINAL if not cmd_opts.use_openvino and opts.data['sd_backend'] == 'original' else Backend.DIFFUSERS
|
||||
|
||||
@property
|
||||
def sd_model_type(self):
|
||||
|
||||
@@ -15,6 +15,7 @@ from modules.ui_components import FormRow, FormColumn, FormGroup, ToolButton, Fo
|
||||
from modules.paths import script_path, data_path
|
||||
from modules.shared import opts, cmd_opts, readfile
|
||||
from modules.dml import directml_override_opts
|
||||
from modules.intel.openvino import openvino_override_opts
|
||||
from modules import prompt_parser
|
||||
import modules.codeformer_model
|
||||
import modules.generation_parameters_copypaste as parameters_copypaste
|
||||
@@ -966,6 +967,8 @@ def create_ui(startup_timer = None):
|
||||
changed.append(key)
|
||||
if cmd_opts.use_directml:
|
||||
directml_override_opts()
|
||||
if cmd_opts.use_openvino:
|
||||
openvino_override_opts()
|
||||
try:
|
||||
opts.save(modules.shared.config_filename)
|
||||
log.info(f'Settings changed: {len(changed)} {changed}')
|
||||
|
||||
Reference in New Issue
Block a user