From d935d30e4cbb1714a70ebee8eeb79607d0ffcb72 Mon Sep 17 00:00:00 2001 From: tsukumi Date: Mon, 23 Sep 2024 21:07:27 +0900 Subject: [PATCH] Add: test code for CoreMLExecutionProvider on a trial basis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently ONNXRuntime's CoreML support is not very good, and on my environment, I get errors like “coreml_execution_provider.cc:192 operator() Input (/sdp/flows.3/GatherND_2_output_0) has a dynamic shape ({-1,-1}) but the runtime shape ({0,10}) has zero elements. This is not supported by the CoreML EP.” and inference fails. I hope this will be fixed in a future version of ONNXRuntime, and leave the test code as it is. --- .gitignore | 2 ++ pyproject.toml | 2 ++ style_bert_vits2/utils/__init__.py | 6 ++++-- tests/test_main.py | 9 +++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9e2934f..f239417 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ dist/ .coverage* .ipynb_checkpoints/ .ruff_cache/ +.DS_Store +._* /*.yml !/default_config.yml diff --git a/pyproject.toml b/pyproject.toml index 7ba547f..3b20d05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -109,6 +109,8 @@ test = "pytest -s tests/test_main.py::test_synthesize_onnx_cpu" test-cuda = "pytest -s tests/test_main.py::test_synthesize_onnx_cuda" # Usage: `hatch run test-onnx:test-directml` test-directml = "pytest -s tests/test_main.py::test_synthesize_onnx_directml" +# Usage: `hatch run test-onnx:test-coreml` +test-coreml = "pytest -s tests/test_main.py::test_synthesize_onnx_coreml" # Usage: `hatch run test-onnx:coverage` test-cov = "coverage run -m pytest -s tests/test_main.py::test_synthesize_onnx_cpu" # Usage: `hatch run test-onnx:cov-report` diff --git a/style_bert_vits2/utils/__init__.py b/style_bert_vits2/utils/__init__.py index d86b476..9d43784 100644 --- a/style_bert_vits2/utils/__init__.py +++ b/style_bert_vits2/utils/__init__.py @@ -5,10 +5,12 @@ def torch_device_to_onnx_providers( device: str, ) -> Sequence[Union[str, tuple[str, dict[str, Any]]]]: if device.startswith("cuda"): - # cudnn_conv_algo_search を DEFAULT にすると推論速度が大幅に向上する - # ref: https://medium.com/neuml/debug-onnx-gpu-performance-c9290fe07459 return [ + # cudnn_conv_algo_search を DEFAULT にすると推論速度が大幅に向上する + # ref: https://medium.com/neuml/debug-onnx-gpu-performance-c9290fe07459 ("CUDAExecutionProvider", {"cudnn_conv_algo_search": "DEFAULT"}), + # CUDA が利用できない場合、可能であれば DirectML を利用する + ("DmlExecutionProvider", {"device_id": 0}), ("CPUExecutionProvider", {}), ] else: diff --git a/tests/test_main.py b/tests/test_main.py index 5126232..d50b502 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -125,3 +125,12 @@ def test_synthesize_onnx_directml(): ("DmlExecutionProvider", {"device_id": 0}), ], ) + + +def test_synthesize_onnx_coreml(): + synthesize( + inference_type="onnx", + onnx_providers=[ + ("CoreMLExecutionProvider", {}), + ], + )