Skip to content

Commit

Permalink
add tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu authored and Ubuntu committed Oct 7, 2024
1 parent d2c7c2f commit 4dcb746
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
4 changes: 0 additions & 4 deletions onnxruntime/test/providers/checkers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ struct DefaultTolerance<MLFloat16> {
if (provider_type == kDmlExecutionProvider) {
return 0.005f;
}
if (provider_type == kXnnpackExecutionProvider) {
// To allow tests like ConvTranspose_2D_Bias_1 to pass
return 0.05f;
}
return absolute;
}
};
Expand Down
1 change: 1 addition & 0 deletions onnxruntime/test/providers/cpu/nn/conv_fp16_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

#include "core/mlas/inc/mlas.h"
#include "core/providers/xnnpack/xnnpack_init.h"

#if defined(MLAS_F16VEC_INTRINSICS_SUPPORTED) || defined(COREML_ENABLE_MLPROGRAM) || defined(XNNPACK_FP16_SUPPORTED)

Expand Down
25 changes: 23 additions & 2 deletions onnxruntime/test/providers/cpu/nn/conv_transpose_op_test.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include "core/providers/xnnpack/xnnpack_init.h"
#include "gtest/gtest.h"
#include "test/providers/provider_test_utils.h"
#include "default_providers.h"
Expand Down Expand Up @@ -28,6 +29,8 @@ void TestConvTransposeOpInitializer(const ConvTransposeOpAttributes& attributes,
const vector<vector<int64_t>>& input_shapes,
const std::vector<T>& expected_output,
const vector<int64_t>& expected_output_shape,
float rel_error = 0.0,
float abs_error = 0.0,
bool is_weight_and_bias_initializer = false,
OpTester::ExpectResult expect_result = OpTester::ExpectResult::kExpectSuccess,
const std::string& err_str = "",
Expand Down Expand Up @@ -64,7 +67,7 @@ void TestConvTransposeOpInitializer(const ConvTransposeOpAttributes& attributes,
for (size_t i = 0; i < inputs.size(); i++) {
test.AddInput<T>(input_names[i], input_shapes[i], inputs[i], is_initializers[i]);
}
test.AddOutput<T>("Y", expected_output_shape, expected_output);
test.AddOutput<T>("Y", expected_output_shape, expected_output, false, rel_error, abs_error);

test.Run(expect_result, err_str, excluded_provider_types); // Disable TensorRT because weight as input is not supported
}
Expand All @@ -78,12 +81,16 @@ void TestConvTransposeOp(const ConvTransposeOpAttributes& attributes,
OpTester::ExpectResult expect_result = OpTester::ExpectResult::kExpectSuccess,
const std::string& err_str = "",
const std::unordered_set<std::string>& excluded_provider_types =
{kCudaNHWCExecutionProvider, kTensorrtExecutionProvider, kQnnExecutionProvider}) {
{kCudaNHWCExecutionProvider, kTensorrtExecutionProvider, kQnnExecutionProvider},
float rel_error = 0.0,
float abs_error = 0.0) {
std::unordered_set<std::string> extra_exclude_openvino_for_initializer_filter = excluded_provider_types;
extra_exclude_openvino_for_initializer_filter.insert(kOpenVINOExecutionProvider);
TestConvTransposeOpInitializer(attributes, inputs, input_shapes, expected_output, expected_output_shape,
rel_error, abs_error,
true, expect_result, err_str, extra_exclude_openvino_for_initializer_filter);
TestConvTransposeOpInitializer(attributes, inputs, input_shapes, expected_output, expected_output_shape,
rel_error, abs_error,
false, expect_result, err_str, excluded_provider_types);
}

Expand Down Expand Up @@ -245,8 +252,22 @@ TYPED_TEST(ConvTransposeTest, ConvTranspose_2D_Bias_1) {
0.07770107f, -0.09561026f, 0.13388641f, 0.30945939f, 0.14015588f,
0.13079405f, -0.00488365f, -0.06758944f, 0.45621645f, 0.01566098f,
0.00703105f, 0.12956856f, 0.0103332f, 0.04221053f, -0.21318194f};
#ifdef XNNPACK_FP16_SUPPORTED
if constexpr (std::is_same<TypeParam, MLFloat16>::value) {
TestConvTransposeOp(attrs, {GetTypedArray<TypeParam>(X), GetTypedArray<TypeParam>(W), GetTypedArray<TypeParam>(B)},
{X_shape, W_shape, B_shape}, GetTypedArray<TypeParam>(expected_vals), Y_shape,
OpTester::ExpectResult::kExpectSuccess, "", // defalut value
{kCudaNHWCExecutionProvider, kTensorrtExecutionProvider, kQnnExecutionProvider}, //default value
0.5, 0.5);
} else {
TestConvTransposeOp(attrs, {GetTypedArray<TypeParam>(X), GetTypedArray<TypeParam>(W), GetTypedArray<TypeParam>(B)},
{X_shape, W_shape, B_shape}, GetTypedArray<TypeParam>(expected_vals), Y_shape);
}

#else
TestConvTransposeOp(attrs, {GetTypedArray<TypeParam>(X), GetTypedArray<TypeParam>(W), GetTypedArray<TypeParam>(B)},
{X_shape, W_shape, B_shape}, GetTypedArray<TypeParam>(expected_vals), Y_shape);
#endif
}

TEST(ConvTransposeTest, ConvTranspose_2D_Bias_2) {
Expand Down

0 comments on commit 4dcb746

Please sign in to comment.