Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions onnxruntime/test/contrib_ops/quantize_ops_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ TEST(QuantizeLinearContribOpTest, QuantizeLinear_per_tensor_float_int8) {
127, -127,
127, -128,
127, -128});
test.SetOutputAbsErr("y", 1.0f);
// Disable Tensorrt EP due to error: node1_quantize_scale_node: out of bounds channel axis 1. Number of input dimensions is 1.
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider});
}
Expand All @@ -311,6 +312,7 @@ TEST(QuantizeLinearContribOpTest, QuantizeLinear_per_tensor_float_uint16) {
32769, 32765,
65535, 0,
65535, 0});
test.SetOutputAbsErr("y", 1.0f);

// Disable Tensorrt EP due to error: unsupported data type
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider});
Expand Down
72 changes: 67 additions & 5 deletions onnxruntime/test/providers/checkers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,27 @@ template <>
struct TensorCheck<Int4x2> {
void operator()(const Tensor& expected, const Tensor& actual, const ValidateOutputParams& params,
const std::string& /*provider_type*/) const {
ORT_UNUSED_PARAMETER(params);
const bool has_abs_err = params.absolute_error.has_value();
Tensor expected_sorted, actual_sorted;
const Int4x2* cur_expected;
const Int4x2* cur_actual;
const auto size = actual.Shape().Size();
cur_expected = expected.Data<Int4x2>();
cur_actual = actual.Data<Int4x2>();
double threshold = 0.0f;
if (has_abs_err) {
threshold = *(params.absolute_error);
}

for (size_t i = 0; i < static_cast<size_t>(size); ++i) {
size_t r = i >> 1;
size_t c = i & 0x1;
EXPECT_EQ(cur_expected[r].GetElem(c), cur_actual[r].GetElem(c)) << "i:" << i;
// TODO: the relative error is not used for int4 yet.
if (has_abs_err) {
EXPECT_NEAR(cur_expected[r].GetElem(c), cur_actual[r].GetElem(c), threshold) << "i:" << i;
} else {
EXPECT_EQ(cur_expected[r].GetElem(c), cur_actual[r].GetElem(c)) << "i:" << i;
}
}
}
};
Expand All @@ -203,18 +212,28 @@ template <>
struct TensorCheck<UInt4x2> {
void operator()(const Tensor& expected, const Tensor& actual, const ValidateOutputParams& params,
const std::string& /*provider_type*/) const {
ORT_UNUSED_PARAMETER(params);
const bool has_abs_err = params.absolute_error.has_value();
Tensor expected_sorted, actual_sorted;
const UInt4x2* cur_expected;
const UInt4x2* cur_actual;
const auto size = actual.Shape().Size();
cur_expected = expected.Data<UInt4x2>();
cur_actual = actual.Data<UInt4x2>();

double threshold = 0.0f;
if (has_abs_err) {
threshold = *(params.absolute_error);
}

for (size_t i = 0; i < static_cast<size_t>(size); ++i) {
size_t r = i >> 1;
size_t c = i & 0x1;
EXPECT_EQ(cur_expected[r].GetElem(c), cur_actual[r].GetElem(c)) << "i:" << i;
// TODO: the relative error is not used for int4 yet.
if (has_abs_err) {
EXPECT_NEAR(cur_expected[r].GetElem(c), cur_actual[r].GetElem(c), threshold) << "i:" << i;
} else {
EXPECT_EQ(cur_expected[r].GetElem(c), cur_actual[r].GetElem(c)) << "i:" << i;
}
}
}
};
Expand Down Expand Up @@ -252,7 +271,7 @@ struct TensorCheck<uint8_t> {
// For any other EPs, we still expect an exact match for the results
// TODO: Verify if DML can possibly have a ROUNDING_MODE parameter and conform to the other EPs #41968513
if ((provider_type == kNnapiExecutionProvider || provider_type == kDmlExecutionProvider ||
provider_type == kXnnpackExecutionProvider) &&
provider_type == kXnnpackExecutionProvider || provider_type == kOpenVINOExecutionProvider) &&
(has_abs_err || has_rel_err)) {
double threshold = has_abs_err ? *(params.absolute_error)
: 0.0;
Expand Down Expand Up @@ -317,6 +336,49 @@ struct TensorCheck<int8_t> {
}
};

template <>
struct TensorCheck<uint16_t> {
void operator()(const Tensor& expected,
const Tensor& actual,
const ValidateOutputParams& params,
const std::string& ) const {
const bool has_abs_err = params.absolute_error.has_value();
const bool has_rel_err = params.relative_error.has_value();

Tensor expected_sorted, actual_sorted;
const uint16_t* cur_expected;
const uint16_t* cur_actual;
const auto size = actual.Shape().Size();
if (params.sort_output) {
sort_expected_and_actual_buffers<uint16_t>(expected, expected_sorted, actual, actual_sorted);
cur_expected = expected_sorted.Data<uint16_t>();
cur_actual = actual_sorted.Data<uint16_t>();
} else {
cur_expected = expected.Data<uint16_t>();
cur_actual = actual.Data<uint16_t>();
}

if (has_abs_err || has_rel_err) {
double threshold = has_abs_err ? *(params.absolute_error)
: 0.0;

for (int64_t i = 0; i < size; ++i) {
if (has_rel_err) {
EXPECT_NEAR(cur_expected[i], cur_actual[i],
*(params.relative_error) * cur_expected[i]) // expected[i] is unsigned, can't be negative
<< "i:" << i;
} else { // has_abs_err
EXPECT_NEAR(cur_expected[i], cur_actual[i], threshold) << "i:" << i;
}
}
} else {
for (int64_t i = 0; i < size; ++i) {
EXPECT_EQ(cur_expected[i], cur_actual[i]) << "i:" << i;
}
}
}
};

template <>
struct TensorCheck<double> {
void operator()(const Tensor& expected,
Expand Down
3 changes: 2 additions & 1 deletion onnxruntime/test/providers/cpu/controlflow/loop_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,8 @@ TEST(Loop, Opset11WithNoVariadicInputsAndOutputs) {
test.AddOutput<float>("loop_scan_out", {1}, {1.0f});

// Disable TensorRT on unsupported data type BOOL
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider});
// Disable OpenVino for floating nodes
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider, kOpenVINOExecutionProvider});
}

// Test a combination of things:
Expand Down
3 changes: 3 additions & 0 deletions onnxruntime/test/providers/cpu/tensor/cast_op_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,9 @@ TEST(CastOpTest, Int32ToInt4x2OddNumberOfElements) {
}

TEST(CastOpTest, Int32ToInt4x2EmptyTensor) {
if (DefaultOpenVINOExecutionProvider().get() != nullptr) {
GTEST_SKIP() << "The OpenVINO not support 0 size input";
}
// GIVEN
const std::vector<int64_t> empty_shape{0};
const std::vector<int32_t> empty_input = {};
Expand Down
2 changes: 2 additions & 0 deletions onnxruntime/test/providers/cpu/tensor/concat_op_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ TEST(ConcatOpTest, Concat1D_2) {
test.Run(OpTester::ExpectResult::kExpectSuccess, "",
{kTensorrtExecutionProvider, // TensorRT: no support for dynamic shape tensor
kNnapiExecutionProvider, // NNAPI: concat does not support 0 size input
kOpenVINOExecutionProvider, // OpenVINO: does not support 0 size input
kQnnExecutionProvider}); // QNN: not support dynamic shape tensor
}

Expand Down Expand Up @@ -118,6 +119,7 @@ TEST(ConcatOpTest, Concat2D_3) {
test.Run(OpTester::ExpectResult::kExpectSuccess, "",
{kTensorrtExecutionProvider, // TensorRT: no support for dynamic shape tensor
kNnapiExecutionProvider, // NNAPI: concat does not support 0 size input
kOpenVINOExecutionProvider, // OpenVINO: does not support 0 size input
kQnnExecutionProvider}); // QNN: not support dynamic shape tensor
}

Expand Down
7 changes: 7 additions & 0 deletions onnxruntime/test/providers/cpu/tensor/quantize_linear_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ TEST(QuantizeLinearOpTest, Uint16) {
32769, 32765,
65535, 0,
65535, 0});
test.SetOutputAbsErr("y", 1.0f);

// Disable Tensorrt EP due to error: unsupported data type
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider});
Expand Down Expand Up @@ -466,6 +467,7 @@ TEST(QuantizeLinearOpTest, Int16) {
32767, -32768,
32767, -32768,
32767, -32768});
test.SetOutputAbsErr("y", 1.0f);

// Disable Tensorrt EP due to error: unsupported data type
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider});
Expand All @@ -490,6 +492,7 @@ TEST(QuantizeLinearOpTest, Int4) {
test.AddOutput<Int4x2>("y", dims,
{Int4x2(-8, -7), Int4x2(-1, 1), Int4x2(2, 7),
Int4x2(7, unused_val)});
test.SetOutputAbsErr("y", 1.0f);

test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider});
}
Expand Down Expand Up @@ -557,6 +560,7 @@ TEST(QuantizeLinearOpTest, OddLarge_Int4) {
test.AddInput<float>("scale", {}, {scale}, true);
test.AddInput<Int4x2>("zero_point", {}, {Int4x2(zp, unused_val)}, true);
test.AddOutput<Int4x2>("y", dims, output);
test.SetOutputAbsErr("y", 1.0f);

test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider});
}
Expand All @@ -583,6 +587,7 @@ TEST(QuantizeLinearOpTest, OddLarge_UInt4) {
test.AddInput<float>("scale", {}, {scale}, true);
test.AddInput<UInt4x2>("zero_point", {}, {UInt4x2(zp, unused_val)}, true);
test.AddOutput<UInt4x2>("y", dims, output);
test.SetOutputAbsErr("y", 1.0f);

test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider});
}
Expand All @@ -600,6 +605,7 @@ TEST(QuantizeLinearOpTest, Int8_NegativeZeroPoint) {
test.AddInput<float>("y_scale", {}, {.039215686f});
test.AddInput<int8_t>("y_zero_point", {}, {-23});
test.AddOutput<int8_t>("y", dims, {-23, 28, 53, 104, 127, -74, -128, -128});
test.SetOutputAbsErr("y", 1.0f);
// Disable Tensorrt EP due to the error, node1_quantize_scale_node: out of bounds channel axis 1. Number of input dimensions is 1.
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider});
}
Expand All @@ -617,6 +623,7 @@ TEST(QuantizeLinearOpTest, Int8_PositiveZeroPoint) {
test.AddInput<float>("y_scale", {}, {.039215686f});
test.AddInput<int8_t>("y_zero_point", {}, {23});
test.AddOutput<int8_t>("y", dims, {23, 74, 99, 127, 127, -28, -104, -128});
test.SetOutputAbsErr("y", 1.0f);
// Disable Tensorrt EP due to error:node1_quantize_scale_node: out of bounds channel axis 1. Number of input dimensions is 1.
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider});
}
Expand Down
2 changes: 2 additions & 0 deletions onnxruntime/test/providers/cpu/tensor/resize_op_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ TEST(ResizeOpTest, NhwcResizeOpLinearDownSampleTest_4DBilinear_uint8) {
std::vector<uint8_t> Y = {2, 4};

test.AddOutput<uint8_t>("Y", {N, static_cast<int64_t>(H * scales[1]), static_cast<int64_t>(W * scales[2]), C}, Y);
test.SetOutputAbsErr("Y", 1.0f);
// CUDA: result mismatch due to not implementing NHWC support
// ROCm: results mismatch
test.Run(OpTester::ExpectResult::kExpectSuccess, "",
Expand Down Expand Up @@ -647,6 +648,7 @@ TEST(ResizeOpTest, NhwcResizeOpLinearDownSampleTest_4DBilinear_pytorch_half_pixe
std::vector<uint8_t> Y = {1, 7, 12};

test.AddOutput<uint8_t>("Y", {N, sizes[1], sizes[2], C}, Y);
test.SetOutputAbsErr("Y", 1.0f);
// CUDA: result mismatch due to not implementing NHWC support
// ROCm: results mismatch
// DML: results mismatch
Expand Down
4 changes: 4 additions & 0 deletions onnxruntime/test/providers/cpu/tensor/slice_op.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,10 @@ TEST(SliceTest, Slice1D_ReverseAllAxes_1) {
GTEST_SKIP() << "Skipping because of the following error: Expected output shape [{4}] did not match run output shape [{0}] for output";
}

if (DefaultOpenVINOExecutionProvider().get() != nullptr) {
GTEST_SKIP() << "Skipping because of the following error: The input ends do not support int max when step is negative.";
}

RunSliceTest<float>({4},
{1.0f, 2.0f, 3.0f, 4.0f},
{-1},
Expand Down
Loading