diff --git a/onnxruntime/test/providers/qnn/clip_op_test.cc b/onnxruntime/test/providers/qnn/clip_op_test.cc index 918c477c75a3d..6c4c6c870bd2c 100644 --- a/onnxruntime/test/providers/qnn/clip_op_test.cc +++ b/onnxruntime/test/providers/qnn/clip_op_test.cc @@ -22,22 +22,15 @@ static void RunClipTest(const TestInputDef& input_def, ExpectedEPNodeAssignment expected_ep_assignment, const std::string& backend_name = "cpu", int opset = 13, - bool enable_fp16_precision = true) { + float fp32_abs_err = 1e-5f) { ProviderOptions provider_options; provider_options["backend_type"] = backend_name; - if (backend_name == "htp") { - if (enable_fp16_precision) { - provider_options["enable_htp_fp16_precision"] = "1"; - } else { - provider_options["enable_htp_fp16_precision"] = "0"; - } - } - RunQnnModelTest(BuildOpTestCase("Clip", {input_def}, min_max_defs, {}), provider_options, opset, - expected_ep_assignment); + expected_ep_assignment, + fp32_abs_err); } // @@ -77,17 +70,19 @@ TEST_F(QnnCPUBackendTests, Clip_5D_f32) { // HTP tests: // -// Test Clip with float32 on HTP -// Fails with QNN SDK 2.35.0: -// value pair (-4.54545403, -4.54687548) at index #3 don't match, which is -0.00142145 from -4.54545 -TEST_F(QnnHTPBackendTests, DISABLED_Clip_f32) { +// Test Clip with float32 on HTP. +// Since QAIRT 2.35, default float precision on QNN HTP became FP16. +// Converting FP32 -> FP16 -> FP32 may introduce minor accuracy loss. +// For example, a value of -4.54545403 could become -4.54687548 after the conversion. +// The expected difference is approximately 0.00142145, so the tolerance is adjusted to 5e-3f. +TEST_F(QnnHTPBackendTests, Clip_f32) { RunClipTest(TestInputDef({1, 1, 3, 4}, false, GetFloatDataInRange(-10.0f, 10.0f, 12)), {TestInputDef({}, true, {-5.0f}), TestInputDef({}, true, {5.0f})}, ExpectedEPNodeAssignment::All, "htp", 13, - false); + 5e-3f); } // Test Clip with int32 on HTP @@ -248,8 +243,7 @@ TEST_F(QnnGPUBackendTests, Clip_fp32) { TestInputDef({}, true, {5.0f})}, ExpectedEPNodeAssignment::All, "gpu", - 13, - false); + 13); } // Test Clip with int32 on GPU diff --git a/onnxruntime/test/providers/qnn/transpose_htp_test.cc b/onnxruntime/test/providers/qnn/transpose_htp_test.cc index 53604dc2af2f8..4ddc2edcb5d88 100644 --- a/onnxruntime/test/providers/qnn/transpose_htp_test.cc +++ b/onnxruntime/test/providers/qnn/transpose_htp_test.cc @@ -88,21 +88,15 @@ template static void RunTransposeNonQDQOnHTP(const TestInputDef& input_def, const std::vector& attrs, ExpectedEPNodeAssignment expected_ep_assignment, - bool enable_fp16_precision = true) { + float fp32_abs_err = 1e-5f) { ProviderOptions provider_options; provider_options["backend_type"] = "htp"; - if (enable_fp16_precision) { - provider_options["enable_htp_fp16_precision"] = "1"; - } else { - provider_options["enable_htp_fp16_precision"] = "0"; - } - RunQnnModelTest(BuildTransposeTestCase(input_def, attrs), provider_options, 13, expected_ep_assignment, - 1e-5f); + fp32_abs_err); } // Check that QNN compiles DQ -> Transpose -> Q as a single unit. @@ -120,12 +114,14 @@ TEST_F(QnnHTPBackendTests, TransposeInt32OnHTP) { } // Check that QNN supports Transpose with float32 data input on HTP -// Fails with QNN SDK 2.35.0: -// value pair (0.183528364, 0.183471695) at index #0 don't match, which is -5.66691e-05 from 0.183528 -TEST_F(QnnHTPBackendTests, DISABLED_TransposeFloatOnHTP) { +// Since QAIRT 2.35, default float precision on QNN HTP became FP16. +// Converting FP32 -> FP16 -> FP32 may introduce minor accuracy loss. +// For example, a value of 7.64300251 could become 7.64453173 after the conversion. +// The expected difference is approximately 0.00152922, so the tolerance is adjusted to 5e-3f. +TEST_F(QnnHTPBackendTests, TransposeFloat32OnHTP) { RunTransposeNonQDQOnHTP(TestInputDef({1, 3, 224, 128}, false, 0, 10.0f), {utils::MakeAttribute("perm", std::vector{0, 2, 3, 1})}, - ExpectedEPNodeAssignment::All, false); + ExpectedEPNodeAssignment::All, 5e-3f); } #endif // defined(__aarch64__) || defined(_M_ARM64) || defined(__linux__)