diff --git a/tools/accuracy_checker/accuracy_checker/launcher/pytorch_launcher.py b/tools/accuracy_checker/accuracy_checker/launcher/pytorch_launcher.py index cbb931b6eb9..fb413a323fe 100644 --- a/tools/accuracy_checker/accuracy_checker/launcher/pytorch_launcher.py +++ b/tools/accuracy_checker/accuracy_checker/launcher/pytorch_launcher.py @@ -20,7 +20,7 @@ from collections import OrderedDict import numpy as np -from ..config import PathField, StringField, DictField, NumberField, ListField +from ..config import PathField, StringField, DictField, NumberField, ListField, BoolField from .launcher import Launcher MODULE_REGEX = r'(?:\w+)(?:(?:.\w+)*)' @@ -51,7 +51,9 @@ def parameters(cls): 'batch': NumberField(value_type=int, min_value=1, optional=True, description="Batch size.", default=1), 'output_names': ListField( optional=True, value_type=str, description='output tensor names' - ) + ), + 'use_openvino_backend': BoolField( + optional=True, default=False, description='use torch.compile feature with openvino backend') }) return parameters @@ -66,6 +68,13 @@ def __init__(self, config_entry: dict, *args, **kwargs): import_error.msg)) from import_error self._torch = torch self.validate_config(config_entry) + self.is_openvino_backend = config_entry.get('use_openvino_backend') + if self.is_openvino_backend: + try: + import openvino.torch # pylint: disable=C0415, W0611 + except ImportError as import_error: + raise ValueError("torch.compile is supported from OpenVINO 2023.1\n{}".format( + import_error.msg)) from import_error module_args = config_entry.get("module_args", ()) module_kwargs = config_entry.get("module_kwargs", {}) self.device = self.get_value_from_config('device') @@ -123,6 +132,9 @@ def load_module(self, model_cls, module_args, module_kwargs, checkpoint=None, st module.load_state_dict(state, strict=False) module.to(self.device) module.eval() + if self.is_openvino_backend: + opts = {"device" : f"{self.device}"} + module = self._torch.compile(module, backend="openvino", options=opts) return module def fit_to_input(self, data, layer_name, layout, precision, template=None): diff --git a/tools/accuracy_checker/accuracy_checker/launcher/pytorch_launcher_readme.md b/tools/accuracy_checker/accuracy_checker/launcher/pytorch_launcher_readme.md index 795dc7bc4e3..232398a0066 100644 --- a/tools/accuracy_checker/accuracy_checker/launcher/pytorch_launcher_readme.md +++ b/tools/accuracy_checker/accuracy_checker/launcher/pytorch_launcher_readme.md @@ -12,6 +12,7 @@ For enabling PyTorch launcher you need to add `framework: pytorch` in launchers * `module_kwargs` - dictionary (`key`: `value` where `key` is argument name, `value` is argument value) which represent network module keyword arguments. * `adapter` - approach how raw output will be converted to representation of dataset problem, some adapters can be specific to framework. You can find detailed instruction how to use adapters [here](../adapters/README.md). * `batch` - batch size for running model (Optional, default 1). +* `use_openvino_backend` - use torch.compile feature with `openvino` backend (Optional, default `False`) In turn if you model has several inputs you need to specify them in config, using specific parameter: `inputs`. Each input description should has following info: