-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Support bool type for Pad CPU #7856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,17 +26,15 @@ static void RunOnnxOpsetTypedTest( | |
| if (opset >= 11) { | ||
| test.AddInput<int64_t>("pads", {static_cast<int64_t>(pads.size())}, pads); | ||
| test.AddInput<T>("value", {1}, {value}); | ||
| } | ||
| else { | ||
| } else { | ||
| test.AddAttribute("pads", pads); | ||
| test.AddAttribute("value", static_cast<float>(value)); | ||
| } | ||
| test.AddOutput<T>("output", output_dims, output); | ||
| if (opset >= 11) { | ||
| // TensorRT do not yet support opset-11 and builds break on this test, hence exclude the EP | ||
| test.Run(expect, error_msg, {kTensorrtExecutionProvider}); | ||
| } | ||
| else { | ||
| } else { | ||
| #if defined(OPENVINO_CONFIG_MYRIAD) || defined(OPENVINO_CONFIG_VAD_M) | ||
| test.Run(expect, error_msg, {kOpenVINOExecutionProvider}); | ||
| #else | ||
|
|
@@ -56,16 +54,24 @@ static void RunAllOpsetAllDomainPadTests( | |
| std::string mode = "constant", | ||
| OpTester::ExpectResult expect = OpTester::ExpectResult::kExpectSuccess, | ||
| const std::string& error_msg = "") { | ||
| // ONNX domain opset-11 is the only one to support all data types | ||
| // Test opset-11 and opset-13 kernels of Pad | ||
| RunOnnxOpsetTypedTest<T, 11>(input_dims, | ||
| input, | ||
| pads, | ||
| value, | ||
| output_dims, | ||
| output, | ||
| mode, expect, error_msg); | ||
|
|
||
| RunOnnxOpsetTypedTest<T, 13>(input_dims, | ||
| input, | ||
| pads, | ||
| value, | ||
| output_dims, | ||
| output, | ||
| mode, expect, error_msg); | ||
| } | ||
| template<> | ||
| template <> | ||
| void RunAllOpsetAllDomainPadTests<>( | ||
| const std::vector<int64_t>& input_dims, | ||
| const std::vector<double>& input, | ||
|
|
@@ -76,24 +82,34 @@ void RunAllOpsetAllDomainPadTests<>( | |
| std::string mode, | ||
| OpTester::ExpectResult expect, | ||
| const std::string& error_msg) { | ||
| // ONNX domain supports double type | ||
| // Test opset-10, opset-11 and opset-13 kernels of Pad (for double type) | ||
| RunOnnxOpsetTypedTest<double, 10>(input_dims, | ||
| input, | ||
| pads, | ||
| value, | ||
| output_dims, | ||
| output, | ||
| mode, expect, error_msg); | ||
|
|
||
| RunOnnxOpsetTypedTest<double, 11>(input_dims, | ||
| input, | ||
| pads, | ||
| value, | ||
| output_dims, | ||
| output, | ||
| mode, expect, error_msg); | ||
|
|
||
| RunOnnxOpsetTypedTest<double, 13>(input_dims, | ||
| input, | ||
| pads, | ||
| value, | ||
| output_dims, | ||
| output, | ||
| mode, expect, error_msg); | ||
| } | ||
|
|
||
| // There is only support for float type for MSDomain kernel in ORT | ||
| template<> | ||
| template <> | ||
| void RunAllOpsetAllDomainPadTests<>( | ||
| const std::vector<int64_t>& input_dims, | ||
| const std::vector<float>& input, | ||
|
|
@@ -104,13 +120,15 @@ void RunAllOpsetAllDomainPadTests<>( | |
| std::string mode, | ||
| OpTester::ExpectResult expect, | ||
| const std::string& error_msg) { | ||
| // Test opset-10, opset-11 and opset-13 kernels of Pad (for float type) | ||
| RunOnnxOpsetTypedTest<float, 10>(input_dims, | ||
| input, | ||
| pads, | ||
| value, | ||
| output_dims, | ||
| output, | ||
| mode, expect, error_msg); | ||
|
|
||
| RunOnnxOpsetTypedTest<float, 11>(input_dims, | ||
| input, | ||
| pads, | ||
|
|
@@ -119,6 +137,14 @@ void RunAllOpsetAllDomainPadTests<>( | |
| output, | ||
| mode, expect, error_msg); | ||
|
|
||
| RunOnnxOpsetTypedTest<float, 13>(input_dims, | ||
| input, | ||
| pads, | ||
| value, | ||
| output_dims, | ||
| output, | ||
| mode, expect, error_msg); | ||
|
|
||
| #ifndef DISABLE_CONTRIB_OPS | ||
|
|
||
| // MSFT domain opset-1 (contrib op) | ||
|
|
@@ -129,7 +155,7 @@ void RunAllOpsetAllDomainPadTests<>( | |
| test3.AddInput<float>("value", {1}, {value}); | ||
| test3.AddOutput<float>("output", output_dims, output); | ||
| //TensorRT does not support pads as an input | ||
| test3.Run(expect, error_msg, {kTensorrtExecutionProvider,kOpenVINOExecutionProvider}); | ||
| test3.Run(expect, error_msg, {kTensorrtExecutionProvider, kOpenVINOExecutionProvider}); | ||
|
|
||
| #endif | ||
| } | ||
|
|
@@ -679,19 +705,19 @@ TYPED_TEST(PadOpTest, Pad_Constant_DimWithZeroInput) { | |
| {T(1), T(1), T(1), T(1), T(1), T(1), T(1), T(1)}); | ||
| } | ||
| // Added output shape verification b/w the output shape generated by operator specific ONNX inference and | ||
| // the output shape generated by operator specific ORT implementation. After adding this verification, | ||
| // the output shape generated by operator specific ORT implementation. After adding this verification, | ||
| // this test logs warning as validation fails for 2 data types out of 8 data types i.e. Float and Double. | ||
| // Reason: | ||
| // Pad ORT implementation output shape does not match with Pad ONNX inference function output shape. | ||
| // | ||
| // For Float and Double this test gets executed for 2 different opset version, 10 and 11. Specifically this | ||
| // test is failing for opset version 10. | ||
| // Investigation Analysis: Different ONNX inference class/method gets executed per opset version. Main difference b/w the 2 | ||
| // | ||
| // For Float and Double this test gets executed for 2 different opset version, 10 and 11. Specifically this | ||
| // test is failing for opset version 10. | ||
| // Investigation Analysis: Different ONNX inference class/method gets executed per opset version. Main difference b/w the 2 | ||
| // pad operator ONNX inference class/method is: | ||
| // Older Pad operator ONNX inference: Accepts "pads and values" as attribute. | ||
| // Newer Pad operator ONNX inference: Accetps "pads and values" as input. | ||
| // For newer version, "pads & values" fields have not been added as initializer, thus instead of shape | ||
| // inference, rank inference gets triggered. Whereas, in older version shape inference gets executed | ||
| // For newer version, "pads & values" fields have not been added as initializer, thus instead of shape | ||
| // inference, rank inference gets triggered. Whereas, in older version shape inference gets executed | ||
| // as "pads & values" fields have been added as attribute. | ||
| // In order to remove the warning, shape inference methods needs to be fixed. | ||
|
|
||
|
|
@@ -743,5 +769,15 @@ TYPED_TEST(PadOpTest, Pad_Reflect_DimWithZeroInput) { | |
| "Cannot use 'reflect' mode to pad dimension with a value of 0. Input shape:{0,2,1}"); | ||
| } | ||
|
|
||
| TEST(PadOpTest, BoolType) { | ||
| OpTester test("Pad", 13); | ||
| test.AddAttribute("mode", "constant"); | ||
| test.AddInput<bool>("data", {3, 2}, {true, false, true, false, true, false}); | ||
| test.AddInput<int64_t>("pads", {4}, {0, 2, 0, 0}); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: easier to read if this is 3 rows of 2 values and the expected output is 3 rows of 4 values. |
||
| test.AddInput<bool>("value", {1}, {true}); | ||
| test.AddOutput<bool>("output", {3, 4}, {true, true, true, false, true, true, true, false, true, true, true, false}); | ||
| test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); | ||
| } | ||
|
|
||
| } // namespace test | ||
| } // namespace onnxruntime | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.