pytorch / executorch

On-device AI across mobile, embedded and edge for PyTorch
https://pytorch.org/executorch/
Other
1.96k stars 324 forks source link

Failed to run qnn_inference_runner on an 8 Gen 2 device #6188

Open ammarasyad opened 6 days ago

ammarasyad commented 6 days ago

🐛 Describe the bug

Hello, I'm following this tutorial to try and get it running on my phone. The only change I added was -fsanitize=undefined to examples/qualcomm/CMakeLists.txt to get around the ubsan problem I've been getting. It compiled just fine, but when I tried to run it on my phone, it failed.

I 00:00:00.008633 executorch:qnn_executor_runner.cpp:131] Model file ./dlv3_qnn.pte is loaded.
I 00:00:00.008849 executorch:qnn_executor_runner.cpp:140] Using method forward
I 00:00:00.008931 executorch:qnn_executor_runner.cpp:188] Setting up planned buffer 0, size 9031680.
[INFO] [Qnn ExecuTorch]: create QNN Logger with log_level 2
[WARNING] [Qnn ExecuTorch]:  <W> Initializing HtpProvider

[WARNING] [Qnn ExecuTorch]:  <W> Function not called, PrepareLib isn't loaded!

[INFO] [Qnn ExecuTorch]: Initialize Qnn backend parameters for Qnn executorch backend type 2
[INFO] [Qnn ExecuTorch]: Caching: Caching is in RESTORE MODE.
[WARNING] [Qnn ExecuTorch]: Failed to interpret QNN Context binary. Error code 30010
[ERROR] [Qnn ExecuTorch]: Failed to parse QNN Graph Info. The cache might be broken. Please consider to re-generate the cache.
[WARNING] [Qnn ExecuTorch]:  <W> sg_stubPtr is not null, skip loadRemoteSymbols

[WARNING] [Qnn ExecuTorch]:  <W> This META does not have Alloc2 Support

[WARNING] [Qnn ExecuTorch]:  <W> This META does not have Alloc2 Support

[WARNING] [Qnn ExecuTorch]:  <W> This META does not have Alloc2 Support

[WARNING] [Qnn ExecuTorch]:  <W> This META does not have Alloc2 Support

[WARNING] [Qnn ExecuTorch]:  <W> This META does not have Alloc2 Support

[WARNING] [Qnn ExecuTorch]:  <W> sg_stubPtr is not null, skip loadRemoteSymbols

[WARNING] [Qnn ExecuTorch]:  <W> Function not called, PrepareLib isn't loaded!

[ERROR] [Qnn ExecuTorch]: QNN context cache is invalid.
E 00:00:00.281056 executorch:QnnManager.cpp:158] Fail to configure Qnn context
E 00:00:00.281075 executorch:QnnExecuTorchBackend.cpp:54] Fail to initialize Qnn Manager
E 00:00:00.281090 executorch:method.cpp:106] Init failed for backend QnnBackend: 0x1
F 00:00:00.286557 executorch:qnn_executor_runner.cpp:213] In function main(), assert failed (method.ok()): Loading of method forward failed with status 0x1
Aborted

Any help would be appreciated. Thanks in advance!

Versions

Collecting environment information... PyTorch version: 2.4.0+cu124 Is debug build: False CUDA used to build PyTorch: 12.4 ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64) GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 Clang version: Could not collect CMake version: version 3.30.4 Libc version: glibc-2.35

Python version: 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] (64-bit runtime) Python platform: Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.35 Is CUDA available: True CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4070 Laptop GPU Nvidia driver version: 565.90 cuDNN version: Could not collect HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 39 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 32 On-line CPU(s) list: 0-31 Vendor ID: GenuineIntel Model name: 13th Gen Intel(R) Core(TM) i9-13900HX CPU family: 6 Model: 183 Thread(s) per core: 2 Core(s) per socket: 16 Socket(s): 1 Stepping: 1 BogoMIPS: 4838.39 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq vmx ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves avx_vnni umip waitpkg gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm md_clear serialize flush_l1d arch_capabilities Virtualization: VT-x Hypervisor vendor: Microsoft Virtualization type: full L1d cache: 768 KiB (16 instances) L1i cache: 512 KiB (16 instances) L2 cache: 32 MiB (16 instances) L3 cache: 36 MiB (1 instance) Vulnerability Gather data sampling: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Retbleed: Mitigation; Enhanced IBRS Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected

Versions of relevant libraries: [pip3] executorch==0.3.0a0+7d77d78 [pip3] numpy==2.1.2 [pip3] torch==2.4.0+cu124 [pip3] torchaudio==2.4.0+cu124 [pip3] torchsr==1.0.4 [pip3] torchvision==0.19.0+cu124 [pip3] triton==3.0.0 [conda] Could not collect

shewu-quic commented 5 days ago

Hi @ammarasyad, I think we don't need -fsanitize=undefined. If you hit the ubsan problem, maybe you could try to use android ndk r26c.

May I know if you have same QNN SDK version on device and host?

ammarasyad commented 3 days ago

Hello @shewu-quic I'm using NDK r26c and removed -fsanitize=undefined. The ubsan issue still exists.

I have QNN SDK 2.22.6.240515. Not sure how I can check the version on my phone, though.

shewu-quic commented 3 days ago

Do you push qnn libraries to the device and set LD_LIBRARY_PATH and ADSP_LIBRARY_PATH? https://pytorch.org/executorch/stable/build-run-qualcomm-ai-engine-direct-backend.html#run-model-inference-on-an-android-smartphone-with-qualcomm-socs

ammarasyad commented 3 days ago

Yes, I followed the guide, set up the paths correctly, and copied the necessary files.