-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[QNN-EP] Enable verbose and artifacts saving in onnxruntime_provider_test.exe #26396
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
Open
qti-hungjuiw
wants to merge
3
commits into
microsoft:main
Choose a base branch
from
CodeLinaro:dev/qti-hungjuiw/qnn-test-save
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+278
−8
Open
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
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 |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # ONNX Runtime QNN Execution Provider Tests | ||
| ## Overview | ||
| 1. The `onnxruntime/test/providers/qnn` directory contains integration tests for the Qualcomm Neural Network (QNN) execution provider. | ||
| 2. Most testcases run an ONNX model through the QNN-EP, then verifies the inference result against the one on CPU-EP | ||
|
|
||
| ## Building the Tests | ||
| The tests are built as part of the regular ONNX Runtime build. After a successful build you will have an executable named | ||
| - onnxruntime_provider_test.exe (Windows) | ||
| - onnxruntime_provider_test (Linux/macOS) | ||
|
|
||
| ## Running the Tests | ||
| 1. QNN supports several backends. You can use the standard Google‑Test syntax for filtering: | ||
| - `onnxruntime_provider_test.exe --gtest_filter=QnnCPUBackendTests.*` | ||
| - `onnxruntime_provider_test.exe --gtest_filter=QnnHTPBackendTests.*` | ||
| - `onnxruntime_provider_test.exe --gtest_filter=QnnGPUBackendTests.*` | ||
| - `onnxruntime_provider_test.exe --gtest_filter=QnnIRBackendTests.*` | ||
| 2. Saving Test Artifacts | ||
| - For debugging it is often helpful to keep the intermediate files that the tests generate. The following environment | ||
| variables are recognized by the test binary: | ||
| - `QNN_DUMP_ONNX`: Saves the input ONNX model used for the test | ||
| - `QNN_DUMP_JSON`: Save json qnn graph with provider_option `dump_json_qnn_graph` | ||
| - `QNN_DUMP_DLC`: Saves the compiled QNN DLC file by specifying the provider_option `backend_path` to `QnnIr.dll` | ||
| - The artifacts will be saved to a directory named with `<TestSuite>_<TestName>` | ||
| ``` | ||
| . | ||
| ├── QnnCPUBackendTests_BatchNorm2D_fp32 # RunQnnModelTest | ||
| │ ├── dumped_f32_model.onnx # float32 ONNX model | ||
| │ ├── QNNExecutionProvider_QNN_XXXX_X_X.dlc | ||
| │ └── QNNExecutionProvider_QNN_XXXX_X_X.json | ||
| ├── QnnHTPBackendTests_BatchNorm_FP16 # TestFp16ModelAccuracy | ||
| │ ├── dumped_f16_model.onnx # float16 ONNX model | ||
| │ ├── dumped_f32_model.onnx # float32 ONNX model | ||
| │ ├── QNNExecutionProvider_QNN_XXXX_X_X.dlc | ||
| │ └── QNNExecutionProvider_QNN_XXXX_X_X.json | ||
| └── QnnHTPBackendTests_BatchNorm2D_U8U8S32 # TestQDQModelAccuracy | ||
| ├── dumped_f32_model.onnx # float32 ONNX model | ||
| ├── dumped_qdq_model.onnx # QDQ ONNX model | ||
| ├── QNNExecutionProvider_QNN_XXXX_X_X.dlc | ||
| └── QNNExecutionProvider_QNN_XXXX_X_X.json | ||
|
|
||
| # All artifact files are placed under the current working directory from which the test binary is invoked. | ||
| ``` | ||
| 3. Verbose | ||
| - `QNN_VERBOSE`: Sets the ONNX Runtime log level to `ORT_LOGGING_LEVEL_VERBOSE` | ||
|
|
||
| 4. You can enable any combination of these environment variables, for example: | ||
| - On Linux/macOS | ||
| ```bash | ||
| export QNN_DUMP_ONNX=1 | ||
| export QNN_DUMP_JSON=1 | ||
| export QNN_DUMP_DLC=1 | ||
| export QNN_VERBOSE=1 | ||
| ``` | ||
| - On Windows | ||
| ```cmd | ||
| set QNN_DUMP_ONNX=1 | ||
| set QNN_DUMP_JSON=1 | ||
| set QNN_DUMP_DLC=1 | ||
| set QNN_VERBOSE=1 | ||
| ``` | ||
| ```ps1 | ||
| $Env:QNN_DUMP_ONNX = "1" | ||
| $Env:QNN_DUMP_JSON = "1" | ||
| $Env:QNN_DUMP_DLC = "1" | ||
| $Env:QNN_VERBOSE = "1" | ||
| ``` | ||
|
|
||
| # Note | ||
| - An issue on QNN backends can prevent the test artifacts from being successfully saved. | ||
| - The `onnxruntime_provider_test.exe` does not automatically delete the artifact directories, so you may want to prune them after a debugging session. |
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 |
|---|---|---|
|
|
@@ -101,6 +101,12 @@ void RunQnnModelTest(const GetTestModelFn& build_test_case, ProviderOptions prov | |
| int opset_version, ExpectedEPNodeAssignment expected_ep_assignment, | ||
| float fp32_abs_err, logging::Severity log_severity, bool verify_outputs, | ||
| std::function<void(const Graph&)>* ep_graph_checker) { | ||
| std::filesystem::path output_dir; | ||
| if (QNNTestEnvironment::GetInstance().dump_onnx() || | ||
| QNNTestEnvironment::GetInstance().dump_json() || | ||
| QNNTestEnvironment::GetInstance().dump_dlc()) { | ||
| output_dir = QNNTestEnvironment::GetInstance().CreateTestcaseDirs(); | ||
| } | ||
| EPVerificationParams verification_params; | ||
| verification_params.ep_node_assignment = expected_ep_assignment; | ||
| verification_params.fp32_abs_err = fp32_abs_err; | ||
|
|
@@ -110,6 +116,10 @@ void RunQnnModelTest(const GetTestModelFn& build_test_case, ProviderOptions prov | |
|
|
||
| auto& logging_manager = DefaultLoggingManager(); | ||
| logging_manager.SetDefaultLoggerSeverity(log_severity); | ||
| if (QNNTestEnvironment::GetInstance().verbose()) { | ||
| logging_manager.RemoveSink(logging::SinkType::EtwSink); | ||
| logging_manager.SetDefaultLoggerSeverity(logging::Severity::kVERBOSE); | ||
| } | ||
|
|
||
| onnxruntime::Model model("QNN_EP_TestModel", false, ModelMetaData(), PathString(), | ||
| IOnnxRuntimeOpSchemaRegistryList(), domain_to_version, {}, | ||
|
|
@@ -123,7 +133,27 @@ void RunQnnModelTest(const GetTestModelFn& build_test_case, ProviderOptions prov | |
| // Serialize the model to a string. | ||
| std::string model_data; | ||
| model.ToProto().SerializeToString(&model_data); | ||
|
|
||
| if (QNNTestEnvironment::GetInstance().dump_onnx()) { | ||
| auto dump_path = output_dir / ToPathString("dumped_f32_model.onnx"); | ||
| LOGS(logging_manager.DefaultLogger(), VERBOSE) << "Save onnx model at: " << dump_path; | ||
| ASSERT_STATUS_OK(onnxruntime::Model::Save(model, dump_path)); | ||
| } | ||
|
|
||
| TryEnableQNNSaver(provider_options); | ||
| if (QNNTestEnvironment::GetInstance().dump_dlc()) { | ||
| provider_options["dump_qnn_ir_dlc"] = "1"; | ||
| provider_options["dump_qnn_ir_dlc_dir"] = output_dir.string(); | ||
| #if defined(_WIN32) | ||
| provider_options["qnn_ir_backend_path"] = "QnnIr.dll"; | ||
| #else | ||
| provider_options["qnn_ir_backend_path"] = "libQnnIr.so"; | ||
| #endif // defined(_WIN32) | ||
| } | ||
| if (QNNTestEnvironment::GetInstance().dump_json()) { | ||
| provider_options["dump_json_qnn_graph"] = "1"; | ||
| provider_options["json_qnn_graph_dir"] = output_dir.string(); | ||
| } | ||
|
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: some of the test setup code is duplicated a few times. would it be worth refactoring it into helper functions? |
||
| RunAndVerifyOutputsWithEP(AsByteSpan(model_data.data(), model_data.size()), "QNN_EP_TestLogID", | ||
| QnnExecutionProviderWithOptions(provider_options), | ||
| helper.feeds_, verification_params, | ||
|
|
@@ -134,11 +164,21 @@ void RunQnnModelTestHTPNoVerify(const GetTestModelFn& build_test_case, ProviderO | |
| int opset_version, ExpectedEPNodeAssignment expected_ep_assignment, | ||
| logging::Severity log_severity, | ||
| std::function<void(const Graph&)>* ep_graph_checker) { | ||
| std::filesystem::path output_dir; | ||
| if (QNNTestEnvironment::GetInstance().dump_onnx() || | ||
| QNNTestEnvironment::GetInstance().dump_dlc() || | ||
| QNNTestEnvironment::GetInstance().dump_json()) { | ||
| output_dir = QNNTestEnvironment::GetInstance().CreateTestcaseDirs(); | ||
| } | ||
| // Add kMSDomain to cover contrib op like Gelu | ||
| const std::unordered_map<std::string, int> domain_to_version = {{"", opset_version}, {kMSDomain, 1}}; | ||
|
|
||
| auto& logging_manager = DefaultLoggingManager(); | ||
| logging_manager.SetDefaultLoggerSeverity(log_severity); | ||
| if (QNNTestEnvironment::GetInstance().verbose()) { | ||
| logging_manager.RemoveSink(logging::SinkType::EtwSink); | ||
| logging_manager.SetDefaultLoggerSeverity(logging::Severity::kVERBOSE); | ||
| } | ||
|
|
||
| onnxruntime::Model model("QNN_EP_TestModel", false, ModelMetaData(), PathString(), | ||
| IOnnxRuntimeOpSchemaRegistryList(), domain_to_version, {}, | ||
|
|
@@ -152,7 +192,27 @@ void RunQnnModelTestHTPNoVerify(const GetTestModelFn& build_test_case, ProviderO | |
| // Serialize the model to a string. | ||
| std::string model_data; | ||
| model.ToProto().SerializeToString(&model_data); | ||
|
|
||
| if (QNNTestEnvironment::GetInstance().dump_onnx()) { | ||
| auto dump_path = output_dir / ToPathString("dumped_f32_model.onnx"); | ||
| LOGS(logging_manager.DefaultLogger(), VERBOSE) << "Save onnx model at: " << dump_path; | ||
| ASSERT_STATUS_OK(onnxruntime::Model::Save(model, dump_path)); | ||
| } | ||
|
|
||
| TryEnableQNNSaver(provider_options); | ||
| if (QNNTestEnvironment::GetInstance().dump_dlc()) { | ||
| provider_options["dump_qnn_ir_dlc"] = "1"; | ||
| provider_options["dump_qnn_ir_dlc_dir"] = output_dir.string(); | ||
| #if defined(_WIN32) | ||
| provider_options["qnn_ir_backend_path"] = "QnnIr.dll"; | ||
| #else | ||
| provider_options["qnn_ir_backend_path"] = "libQnnIr.so"; | ||
| #endif // defined(_WIN32) | ||
| } | ||
| if (QNNTestEnvironment::GetInstance().dump_json()) { | ||
| provider_options["dump_json_qnn_graph"] = "1"; | ||
| provider_options["json_qnn_graph_dir"] = output_dir.string(); | ||
| } | ||
|
|
||
| SessionOptions so; | ||
| so.session_logid = "QNN_EP_TestLogID"; | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of curiosity, why is the ETW log sink removed?