pytorch / pytorch/executorch

Failed to export ViT model to QNN with quant_dtype set to None

Open
#7,429 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

module: qnn partner: qualcomm triaged
Dominant language
Python
Stars
5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
581

Description

🐛 Describe the bug

I can run this command successfully.

python -m examples.qualcomm.scripts.torchvision_vit -b build-android -m SM8650 --compile_only

However, if I set quant_dtype to None, I got following errors:

[ERROR] [Qnn ExecuTorch]: graph_prepare.cc:213:ERROR:could not create op: q::ConvLayer.fp16.s1.tcm

[ERROR] [Qnn ExecuTorch]: graph_prepare.cc:1403:ERROR:Op 0x2c76300000035 preparation failed with err:-1

[ERROR] [Qnn ExecuTorch]:  <E> "aten_view_copy_default_2" generated: could not create op

[ERROR] [Qnn ExecuTorch]:  <E> RouterX86 graph prepare failed 12

[ERROR] [Qnn ExecuTorch]:  <E> Failed to finalize graph (id: 1) with err 1002

[ERROR] [Qnn ExecuTorch]: Failed to finalize Qnn Graph with error: 1002
Traceback (most recent call last):
  File "/home/user/Projects/android/executorch/examples/qualcomm/scripts/torchvision_vit.py", line 150, in <module>
    main(args)
  File "/home/user/Projects/android/executorch/examples/qualcomm/scripts/torchvision_vit.py", line 75, in main
    build_executorch_binary(
  File "/home/user/Projects/android/executorch/examples/qualcomm/utils.py", line 294, in build_executorch_binary
    exported_program = to_backend(edge_prog.exported_program, qnn_partitioner)
  File "/home/user/.conda/envs/robot/lib/python3.10/functools.py", line 889, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "/home/user/Projects/android/executorch/exir/backend/backend_api.py", line 396, in _
    tagged_graph_module = _partition_and_lower(
  File "/home/user/Projects/android/executorch/exir/backend/backend_api.py", line 319, in _partition_and_lower
    partitioned_module = _partition_and_lower_one_graph_module(
  File "/home/user/Projects/android/executorch/exir/backend/backend_api.py", line 249, in _partition_and_lower_one_graph_module
    lowered_submodule = to_backend(
  File "/home/user/.conda/envs/robot/lib/python3.10/functools.py", line 889, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "/home/user/Projects/android/executorch/exir/backend/backend_api.py", line 113, in _
    preprocess_result: PreprocessResult = cls.preprocess(
  File "/home/user/Projects/android/executorch/backends/qualcomm/qnn_preprocess.py", line 111, in preprocess
    assert len(qnn_context_binary) != 0, "Failed to generate Qnn context binary."
AssertionError: Failed to generate Qnn context binary.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/.conda/envs/robot/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/user/.conda/envs/robot/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/user/Projects/android/executorch/examples/qualcomm/scripts/torchvision_vit.py", line 156, in <module>
    raise Exception(e)
Exception: Failed to generate Qnn context binary.
[INFO] [Qnn ExecuTorch]: Destroy Qnn context
[INFO] [Qnn ExecuTorch]: Destroy Qnn device
[INFO] [Qnn ExecuTorch]: Destroy Qnn backend
Versions

Python: 3.10.16
ExecuTorch: 0.4
QNN SDK: 2.29.0.241129

cc @cccclai @winskuo-quic @shewu-quic

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with examples/qualcomm/scripts/torchvision_vit.py and reproduce the failure using the provided command with quant_dtype set to None. Trace the call through examples/qualcomm/utils.py into backends/qualcomm/qnn_preprocess.py, focusing on QNN context generation and the reported ConvLayer and view-copy errors. Done means the ViT export generates a QNN context binary successfully with quant_dtype=None.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.