onnxruntime/onnxruntime/test/python/onnx_backend_test_series.py
Paul Fultz II 7759136610
Add amd migraphx execution provider to onnx runtime (#2929)
* Add amd migraphx execution provider to onnx runtime

* rename MiGraphX to MIGraphX

* remove unnecessary changes in migraphx_execution_provider.cc

* add migraphx EP to tests

* add input requests of the batchnorm operator

* add to support an onnx operator PRelu

* update migrapx dockerfile and removed one unused line

* sync submodules with mater branch

* fixed a small bug

* fix various bugs to run msft real models correctly

* some code cleanup

* fix python file format

* fixed a code style issue

* add default provider for migraphx execution provider

Co-authored-by: Shucai Xiao <Shucai.Xiao@amd.com>
2020-05-27 04:24:59 +08:00

128 lines
5 KiB
Python

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import argparse
import json
import sys
import os
import platform
import unittest
import onnx
import onnx.backend.test
import numpy as np
import onnxruntime.backend as c2
pytest_plugins = 'onnx.backend.test.report',
class OrtBackendTest(onnx.backend.test.BackendTest):
def __init__(self, backend, parent_module=None):
super(OrtBackendTest, self).__init__(backend, parent_module)
@classmethod
def assert_similar_outputs(cls, ref_outputs, outputs, rtol, atol):
np.testing.assert_equal(len(ref_outputs), len(outputs))
for i in range(len(outputs)):
np.testing.assert_equal(ref_outputs[i].dtype, outputs[i].dtype)
if ref_outputs[i].dtype == np.object:
np.testing.assert_array_equal(ref_outputs[i], outputs[i])
else:
np.testing.assert_allclose(ref_outputs[i], outputs[i], rtol=1e-3, atol=1e-5)
def create_backend_test(testname=None):
backend_test = OrtBackendTest(c2, __name__)
# Type not supported
backend_test.exclude(r'(FLOAT16)')
if testname:
backend_test.include(testname + '.*')
else:
# read filters data
with open(
os.path.join(os.path.dirname(os.path.realpath(__file__)), 'testdata',
'onnx_backend_test_series_filters.jsonc')) as f:
filters_lines = f.readlines()
filters_lines = [x.split('//')[0] for x in filters_lines]
filters = json.loads('\n'.join(filters_lines))
current_failing_tests = filters['current_failing_tests']
if platform.architecture()[0] == '32bit':
current_failing_tests += filters['current_failing_tests_x86']
if c2.supports_device('NGRAPH'):
current_failing_tests += filters['current_failing_tests_NGRAPH']
if c2.supports_device('DNNL'):
current_failing_tests += filters['current_failing_tests_DNNL']
if c2.supports_device('NNAPI'):
current_failing_tests += filters['current_failing_tests_NNAPI']
if c2.supports_device('OPENVINO_GPU_FP32') or c2.supports_device('OPENVINO_GPU_FP16'):
current_failing_tests += filters['current_failing_tests_OPENVINO_GPU']
if c2.supports_device('OPENVINO_GPU_FP32'):
current_failing_tests += filters['current_failing_tests_OPENVINO_GPU_FP32']
if c2.supports_device('OPENVINO_CPU_FP32'):
current_failing_tests += filters['current_failing_tests_OPENVINO_CPU_FP32']
if c2.supports_device('MIGRAPHX'):
current_failing_tests += [
'^test_constant_pad_cpu', '^test_softmax_axis_1_cpu', '^test_softmax_axis_0_cpu',
'^test_softmax_default_axis_cpu', '^test_round_cpu', '^test_lrn_default_cpu', '^test_lrn_cpu',
'^test_logsoftmax_axis_0_cpu', '^test_logsoftmax_axis_1_cpu', '^test_logsoftmax_default_axis_cpu',
'^test_dynamicquantizelinear_expanded_cpu', '^test_dynamicquantizelinear_max_adjusted_cpu',
'^test_dynamicquantizelinear_max_adjusted_expanded_cpu', '^test_dynamicquantizelinear_min_adjusted_cpu',
'^test_dynamicquantizelinear_min_adjusted_expanded_cpu',
'^test_range_float_type_positive_delta_expanded_cpu',
'^test_range_int32_type_negative_delta_expanded_cpu', '^test_operator_symbolic_override_nested_cpu'
]
filters = current_failing_tests + \
filters['tests_with_pre_opset7_dependencies'] + \
filters['unsupported_usages'] + \
filters['failing_permanently'] + \
filters['test_with_types_disabled_due_to_binary_size_concerns']
backend_test.exclude('(' + '|'.join(filters) + ')')
print('excluded tests:', filters)
# import all test cases at global scope to make
# them visible to python.unittest.
globals().update(backend_test.enable_report().test_cases)
return backend_test
def parse_args():
parser = argparse.ArgumentParser(os.path.basename(__file__),
description='Run the ONNX backend tests using ONNXRuntime.')
# Add an argument to match a single test name, by adding the name to the 'include' filter.
# Using -k with python unittest (https://docs.python.org/3/library/unittest.html#command-line-options)
# doesn't work as it filters on the test method name (Runner._add_model_test) rather than inidividual
# test case names.
parser.add_argument(
'-t',
'--test-name',
dest='testname',
type=str,
help="Only run tests that match this value. Matching is regex based, and '.*' is automatically appended")
# parse just our args. python unittest has its own args and arg parsing, and that runs inside unittest.main()
args, left = parser.parse_known_args()
sys.argv = sys.argv[:1] + left
return args
if __name__ == '__main__':
args = parse_args()
backend_test = create_backend_test(args.testname)
unittest.main()