Skip to content

Conversation

cccclai
Copy link
Contributor

@cccclai cccclai commented Aug 29, 2025

Add QNN to pip package, target linux only. The qnn sdk will be installed when user import from any submodule in executorch.backend.qualcomm the first time

How to test:

  1. When building the wheel package
conda create -yn executorch python=3.10.0 && conda activate executorch
./install_executorch.sh
EXECUTORCH_BUILDING_WHEEL=1 python setup.py bdist_wheel

The wheel package will be under dist folder

  1. When users install the wheel packages
    Start a new terminal from a fresh repro (like /tmp)
unset EXECUTORCH_BUILDING_WHEEL // to make sure this env is not set
pip install executorch-0.8.0a0+8fe177e-cp310-cp310-linux_x86_64.whl  // path to the wheel package
pip install install torch=="2.9.0.dev20250801" --index-url "https://download.pytorch.org/whl/nightly/cpu"
pip install  --pre torchao --index-url "https://download.pytorch.org/whl/nightly/cpu"

Run the script the same as test_wheel_package_qnn.sh

Copy link

pytorch-bot bot commented Aug 29, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/13794

Note: Links to docs will display an error until the docs builds have been completed.

❌ 3 New Failures, 37 Pending, 4 Unrelated Failures

As of commit 396b21d with merge base 8496f27 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but was present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@cccclai cccclai marked this pull request as draft August 29, 2025 06:42
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 29, 2025
Copy link

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@cccclai cccclai force-pushed the qnn_pip branch 2 times, most recently from 9014e21 to 0ca5bd3 Compare September 1, 2025 21:58
@cccclai
Copy link
Contributor Author

cccclai commented Sep 3, 2025

working version ded7cf0

@cccclai cccclai marked this pull request as ready for review September 4, 2025 15:44
TEMP_ENV_DIR=$(mktemp -d)
echo "Using temporary directory: $TEMP_ENV_DIR"

conda create -y -p "$TEMP_ENV_DIR/env" python=3.10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also check for other python versions? Looks like we do both 3.10 and 3.12 https://pypi.org/project/executorch/0.7.0/#files, so maybe test both?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if venv is used, can we check it works with venv as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added venv in the test too

Comment on lines 138 to 140
conda run -p "$TEMP_ENV_DIR/env" python -c "import executorch; print('executorch imported successfully')"
conda run -p "$TEMP_ENV_DIR/env" python -c "import executorch.backends.qualcomm; print('executorch.backends.qualcomm imported successfully')"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it worth checking if the so files are downloaded and installed? Or the script running would suffice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script includes the lowering steps, should be enough if lowering is successful

- Only runs on Linux x86 platforms. Skips otherwise.
"""
print("Downloading Qualcomm SDK...")
QNN_VERSION = "2.37.0.250724"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe refactor to get/set qnn version functions? Mainly for ease of maintenance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'd need to have a separate PR to remove the hardcoded numbers #13960

libcxx = target_dir / "libc++.so.1.0"
libcxx_abi = target_dir / "libc++abi.so.1.0"
if libcxx.exists():
os.symlink("libc++.so.1.0", target_dir / "libc++.so.1")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is creating symlink to what?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few ones like libc++.so.1.0 to libc++.so.1, that's extra burden for users imo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are system libs generally. I dont know what the expectation is for qnn sdk. Can you tag someone from qcomm to at least understand if there is specific version of libc++ that is need for specific version of qnn sdk.

My biggest concern with all these is that different libraries may have different libc++ requirement. What if mtk's sdk doesnt work with this specific libc++.

if self._ran_build:
return

try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a separate build_ext? is it possible to do?

Copy link
Contributor Author

@cccclai cccclai Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each setup() only has one build_ext to override, but I can double check if we can move it to build instead (where our current main build happens)

Copy link
Contributor

@kimishpatel kimishpatel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments. Lets resolve this soon and validate

@cccclai
Copy link
Contributor Author

cccclai commented Sep 5, 2025

mark as draft to address some feedback

@cccclai cccclai marked this pull request as draft September 5, 2025 18:08
@facebook-github-bot
Copy link
Contributor

@cccclai has imported this pull request. If you are a Meta employee, you can view this in D82069599.

Copy link
Contributor

@kimishpatel kimishpatel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. i will test this separately on my end

@facebook-github-bot
Copy link
Contributor

@cccclai has imported this pull request. If you are a Meta employee, you can view this in D82069599.


# Run build.sh with SDK path exported
env = dict(**os.environ)
env["QNN_SDK_ROOT"] = str(sdk_path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, this env variable only visible when doing pip install. If user starts a new process, will they be notified to use the correct one?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah never mind, this is for building delegate related libraries for packaging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, only building delegates for the wheel package

env_flag = os.getenv("EXECUTORCH_BUILDING_WHEEL", "0").lower()
# If users have preinstalled QNN_SDK_ROOT, we will use it.
qnn_sdk_root_flag = os.getenv("QNN_SDK_ROOT", None)
if env_flag not in ("1", "true", "yes") and not qnn_sdk_root_flag:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the same user will keep downloading SDK if QNN_SDK_ROOT is never set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if QNN_SDK_ROOT is not set, we will use the predefined path SDK_DIR = PKG_ROOT / "sdk" / "qnn". Inside the download_qnn_sdk.py logic, we will check if the library is there already, if yes, we will just use those files

@cccclai
Copy link
Contributor Author

cccclai commented Sep 11, 2025

@haowhsu-quic I will merge this PR for now, but would like to hear your feedback/concern and address them

@cccclai cccclai merged commit 068d341 into main Sep 11, 2025
283 of 292 checks passed
@cccclai cccclai deleted the qnn_pip branch September 11, 2025 04:54
swolchok added a commit that referenced this pull request Sep 11, 2025
This reverts commit 068d341. It broke Windows wheels per https://hud.pytorch.org/hud/pytorch/executorch/main/1?per_page=50&name_filter=windows


ghstack-source-id: da82656
ghstack-comment-id: 3281366424
Pull-Request: #14212
cccclai added a commit that referenced this pull request Sep 11, 2025
from .scripts.download_qnn_sdk import install_qnn_sdk


env_flag = os.getenv("EXECUTORCH_BUILDING_WHEEL", "0").lower()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gate on another flat like BUILDING_WHEEL_FOR_LINUX or something similar

)
QAIRT_CONTENT_DIR = f"qairt/{QNN_VERSION}"

if not is_linux_x86():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the linux check here @kimishpatel

if env_flag not in ("1", "true", "yes") and not qnn_sdk_root_flag:
ok = install_qnn_sdk()

if not ok:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On windows this will always be not ok. So you want to raise this error only if we are linux.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see what you meant, okay let me add it


os.environ["EXECUTORCH_BUILDING_WHEEL"] = "1"

with tempfile.TemporaryDirectory() as tmpdir:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this componenents should be trigerred only for linux as well

cccclai added a commit that referenced this pull request Sep 12, 2025
StrycekSimon pushed a commit to nxp-upstream/executorch that referenced this pull request Sep 23, 2025
Add QNN to pip package, target linux only. The qnn sdk will be installed
when user import from any submodule in executorch.backend.qualcomm the
first time

How to test:

1. When building the wheel package

```
conda create -yn executorch python=3.10.0 && conda activate executorch
./install_executorch.sh
EXECUTORCH_BUILDING_WHEEL=1 python setup.py bdist_wheel
```
The wheel package will be under `dist` folder

2. When users install the wheel packages
Start a new terminal from a fresh repro (like /tmp)
```
unset EXECUTORCH_BUILDING_WHEEL // to make sure this env is not set
pip install executorch-0.8.0a0+8fe177e-cp310-cp310-linux_x86_64.whl  // path to the wheel package
pip install install torch=="2.9.0.dev20250801" --index-url "https://download.pytorch.org/whl/nightly/cpu"
pip install  --pre torchao --index-url "https://download.pytorch.org/whl/nightly/cpu"
```
Run the script the same as `test_wheel_package_qnn.sh`
StrycekSimon pushed a commit to nxp-upstream/executorch that referenced this pull request Sep 23, 2025
StrycekSimon pushed a commit to nxp-upstream/executorch that referenced this pull request Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants