Skip to content

Commit

Permalink
[QNN EP] Update QNN SDK to version 2.14.1 (microsoft#17467)
Browse files Browse the repository at this point in the history
### Description
Updates the version of QNN SDK used by CI Pipelines. Enables some tests
fixed by 2.14.1, but still need to look into Resize in a separate PR.

### Motivation and Context
Test latest version of QNN SDK.
  • Loading branch information
adrianlizarraga authored Sep 12, 2023
1 parent 8ad9ab1 commit f20e475
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 158 deletions.
1 change: 1 addition & 0 deletions onnxruntime/test/onnx/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,7 @@ select from 'TF8', 'TF16', 'UINT8', 'FLOAT', 'ITENSOR'. \n)");
broken_tests.insert({"sce_sum_log_prob", "result differs"});
broken_tests.insert({"sce_sum_log_prob_expanded", "result differs"});
broken_tests.insert({"gridsample_reflection_padding", "result differs"});
broken_tests.insert({"spacetodepth", "result differs"});
}
#if defined(_WIN32) && !defined(_WIN64)
broken_tests.insert({"vgg19", "failed: bad allocation"});
Expand Down
10 changes: 8 additions & 2 deletions onnxruntime/test/providers/cpu/tensor/space_depth_ops_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ TEST(TensorOpTest, SpaceToDepthTest_1) {
1.1f, 1.3f,
3.1f, 3.3f};
test.AddOutput<float>("output", {N, C * blocksize * blocksize, H / blocksize, W / blocksize}, result);
test.Run();

// TODO: Test is flaky on QNN EP (CPU backend). Reneable when the QnnCPUBackendTests.DISABLED_SpaceToDepth_Flaky test
// is fixed.
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kQnnExecutionProvider});
}

TEST(TensorOpTest, SpaceToDepthTest_1_double) {
Expand Down Expand Up @@ -99,7 +102,10 @@ TEST(TensorOpTest, SpaceToDepthTest_2) {
98., 101., 66., 69., 84., 87., 102., 105., 67., 70., 85.,
88., 103., 106., 68., 71., 86., 89., 104., 107.};
test.AddOutput<float>("output", {2, 27, 1, 2}, result);
test.Run();

// TODO: Test is flaky on QNN EP (CPU backend). Reneable when the QnnCPUBackendTests.DISABLED_SpaceToDepth_Flaky2
// test is fixed.
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kQnnExecutionProvider});
}

TEST(TensorOpTest, DepthToSpaceTest_1) {
Expand Down
128 changes: 64 additions & 64 deletions onnxruntime/test/providers/qnn/conv_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,6 @@
namespace onnxruntime {
namespace test {

// The bug is from a QDQ model, and Conv node gets processed before it's producer Mul node
// A Transpose node gets inserted between Mul and the dynamic weight tensor shape on Conv
// to make Conv weight with shape HWNC
// However it changes Mul output shape to HWNC and cause issue
// It has to be QDQ model, because the DQ node with initializer on Conv gets processed first
// and DQ node requires its node unit to be processed
// So, Conv gets processed before Mul node
TEST_F(QnnHTPBackendTests, Test_QDQConvWithDynamicWeightsFromMul) {
ProviderOptions provider_options;

#if defined(_WIN32)
provider_options["backend_path"] = "QnnHtp.dll";
#else
provider_options["backend_path"] = "libQnnHtp.so";
#endif

auto BuildConvMulGraph = [](ModelTestBuilder& builder) {
// DQ node for Conv input
auto* dq_i_output = builder.MakeIntermediate();
auto* conv_dq_input = builder.MakeInitializer<uint8_t>({1, 32, 16, 113}, static_cast<uint8_t>(0), static_cast<uint8_t>(127));

// DQ node for Conv bias
auto* dq_bias_output = builder.MakeIntermediate();
auto* bias = builder.MakeInitializer<int32_t>({16}, static_cast<int32_t>(0), static_cast<int32_t>(127));

// Mul node
// DQ nodes for Mul
auto* mul_dq1_output = builder.MakeIntermediate();
auto* mul_input1 = builder.MakeInput<uint8_t>({16, 32, 1, 1}, static_cast<uint8_t>(0), static_cast<uint8_t>(127));

auto* mul_dq2_output = builder.MakeIntermediate();
auto* mul_input2 = builder.MakeInitializer<uint8_t>({16, 1, 1, 1}, static_cast<uint8_t>(0), static_cast<uint8_t>(127));
builder.AddDequantizeLinearNode<uint8_t>(mul_input1, .03f, 0, mul_dq1_output);
builder.AddDequantizeLinearNode<uint8_t>(mul_input2, .03f, 0, mul_dq2_output);

auto* mul_output = builder.MakeIntermediate();
builder.AddNode("Mul", {mul_dq1_output, mul_dq2_output}, {mul_output});

auto* mul_dq_output = AddQDQNodePair<uint8_t>(builder, mul_output, .03f, 0);

builder.AddDequantizeLinearNode<uint8_t>(conv_dq_input, .04f, 0, dq_i_output);
builder.AddDequantizeLinearNode<int32_t>(bias, .0012f, 0, dq_bias_output);
// Conv node
auto* conv_output = builder.MakeIntermediate();

Node& conv_node = builder.AddNode("Conv", {dq_i_output, mul_dq_output, dq_bias_output}, {conv_output});
conv_node.AddAttribute("auto_pad", "NOTSET");
conv_node.AddAttribute("pads", std::vector<int64_t>{0, 0, 0, 0});
conv_node.AddAttribute("strides", std::vector<int64_t>{1, 1});
conv_node.AddAttribute("dilations", std::vector<int64_t>{1, 1});

auto* q_output = builder.MakeIntermediate();
builder.AddQuantizeLinearNode<uint8_t>(conv_output, .039f, 0, q_output);

auto* dq_output = builder.MakeOutput();
builder.AddDequantizeLinearNode<uint8_t>(q_output, .039f, 0, dq_output);
};

RunQnnModelTest(BuildConvMulGraph,
provider_options,
13,
ExpectedEPNodeAssignment::All);
}

// Creates a graph with a single float32 Conv operator. Used for testing CPU backend.
static GetTestModelFn BuildF32ConvTestCase(const std::string& conv_op_type, const TestInputDef<float>& input_def,
const TestInputDef<float>& weights_def,
Expand Down Expand Up @@ -395,6 +331,70 @@ TEST_F(QnnCPUBackendTests, ConvTranspose1Df32_DynamicWeights_DefaultBias) {

#if defined(__aarch64__) || defined(_M_ARM64) || defined(__linux__)

// The bug is from a QDQ model, and Conv node gets processed before it's producer Mul node
// A Transpose node gets inserted between Mul and the dynamic weight tensor shape on Conv
// to make Conv weight with shape HWNC
// However it changes Mul output shape to HWNC and cause issue
// It has to be QDQ model, because the DQ node with initializer on Conv gets processed first
// and DQ node requires its node unit to be processed
// So, Conv gets processed before Mul node
TEST_F(QnnHTPBackendTests, Test_QDQConvWithDynamicWeightsFromMul) {
ProviderOptions provider_options;

#if defined(_WIN32)
provider_options["backend_path"] = "QnnHtp.dll";
#else
provider_options["backend_path"] = "libQnnHtp.so";
#endif

auto BuildConvMulGraph = [](ModelTestBuilder& builder) {
// DQ node for Conv input
auto* dq_i_output = builder.MakeIntermediate();
auto* conv_dq_input = builder.MakeInitializer<uint8_t>({1, 32, 16, 113}, static_cast<uint8_t>(0), static_cast<uint8_t>(127));

// DQ node for Conv bias
auto* dq_bias_output = builder.MakeIntermediate();
auto* bias = builder.MakeInitializer<int32_t>({16}, static_cast<int32_t>(0), static_cast<int32_t>(127));

// Mul node
// DQ nodes for Mul
auto* mul_dq1_output = builder.MakeIntermediate();
auto* mul_input1 = builder.MakeInput<uint8_t>({16, 32, 1, 1}, static_cast<uint8_t>(0), static_cast<uint8_t>(127));

auto* mul_dq2_output = builder.MakeIntermediate();
auto* mul_input2 = builder.MakeInitializer<uint8_t>({16, 1, 1, 1}, static_cast<uint8_t>(0), static_cast<uint8_t>(127));
builder.AddDequantizeLinearNode<uint8_t>(mul_input1, .03f, 0, mul_dq1_output);
builder.AddDequantizeLinearNode<uint8_t>(mul_input2, .03f, 0, mul_dq2_output);

auto* mul_output = builder.MakeIntermediate();
builder.AddNode("Mul", {mul_dq1_output, mul_dq2_output}, {mul_output});

auto* mul_dq_output = AddQDQNodePair<uint8_t>(builder, mul_output, .03f, 0);

builder.AddDequantizeLinearNode<uint8_t>(conv_dq_input, .04f, 0, dq_i_output);
builder.AddDequantizeLinearNode<int32_t>(bias, .0012f, 0, dq_bias_output);
// Conv node
auto* conv_output = builder.MakeIntermediate();

Node& conv_node = builder.AddNode("Conv", {dq_i_output, mul_dq_output, dq_bias_output}, {conv_output});
conv_node.AddAttribute("auto_pad", "NOTSET");
conv_node.AddAttribute("pads", std::vector<int64_t>{0, 0, 0, 0});
conv_node.AddAttribute("strides", std::vector<int64_t>{1, 1});
conv_node.AddAttribute("dilations", std::vector<int64_t>{1, 1});

auto* q_output = builder.MakeIntermediate();
builder.AddQuantizeLinearNode<uint8_t>(conv_output, .039f, 0, q_output);

auto* dq_output = builder.MakeOutput();
builder.AddDequantizeLinearNode<uint8_t>(q_output, .039f, 0, dq_output);
};

RunQnnModelTest(BuildConvMulGraph,
provider_options,
13,
ExpectedEPNodeAssignment::All);
}

// Check that QNN compiles DQ -> Conv -> Q as a single unit.
// Tests bias as a dynamic input.
TEST_F(QnnHTPBackendTests, ConvU8S32_bias_dynamic_input) {
Expand Down
Loading

0 comments on commit f20e475

Please sign in to comment.