Skip to content

Commit 73e9073

Browse files
Enable test_qnn_delegate tests to run on PR (#19050)
Summary: Pull Request resolved: #19050 Enable `test_qnn_delegate` tests to run on PR Differential Revision: D102010420
1 parent 209868b commit 73e9073

3 files changed

Lines changed: 101 additions & 0 deletions

File tree

.github/workflows/pull.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,44 @@ jobs:
923923
# Run QNN pass unit tests
924924
pytest -xvs backends/qualcomm/tests/test_passes.py
925925
926+
test-qnn-delegate-linux:
927+
name: test-qnn-delegate-linux
928+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
929+
permissions:
930+
id-token: write
931+
contents: read
932+
strategy:
933+
fail-fast: false
934+
with:
935+
runner: linux.2xlarge
936+
docker-image: ci-image:executorch-ubuntu-22.04-qnn-sdk
937+
submodules: 'recursive'
938+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
939+
timeout: 90
940+
script: |
941+
# The generic Linux job chooses to use base env, not the one setup by the image
942+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
943+
conda activate "${CONDA_ENV}"
944+
945+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh
946+
# Source (not bash) so QNN_SDK_ROOT stays in the environment
947+
PYTHON_EXECUTABLE=python source .ci/scripts/build-qnn-sdk.sh
948+
949+
# Editable install so the PyQnnManagerAdaptor .so built by build-qnn-sdk.sh
950+
# is visible in the source tree
951+
CMAKE_ARGS="-DEXECUTORCH_BUILD_QNN=ON -DQNN_SDK_ROOT=$QNN_SDK_ROOT -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON" \
952+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool cmake --editable true
953+
954+
pip install -r requirements-examples.txt
955+
956+
# Enable conftest.py to call setup_environment() for pytest runs
957+
export QNN_DELEGATE_TEST=1
958+
export LD_LIBRARY_PATH="$QNN_SDK_ROOT/lib/x86_64-linux-clang/:$(realpath build-x86/lib/):${LD_LIBRARY_PATH:-}"
959+
960+
# Run all test classes. Tests that need a device, datasets, or
961+
# pretrained artifacts self-skip via required_envs() guards.
962+
pytest -xvs backends/qualcomm/tests/test_qnn_delegate.py
963+
926964
test-phi-3-mini-runner-linux:
927965
name: test-phi-3-mini-runner-linux
928966
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright (c) Qualcomm Innovation Center, Inc.
2+
# All rights reserved
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
"""Pytest conftest for test_qnn_delegate.py.
8+
9+
When test_qnn_delegate.py is invoked via pytest (instead of as __main__),
10+
setup_environment() is never called, so TestQNN class attributes remain at
11+
their defaults (None / empty string / False). This conftest bridges the gap
12+
by calling setup_environment() with a synthetic argv built from environment
13+
variables, keeping a single source of truth for attribute assignment.
14+
15+
Required env vars for x86 simulator execution:
16+
QNN_SOC_MODEL - e.g. "SM8650"
17+
QNN_SDK_ROOT - path to QNN SDK (also used by verify_output)
18+
19+
Optional env vars (with defaults shown):
20+
QNN_BACKEND - "htp"
21+
QNN_BUILD_FOLDER - "build-x86"
22+
QNN_ENABLE_X86_64 - "1" to enable x86 simulator mode
23+
EXECUTORCH_ROOT - cwd
24+
QNN_ARTIFACT_DIR - "/tmp/qnn_test_artifacts"
25+
"""
26+
27+
import os
28+
import sys
29+
30+
31+
def pytest_configure(config):
32+
if os.environ.get("QNN_DELEGATE_TEST") != "1":
33+
return
34+
35+
argv = [
36+
"test_qnn_delegate.py",
37+
"--soc_model",
38+
os.environ.get("QNN_SOC_MODEL", "SM8650"),
39+
"--backend",
40+
os.environ.get("QNN_BACKEND", "htp"),
41+
"--build_folder",
42+
os.environ.get("QNN_BUILD_FOLDER", "build-x86"),
43+
"--executorch_root",
44+
os.environ.get("EXECUTORCH_ROOT", os.getcwd()),
45+
"--artifact_dir",
46+
os.environ.get("QNN_ARTIFACT_DIR", "/tmp/qnn_test_artifacts"),
47+
]
48+
49+
if os.environ.get("QNN_ENABLE_X86_64", "1") == "1":
50+
argv.append("--enable_x86_64")
51+
52+
original_argv = sys.argv
53+
try:
54+
sys.argv = argv
55+
from executorch.backends.qualcomm.tests.test_qnn_delegate import (
56+
setup_environment,
57+
)
58+
59+
setup_environment()
60+
finally:
61+
sys.argv = original_argv

backends/qualcomm/tests/test_qnn_delegate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,8 @@ def test_qnn_backend_is_inf(self):
13151315
self.lower_module_and_test_output(module, sample_input)
13161316

13171317
def test_qnn_backend_is_nan(self):
1318+
if self.enable_x86_64:
1319+
self.skipTest("isnan produces incorrect results on x86 simulator")
13181320
module = IsNan() # noqa: F405
13191321
sample_inputs = [
13201322
(

0 commit comments

Comments
 (0)