Skip to content

Commit 05b977d

Browse files
authored
Qualcomm AI Engine Direct - tensor dumping at lpai backend (pytorch#20369)
### Summary Currently, using --dump_intermediate_outputs and RPC mode will dump tensor ### Test plan python backends/qualcomm/tests/test_qnn_delegate.py -k TestQNNQuantizedUtils.test_qnn_backend_dump_intermediate_outputs_simple_model -b build-android -s ${SN} -m ${CHIPID} --backend lpai python backends/qualcomm/tests/test_qnn_delegate.py -k TestQNNQuantizedUtils.test_qnn_backend_dump_intermediate_outputs_simple_model -b build-android -s ${SN} -m ${CHIPID} --dump_intermediate_outputs --backend lpai
1 parent 522ed49 commit 05b977d

3 files changed

Lines changed: 34 additions & 7 deletions

File tree

backends/qualcomm/debugger/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ After `build_executorch_binary()`, the debugger holds:
156156

157157
Ensure `dump_intermediate_outputs` is enabled in your `QnnConfig` (or pass `--dump_intermediate_outputs` via CLI). Only run **one inference** for debugging — multiple executions are not supported.
158158

159+
**Note:** Intermediate tensor dumping is not currently supported in direct mode on HTP/LPAI backends.
160+
159161
```python
160162
from executorch.examples.qualcomm.utils import SimpleADB
161163

@@ -266,7 +268,7 @@ python -m examples.qualcomm.util_scripts.qnn_intermediate_debugger_demo -b build
266268
3. Does not support graphs with partitions (partial delegation).
267269
4. Does not support LLM models.
268270
5. Does not support graphs with multiple methods.
269-
271+
6. Intermediate tensor dumping is not currently supported in direct mode on HTP/LPAI backends.
270272

271273
## ExecuTorch QNN HTP Heap Profiling
272274

backends/qualcomm/export_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ def __init__(
276276
self.skip_push = qnn_config.skip_push
277277
self.backend_library_paths = {}
278278

279+
if self.direct_build_folder and self.dump_intermediate_outputs:
280+
raise ValueError(
281+
"Per-tensor dumping is currently not supported in direct mode."
282+
)
279283
if self.direct_build_folder:
280284
direct_general_artifacts = [
281285
f"{self.build_path}/examples/qualcomm/direct_executor_runner/libqnn_executorch_stub.so",
@@ -437,9 +441,8 @@ def execute(
437441
f"--input_list_path {self.input_list_filename}",
438442
f"--etdump_path {self.etdump_path}",
439443
"--shared_buffer" if self.shared_buffer else "",
440-
f"--debug_output_path {self.debug_output_path}",
441444
(
442-
"--dump_intermediate_outputs"
445+
f"--debug_output_path {self.debug_output_path} --dump_intermediate_outputs"
443446
if self.dump_intermediate_outputs
444447
else ""
445448
),

backends/qualcomm/tests/test_qnn_delegate.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6167,6 +6167,10 @@ def test_qnn_backend_dump_intermediate_outputs_topk(self):
61676167
)
61686168

61696169
def test_qnn_backend_dump_intermediate_outputs_simple_model(self):
6170+
if self.direct_build_folder:
6171+
self.skipTest(
6172+
"Direct mode does not support per-tensor dumping (HTP/LPAI backends)."
6173+
)
61706174
backend_options = generate_htp_compiler_spec(use_fp16=True)
61716175
TestQNN.compiler_specs = generate_qnn_executorch_compiler_spec(
61726176
soc_model=self.chipset_table[TestQNN.soc_model],
@@ -6897,20 +6901,38 @@ def output_callback(log_msg):
68976901
)
68986902

68996903
def test_qnn_backend_dump_intermediate_outputs_simple_model(self):
6900-
backend_options = generate_htp_compiler_spec(use_fp16=False)
6904+
# TODO: LPAI direct mode support per-tensor dumping.
6905+
if self.direct_build_folder:
6906+
self.skipTest(
6907+
"Direct mode does not support per-tensor dumping (HTP/LPAI backends)."
6908+
)
6909+
match get_backend_type(self.backend):
6910+
case QnnExecuTorchBackendType.kHtpBackend:
6911+
backend_options = generate_htp_compiler_spec(use_fp16=False)
6912+
expected_compared_events = 14
6913+
case QnnExecuTorchBackendType.kLpaiBackend:
6914+
backend_options = generate_lpai_compiler_spec(
6915+
target_env=self.get_lpai_target_env()
6916+
)
6917+
# I/O q/dq nodes fall back to CPU via FoldQDQ LPAI workaround
6918+
# and are excluded from QNN etdump; update after first LPAI run
6919+
expected_compared_events = 17
6920+
case _:
6921+
raise ValueError("Backend is not implemented yet")
69016922
TestQNN.compiler_specs = generate_qnn_executorch_compiler_spec(
69026923
soc_model=self.chipset_table[TestQNN.soc_model],
69036924
backend_options=backend_options,
69046925
dump_intermediate_outputs=True,
69056926
)
69066927
module = SimpleModel() # noqa: F405
6928+
torch.manual_seed(8)
69076929
sample_input = (torch.ones(1, 32, 28, 28), torch.ones(1, 32, 28, 28))
6908-
module = self.get_qdq_module(module, sample_input)
6930+
qdq_module = self.get_qdq_module(module, sample_input)
69096931
self.lower_module_and_test_output(
6910-
module,
6932+
qdq_module,
69116933
sample_input,
69126934
expected_partitions=1,
6913-
expected_compared_events=14,
6935+
expected_compared_events=expected_compared_events,
69146936
)
69156937

69166938
def test_qnn_backend_dump_intermediate_outputs_topk(self):

0 commit comments

Comments
 (0)