From f977be066318111f01d7f2e2373824566a7fe9c0 Mon Sep 17 00:00:00 2001 From: Hector Li Date: Sat, 23 Mar 2024 13:43:20 -0700 Subject: [PATCH] Fix issue that failed to load Conv node with external initializer (#20042) ### Description Fix issue that failed to load Conv node with external initializer. Root cause the model path is not provided while loading the weight and bias tensor for Conv. --- .../qnn/builder/opbuilder/base_op_builder.cc | 4 +++- .../test/providers/qnn/qnn_basic_test.cc | 20 ++++++++++++++++++ .../test/testdata/conv_qdq_external_ini.bin | Bin 0 -> 2000 bytes .../test/testdata/conv_qdq_external_ini.onnx | Bin 0 -> 2204 bytes 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 onnxruntime/test/testdata/conv_qdq_external_ini.bin create mode 100644 onnxruntime/test/testdata/conv_qdq_external_ini.onnx diff --git a/onnxruntime/core/providers/qnn/builder/opbuilder/base_op_builder.cc b/onnxruntime/core/providers/qnn/builder/opbuilder/base_op_builder.cc index 6d8c80bd2aaa1..08c9a8449cc33 100644 --- a/onnxruntime/core/providers/qnn/builder/opbuilder/base_op_builder.cc +++ b/onnxruntime/core/providers/qnn/builder/opbuilder/base_op_builder.cc @@ -244,7 +244,9 @@ Status BaseOpBuilder::TransposeInitializer(const QnnModelWrapper& qnn_model_wrap TensorShape new_tensor_shape(new_tensor_shape_dims); Tensor out_tensor = Tensor(tensor_dtype, new_tensor_shape, cpu_allocator); - ORT_RETURN_IF_ERROR(onnxruntime::utils::TensorProtoToTensor(Env::Default(), nullptr, initializer, in_tensor)); + onnxruntime::PathString model_path = qnn_model_wrapper.GetGraphViewer().ModelPath().ToPathString(); + const ORTCHAR_T* model_path_str = model_path.empty() ? nullptr : model_path.c_str(); + ORT_RETURN_IF_ERROR(onnxruntime::utils::TensorProtoToTensor(Env::Default(), model_path_str, initializer, in_tensor)); ORT_RETURN_IF_ERROR(Transpose::DoTranspose(permutations, in_tensor, out_tensor)); onnx::TensorProto new_tensor_proto = onnxruntime::utils::TensorToTensorProto(out_tensor, "test"); ORT_RETURN_IF_ERROR(qnn_model_wrapper.UnpackInitializerData(new_tensor_proto, transposed_data)); diff --git a/onnxruntime/test/providers/qnn/qnn_basic_test.cc b/onnxruntime/test/providers/qnn/qnn_basic_test.cc index 4f294f899c170..7fd2441441dcf 100644 --- a/onnxruntime/test/providers/qnn/qnn_basic_test.cc +++ b/onnxruntime/test/providers/qnn/qnn_basic_test.cc @@ -168,6 +168,26 @@ TEST(QnnEP, TestDisableCPUFallback_ConflictingConfig) { } } +// Conv node `Conv` is not supported: GetFileLength for conv_qdq_external_ini.bin failed:open file conv_qdq_external_ini.bin fail, +// errcode = 2 - The system cannot find the file specified. +TEST_F(QnnHTPBackendTests, TestConvWithExternalData) { + Ort::SessionOptions so; + onnxruntime::ProviderOptions options; +#if defined(_WIN32) + options["backend_path"] = "QnnHtp.dll"; +#else + options["backend_path"] = "libQnnHtp.so"; +#endif + + so.AppendExecutionProvider("QNN", options); + + Ort::Status status(OrtSessionOptionsAppendExecutionProvider_CPU(so, 1)); + + const ORTCHAR_T* ort_model_path = ORT_MODEL_FOLDER "conv_qdq_external_ini.onnx"; + + Ort::Session session(*ort_env, ort_model_path, so); +} + // Helper function that runs an ONNX model with a NHWC Resize operator to test that // type/shape inference succeeds during layout transformation. // Refer to onnxruntime/core/graph/contrib_ops/nhwc_inference_context.h. diff --git a/onnxruntime/test/testdata/conv_qdq_external_ini.bin b/onnxruntime/test/testdata/conv_qdq_external_ini.bin new file mode 100644 index 0000000000000000000000000000000000000000..e749ab5af29c58c932a40d432f236cf3ae5d5be3 GIT binary patch literal 2000 zcmeH`>rY#C7{?pqB__t07!!T%i^VtFE2B}ehy&IE8_MR22yHD;N=Gk1PwD0K^z?SR z9(sDCJ?-f!)KfZWx%5I?29(l{%L;+XZf+(6;$>zkk*_xh~3$emfk0VBY+?((J zo`m%SwzfRN3-oB#iwg5v~S%!v~&neh6&Hr;uEZFw=i zY~j*p+H}J4&0ahni-bvs+x!rMEzTj*mvijsP3sZy_~#N_&is5fYP7J~IgMwqR5wv` zbw`L)V_}~>HGh+6bXw{zw|KTuqFT)^+9|_NZ~aJVP@D-= z&UKC@R);=uq4qFaYwmwk@HhgQxM@%tX!OEe0-sLfwd|D{D1{R+A=zIts%-C?I*gd8 z&faT@^=LXvK_f^S& zV6=5RGpX%YM0+zd3%X0` zgl~`ct`V@!;P+s z6Dth#RSFxRcX^vMX1r!VyJcn^>0O5@H0W0$aKZNF(wfshBOa1Q6UrU|`5viu2BI=r z_D@_qLUk$HCy%wNvM!>ecRPjRHx=T^Z?n+6Xo4Pga>!NdPc4Y1!?w^pQs!1ZxEO>&)vDS8 z-fr`15?8i)KCU=&0Nz_H7V8DTn}Fv5zk%6H!27_z13+Xw0saN>8ptmKUVi4of3E`G y0D$$u-+;s2bAZE}LtY2@Dezx_KcD#(F#8weMeqF&L1fh*_57&kM?L@F_xwL!Iyz|p literal 0 HcmV?d00001 diff --git a/onnxruntime/test/testdata/conv_qdq_external_ini.onnx b/onnxruntime/test/testdata/conv_qdq_external_ini.onnx new file mode 100644 index 0000000000000000000000000000000000000000..fad6074aea133f2d5c3ecbf5b597bae70bdde4ce GIT binary patch literal 2204 zcmbVOL2uJA6eexgg|~L3p=(PRw5r4<(n33?u>sPmzy*m5S1wVSx~;R+$r5)R;}>v% z8#fN{Z;&`3{slh+J89RXO}vwO)L` z2VVs!TQ0e5Yh7#x#thK|CCzFCmgyj$rlAN$dQmP4COv0l?$0CigzB@%%7q&3*#uRqK*K{SM=qJWojx6t| zOC9;Cq*|N1Nfb;V6}O495>YPsxWb;|+;6t%>65_vg@Rb5WyKv+wn9eItG9gBl>BS9 z$&6Mr$KR?9cYD||DRxQF5jw&TVOuT0*1&hiUXA@_)IBJiBcCA02!^JII@wN^gG!L| z%wEvRL=QJfupLkz_t0!6_ylW|Kw+vf+CQb~Uo3)qsctCg=A{^(LppFXZ$9Exs#E^O zcrM3HmZ)lF-ck{P+1xk8fagpPT*aua|mCcByqX zTjqc?XdJ9m?60<0DT{YuvRv`f|k73U}hqtG{P@BDiW-Y)E-MwZ7d(6_XKH z)jm97s`{cJ3Hq99c^jtF(?fgb#(#l(f6jRF`liZzJF?>ivJdrXv6CxM76n;?j3}^{ zWv#|rx50uHCi?=S!Fm+kx+b-TM!-%V);)*S5)}kMWcVCM*v~hV zo)|Nqj%y2>t)*Ad5T9B0#cr*teKCfF_x91c0<$n`?&{MOm0>~H%>X?k74<6Ix7?97 z!j|s_Zl7wz8cr;><8}c|tcAz=$dR&oji2KT7-;MO4l_$594YB#kY-5gn=IYPfQ{dW z+RW