From 34e8bea487d1d4c3bd90bedb6aa814e723840730 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Tue, 7 May 2019 10:44:37 -0700 Subject: [PATCH] Uncomment mod tests and make infra run them (#971) Add np.uint32, np.float16 to numpy to MLDataType mappings. Fix up the mapping and get rid of hash defines in the map. Uncomment mod tests. --- .../python/onnxruntime_pybind_mlvalue.cc | 35 ++++++++++++++----- onnxruntime/test/onnx/main.cc | 3 +- .../test/python/onnx_backend_test_series.py | 4 --- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/onnxruntime/python/onnxruntime_pybind_mlvalue.cc b/onnxruntime/python/onnxruntime_pybind_mlvalue.cc index 508c491d37..e424f2667c 100644 --- a/onnxruntime/python/onnxruntime_pybind_mlvalue.cc +++ b/onnxruntime/python/onnxruntime_pybind_mlvalue.cc @@ -24,12 +24,14 @@ int OnnxRuntimeTensorToNumpyType(const DataTypeImpl* tensor_type) { static std::map type_map{ {DataTypeImpl::GetType(), NPY_BOOL}, {DataTypeImpl::GetType(), NPY_FLOAT}, + {DataTypeImpl::GetType(), NPY_FLOAT16}, {DataTypeImpl::GetType(), NPY_DOUBLE}, - {DataTypeImpl::GetType(), NPY_INT}, {DataTypeImpl::GetType(), NPY_INT8}, {DataTypeImpl::GetType(), NPY_UINT8}, {DataTypeImpl::GetType(), NPY_INT16}, {DataTypeImpl::GetType(), NPY_UINT16}, + {DataTypeImpl::GetType(), NPY_INT}, + {DataTypeImpl::GetType(), NPY_UINT}, {DataTypeImpl::GetType(), NPY_LONGLONG}, {DataTypeImpl::GetType(), NPY_ULONGLONG}, {DataTypeImpl::GetType(), NPY_OBJECT}, @@ -47,15 +49,32 @@ const DataTypeImpl* NumpyToOnnxRuntimeTensorType(int numpy_type) { static std::map type_map{ {NPY_BOOL, DataTypeImpl::GetType()}, {NPY_FLOAT, DataTypeImpl::GetType()}, + // Special, not a C type expands to enum value of 16 + {NPY_FLOAT16, DataTypeImpl::GetType()}, {NPY_DOUBLE, DataTypeImpl::GetType()}, - {NPY_INT, DataTypeImpl::GetType()}, - {NPY_INT8, DataTypeImpl::GetType()}, - {NPY_UINT8, DataTypeImpl::GetType()}, - {NPY_INT16, DataTypeImpl::GetType()}, - {NPY_UINT16, DataTypeImpl::GetType()}, + // We don't want to use size specific types such + // as NPY_INT32 bc they are not enums but hash defines + // which may map into other enums and may conflict with other entries here + // also NPY docs define these sizes as platform specific, thus we + // choose to do some rudimentary checks for proper mapping on C++ size + {NPY_BYTE, DataTypeImpl::GetType()}, + {NPY_UBYTE, DataTypeImpl::GetType()}, + {NPY_SHORT, sizeof(short) == sizeof(int16_t) ? DataTypeImpl::GetType() + : DataTypeImpl::GetType()}, + {NPY_USHORT, sizeof(unsigned short) == sizeof(uint16_t) ? DataTypeImpl::GetType() + : DataTypeImpl::GetType()}, + {NPY_INT, + sizeof(int) == sizeof(int32_t) ? DataTypeImpl::GetType() + : DataTypeImpl::GetType()}, + {NPY_UINT, sizeof(int) == sizeof(int32_t) ? DataTypeImpl::GetType() + : DataTypeImpl::GetType()}, + {NPY_LONG, - sizeof(long) == sizeof(int) ? DataTypeImpl::GetType() - : DataTypeImpl::GetType()}, + sizeof(long) == sizeof(int32_t) ? DataTypeImpl::GetType() + : DataTypeImpl::GetType()}, + {NPY_ULONG, + sizeof(unsigned long) == sizeof(uint32_t) ? DataTypeImpl::GetType() + : DataTypeImpl::GetType()}, {NPY_LONGLONG, DataTypeImpl::GetType()}, {NPY_ULONGLONG, DataTypeImpl::GetType()}, {NPY_UNICODE, DataTypeImpl::GetType()}, diff --git a/onnxruntime/test/onnx/main.cc b/onnxruntime/test/onnx/main.cc index f57301b35c..e3d0c6979c 100644 --- a/onnxruntime/test/onnx/main.cc +++ b/onnxruntime/test/onnx/main.cc @@ -354,8 +354,7 @@ int real_main(int argc, char* argv[], Ort::Env& env) { {"tf_mobilenet_v2_1.4_224", "result mismatch"}, {"tf_mobilenet_v1_1.0_224", "result mismatch"}, {"mobilenetv2-1.0", "result mismatch"}, - {"mxnet_arcface", "result mismatch"}, - {"mod_float_mixed_sign_example", "faulty test"} + {"mxnet_arcface", "result mismatch"} }; #ifdef USE_NGRAPH diff --git a/onnxruntime/test/python/onnx_backend_test_series.py b/onnxruntime/test/python/onnx_backend_test_series.py index bc617de200..4514f942de 100644 --- a/onnxruntime/test/python/onnx_backend_test_series.py +++ b/onnxruntime/test/python/onnx_backend_test_series.py @@ -87,13 +87,9 @@ backend_test.exclude(r'(' '|^test_mvn_cpu.*' '|^test_qlinearconv_cpu.*' '|^test_quantizelinear_cpu.*' -'|^test_mod_float_mixed_sign_example.*' '|^test_reversesequence_batch_cpu.*' '|^test_reversesequence_time_cpu.*' '|^test_roialign_cpu.*' -'|^test_mod_mixed_sign_float16_cpu.*' -'|^test_mod_uint32_cpu.*' -'|^test_mod_uint64_cpu.*' ')') # import all test cases at global scope to make