From 3acf6013f618da7c9c72d1fd93ed854f77a66e4d Mon Sep 17 00:00:00 2001 From: Disty0 Date: Thu, 24 Oct 2024 19:28:15 +0300 Subject: [PATCH] OpenVINO add accuracy option --- modules/intel/openvino/__init__.py | 17 +++++++++++++---- modules/shared.py | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/intel/openvino/__init__.py b/modules/intel/openvino/__init__.py index 975a97672..08a5d2d2a 100644 --- a/modules/intel/openvino/__init__.py +++ b/modules/intel/openvino/__init__.py @@ -7,6 +7,7 @@ from openvino.frontend import FrontEndManager from openvino.frontend.pytorch.fx_decoder import TorchFXPythonDecoder from openvino.frontend.pytorch.torchdynamo.partition import Partitioner from openvino.runtime import Core, Type, PartialShape, serialize +from openvino.properties import hint as ov_hints from torch._dynamo.backends.common import fake_tensor_unsupported from torch._dynamo.backends.registry import register_backend @@ -156,7 +157,6 @@ def openvino_compile(gm: GraphModule, *example_inputs, model_hash_str: str = Non core = Core() device = get_device() - cache_root = shared.opts.openvino_cache_path global dont_use_4bit_nncf global dont_use_nncf global dont_use_quant @@ -233,9 +233,14 @@ def openvino_compile(gm: GraphModule, *example_inputs, model_hash_str: str = Non else: om = nncf.compress_weights(om, mode=getattr(nncf.CompressWeightsMode, shared.opts.nncf_compress_weights_mode), group_size=8, ratio=shared.opts.nncf_compress_weights_raito) - + hints = {} + if shared.opts.openvino_accuracy == "performance": + hints[ov_hints.execution_mode] = ov_hints.ExecutionMode.PERFORMANCE + elif shared.opts.openvino_accuracy == "accuracy": + hints[ov_hints.execution_mode] = ov_hints.ExecutionMode.ACCURACY if model_hash_str is not None: - core.set_property({'CACHE_DIR': cache_root + '/blob'}) + hints['CACHE_DIR'] = shared.opts.openvino_cache_path + '/blob' + core.set_property(hints) dont_use_nncf = False dont_use_quant = False dont_use_4bit_nncf = False @@ -286,7 +291,11 @@ def openvino_compile_cached_model(cached_model_path, *example_inputs): else: om = nncf.compress_weights(om, mode=getattr(nncf.CompressWeightsMode, shared.opts.nncf_compress_weights_mode), group_size=8, ratio=shared.opts.nncf_compress_weights_raito) - core.set_property({'CACHE_DIR': shared.opts.openvino_cache_path + '/blob'}) + hints = {'CACHE_DIR': shared.opts.openvino_cache_path + '/blob'} + if shared.opts.openvino_accuracy == "performance": + hints[ov_hints.execution_mode] = ov_hints.ExecutionMode.PERFORMANCE + elif shared.opts.openvino_accuracy == "accuracy": + hints[ov_hints.execution_mode] = ov_hints.ExecutionMode.ACCURACY dont_use_nncf = False dont_use_quant = False dont_use_4bit_nncf = False diff --git a/modules/shared.py b/modules/shared.py index bb1e13b9e..e184e53ed 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -495,6 +495,7 @@ options_templates.update(options_section(('cuda', "Compute Settings"), { "openvino_sep": OptionInfo("

OpenVINO

", "", gr.HTML, {"visible": cmd_opts.use_openvino}), "openvino_devices": OptionInfo([], "OpenVINO devices to use", gr.CheckboxGroup, {"choices": get_openvino_device_list() if cmd_opts.use_openvino else [], "visible": cmd_opts.use_openvino}), # pylint: disable=E0606 + "openvino_accuracy": OptionInfo("performance", "OpenVINO accuracy mode", gr.Radio, {"choices": ['performance', 'accuracy'], "visible": cmd_opts.use_openvino}), "openvino_disable_model_caching": OptionInfo(False, "OpenVINO disable model caching", gr.Checkbox, {"visible": cmd_opts.use_openvino}), "openvino_disable_memory_cleanup": OptionInfo(True, "OpenVINO disable memory cleanup after compile", gr.Checkbox, {"visible": cmd_opts.use_openvino}),