Skip to content

Commit 719e1f6

Browse files
author
Anna Mironova
authored
AC: Added processing of device configs for composite devices (openvinotoolkit#1434)
1 parent df2c84c commit 719e1f6

File tree

4 files changed

+81
-12
lines changed

4 files changed

+81
-12
lines changed

tools/accuracy_checker/accuracy_checker/launcher/dlsdk_launcher.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import os
2121
import platform
2222
import re
23+
import warnings
2324
from collections import OrderedDict
2425
import numpy as np
2526
import openvino.inference_engine as ie
@@ -699,10 +700,22 @@ def _prepare_multi_device(self, log=True):
699700
print_info(' {} - {}'.format(device, nreq))
700701

701702
def _set_device_config(self, device_config):
702-
device_specific_configuration = read_yaml(device_config)
703-
if not isinstance(device_specific_configuration, dict):
703+
device_configuration = read_yaml(device_config)
704+
if not isinstance(device_configuration, dict):
704705
raise ConfigError('device configuration should be a dict-like')
705-
self.ie_core.set_config(device_specific_configuration, self.device)
706+
if all(not isinstance(value, dict) for value in device_configuration.values()):
707+
self.ie_core.set_config(device_configuration, self.device)
708+
else:
709+
for key, value in device_configuration.items():
710+
if isinstance(value, dict):
711+
if key in ie.known_plugins:
712+
self.ie_core.set_config(value, key)
713+
else:
714+
warnings.warn('Option {key}: {value} will be skipped because device is '
715+
'unknown'.format(key=key, value=value))
716+
else:
717+
warnings.warn('Option {key}: {value} will be skipped because device to which it should be '
718+
'applied is not specified or option is not a dict-like'.format(key=key, value=value))
706719

707720
def _log_versions(self):
708721
versions = self.ie_core.get_versions(self._device)

tools/accuracy_checker/accuracy_checker/launcher/dlsdk_launcher_readme.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ It is possible to specify one or more devices via `-td, --target devices` comman
99
* `model` - path to xml file with model for your topology or compiled executable network.
1010
* `weights` - path to bin file with weights for your topology (Optional, the argument can be omitted if bin file stored in the same directory with model xml or if you use compiled blob).
1111

12-
**Note:**
12+
**Note:**
1313
You can generate executable blob using [compile_tool](https://docs.openvinotoolkit.org/latest/_inference_engine_tools_compile_tool_README.html).
1414
Before evaluation executable blob, please make sure that selected device support it.
1515

@@ -28,7 +28,7 @@ You can provide:
2828
In case when you want to determine additional parameters for model conversion (data_type, input_shape and so on), you can use `mo_params` for arguments with values and `mo_flags` for positional arguments like `legacy_mxnet_model` .
2929
Full list of supported parameters you can find in Model Optimizer Developer Guide.
3030

31-
Model will be converted before every evaluation.
31+
Model will be converted before every evaluation.
3232
You can provide `converted_model_dir` for saving converted model in specific folder, otherwise, converted models will be saved in path provided via `-C` command line argument or source model directory.
3333

3434
* `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).
@@ -43,14 +43,18 @@ Additionally you can provide device specific parameters:
4343
* `gpu_extensions` (path to extension *.xml file with OpenCL kernel description for gpu).
4444
* `bitstream` for running on FPGA.
4545

46-
For setting device specific flags, you are able to use `-dc` or `--device_config` command line option. Device config should be represented as YML file with dictionary, where keys are plugin configuration keys and values are their values respectively.
46+
Device config contains device specific options which should be set to Inference Engine. For setting device specific flags, you are able to use `-dc` or `--device_config` command line option. Device config should be represented as YML file with dictionary of one of two types:
47+
1. keys are plugin configuration keys and values are their values respectively. In this way configuration will be applied to current running device.
48+
2. keys are supported devices and values are plugin configuration for each device. Plugin configuration represented as dictionary where keys are plugin specific configuration keys and values are their values respectively.
49+
4750
Each supported device has own set of supported configuration parameters which can be found on device page in [Inference Engine development guide](https://docs.openvinotoolkit.org/latest/_docs_IE_DG_supported_plugins_Supported_Devices.html)
4851

4952
**Note:** Since OpenVINO 2020.4 on platforms with native bfloat16 support models will be executed on this precision by default. For disabling this behaviour, you need to use device_config with following configuration:
5053
```yml
51-
ENFORCE_BF16: "NO"
54+
CPU:
55+
ENFORCE_BF16: "NO"
5256
```
53-
Device config example can be found <a href="https://github.com/opencv/open_model_zoo/blob/develop/tools/accuracy_checker/sample/disable_bfloat16_device_config.yml">here</a>()
57+
Device config example can be found <a href="https://github.com/opencv/open_model_zoo/blob/develop/tools/accuracy_checker/sample/disable_bfloat16_device_config.yml">here</a>
5458
5559
Beside that, you can launch model in `async_mode`, enable this option and optionally provide the number of infer requests (`num_requests`), which will be used in evaluation process. By default, if `num_requests` not provided or used value `AUTO`, automatic number request assignment for specific device will be performed
5660
For multi device configuration async mode used always. You can provide number requests for each device as part device specification: `MULTI:device_1(num_req_1),device_2(num_req_2)` or in `num_requests` config section (for this case comma-separated list of integer numbers or one value if number requests for all devices equal can be used).
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
# Device config example
22

33
# Contains device specific options which should be set to Inference Engine.
4-
# Set of supported keys can be found on device related page in Inference Engine Development guide.
5-
# Device config should be provided via -dc or --device_config commandline option.
4+
# For setting device specific flags, you are able to use `-dc` or `--device_config` command line option.
5+
# Device config should be represented as YML file with dictionary of one of two types:
6+
# 1. keys are plugin configuration keys and values are their values respectively.
7+
# In this way configuration will be applied to current running device.
8+
# 2. keys are supported devices and values are plugin configuration for each device.
9+
# Plugin configuration represented as dictionary where keys are plugin specific configuration keys and values
10+
# are their values respectively.
11+
# Each supported device has own set of supported configuration parameters which can be found on
12+
# device page in Inference Engine development guide.
613

714
# This config example shows how to disable bfloat16 optimizations for CPU.
815
# Note: on platforms with native bfloat16 support, ENFORCE_BF16 parameter by default set as "YES",
9-
# for disabling this behavior you need to specify following configuration.
10-
ENFORCE_BF16: "NO"
16+
# for disabling this behavior you need to use device_config with following configuration.
17+
CPU:
18+
ENFORCE_BF16: "NO"

tools/accuracy_checker/tests/test_dlsdk_launcher.py

+44
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,50 @@ def test_raises_with_tf_model_and_tf_meta_both_provided(self):
11071107
with pytest.raises(ConfigError):
11081108
DLSDKLauncher(config)
11091109

1110+
@pytest.mark.usefixtures('mock_file_exists')
1111+
def test_dlsdk_launcher_device_config_config_not_dict_like(self, mocker, models_dir):
1112+
device_config = 'ENFORCE_BF16'
1113+
1114+
mocker.patch(
1115+
'accuracy_checker.launcher.dlsdk_launcher.read_yaml', return_value=device_config
1116+
)
1117+
1118+
with pytest.raises(ConfigError):
1119+
get_dlsdk_test_model(models_dir, {'_device_config': './device_config.yml'})
1120+
1121+
@pytest.mark.usefixtures('mock_file_exists')
1122+
def test_dlsdk_launcher_device_config_device_unknown(self, mocker, models_dir):
1123+
device_config = {'device': {'ENFORCE_BF16': 'NO'}}
1124+
1125+
mocker.patch(
1126+
'accuracy_checker.launcher.dlsdk_launcher.read_yaml', return_value=device_config
1127+
)
1128+
1129+
with pytest.warns(Warning):
1130+
get_dlsdk_test_model(models_dir, {'_device_config': './device_config.yml'})
1131+
1132+
@pytest.mark.usefixtures('mock_file_exists')
1133+
def test_dlsdk_launcher_device_config_one_option_for_device_is_not_dict(self, mocker, models_dir):
1134+
device_config = {'CPU': {'ENFORCE_BF16': 'NO'}, 'GPU': 'ENFORCE_BF16'}
1135+
1136+
mocker.patch(
1137+
'accuracy_checker.launcher.dlsdk_launcher.read_yaml', return_value=device_config
1138+
)
1139+
1140+
with pytest.warns(Warning):
1141+
get_dlsdk_test_model(models_dir, {'_device_config': './device_config.yml'})
1142+
1143+
@pytest.mark.usefixtures('mock_file_exists')
1144+
def test_dlsdk_launcher_device_config_one_option_is_not_binding_to_device(self, mocker, models_dir):
1145+
device_config = {'CPU': {'ENFORCE_BF16': 'NO'}, 'ENFORCE_BF16': 'NO'}
1146+
1147+
mocker.patch(
1148+
'accuracy_checker.launcher.dlsdk_launcher.read_yaml', return_value=device_config
1149+
)
1150+
1151+
with pytest.warns(Warning):
1152+
get_dlsdk_test_model(models_dir, {'_device_config': './device_config.yml'})
1153+
11101154

11111155
@pytest.mark.usefixtures('mock_path_exists', 'mock_inputs', 'mock_inference_engine')
11121156
class TestDLSDKLauncherConfig:

0 commit comments

Comments
 (0)