Skip to content

Link QNN backend to pybinding lib when built - #13467

Merged
GregoryComer merged 284 commits into
mainfrom
gh/GregoryComer/131/head
Aug 20, 2025
Merged

Link QNN backend to pybinding lib when built#13467
GregoryComer merged 284 commits into
mainfrom
gh/GregoryComer/131/head

Conversation

@GregoryComer

@GregoryComerGregoryComer commented Aug 17, 2025

Copy link
Copy Markdown
Contributor

This change makes it possible to run QNN models with pybindings, when enabled. It does still require the environment setup described in the docs.

I validated this change locally by running install_executorch.sh with CMAKE_ARGS="-DEXECUTORCH_BUILD_QNN=ON", and then lowering and running a simple add model. The CI set up further in this stack also leverage this feature and test it extensively.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]

@digantdesaidigantdesai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess rest of the pybind code was already present?

@GregoryComer

Copy link
Copy Markdown
ContributorAuthor

I guess rest of the pybind code was already present?

When all of the required libraries and environment variables are set up, it will work with only this change. I would like to further simplify, as there is a lot of setup required - including some copying around of python extension binaries. But this code here is enough to make it runnable in conjunction with the existing QNN CI scripts (which do all of the setup).

@cccclai

Copy link
Copy Markdown
Contributor

as there is a lot of setup required - including some copying around of python extension binaries

Can you elaborate?

@GregoryComer

Copy link
Copy Markdown
ContributorAuthor

as there is a lot of setup required - including some copying around of python extension binaries

Can you elaborate?

Yeah, it looks like it's currently building the Python extension components separately and then copying them into the ET directory. (See https://docs.pytorch.org/executorch/main/backends-qualcomm.html#aot-ahead-of-time-components). As part of the build cleanup and pybind enablement, I'll see if I can fold that into our "main" pybind build. That will also make it just work with installation, wheels, etc.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Base automatically changed from gh/GregoryComer/130/head to mainAugust 19, 2025 21:58
@cccclai

Copy link
Copy Markdown
Contributor

as there is a lot of setup required - including some copying around of python extension binaries

Can you elaborate?

Yeah, it looks like it's currently building the Python extension components separately and then copying them into the ET directory. (See https://docs.pytorch.org/executorch/main/backends-qualcomm.html#aot-ahead-of-time-components). As part of the build cleanup and pybind enablement, I'll see if I can fold that into our "main" pybind build. That will also make it just work with installation, wheels, etc.

They should be part of ./backends/qualcomm/scripts/build.sh. After you run this script, does pybind work?

[ghstack-poisoned]
@GregoryComerGregoryComer added the release notes: none Do not include this in the release notes label Aug 19, 2025
Add (unquantized) QNN test flows to the nightly CI. This runs both the
model and operator suite.
@GregoryComer

Copy link
Copy Markdown
ContributorAuthor

as there is a lot of setup required - including some copying around of python extension binaries

Can you elaborate?

Yeah, it looks like it's currently building the Python extension components separately and then copying them into the ET directory. (See https://docs.pytorch.org/executorch/main/backends-qualcomm.html#aot-ahead-of-time-components). As part of the build cleanup and pybind enablement, I'll see if I can fold that into our "main" pybind build. That will also make it just work with installation, wheels, etc.

They should be part of ./backends/qualcomm/scripts/build.sh. After you run this script, does pybind work?

Sort of. It does expect that you're running scripts from the root directory of executorch (or have an editable install), since it puts the extension binaries in the source directory. So it won't work if you're using ET from another directory, such as a dependent project. It should ideally put these binaries wherever the installed copy of the executorch python package is.

If no objection, I'm happy to take this task as part of the build workstream. Basically, running install_executorch.sh with qnn enabled will automatically do what that build.sh script does as part of the main install, in order to make it easy.

[ghstack-poisoned]
GregoryComer added a commit that referenced this pull request Aug 20, 2025
ghstack-source-id: 2b27fbd
ghstack-comment-id: 3194008742
Pull-Request: #13467
[ghstack-poisoned]

@cccclaicccclai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for enabling pybinding + QNN

@GregoryComer
GregoryComer merged commit ea0fff3 into mainAug 20, 2025
225 of 240 checks passed
@GregoryComer
GregoryComer deleted the gh/GregoryComer/131/head branch August 20, 2025 18:14

# We need the runner to test the built library.
PYTHON_EXECUTABLE=python CMAKE_ARGS="$EXTRA_BUILD_ARGS" .ci/scripts/setup-linux.sh --build-tool cmake --build-mode Release
PYTHON_EXECUTABLE=python CMAKE_ARGS="$EXTRA_BUILD_ARGS" .ci/scripts/setup-linux.sh --build-tool cmake --build-mode Release --editable true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you remind me why this was necessary?

agrima1304 pushed a commit to agrima1304/executorch that referenced this pull request Aug 26, 2025
This change makes it possible to run QNN models with pybindings, when
enabled. It does still require the environment setup described in the
docs.
I validated this change locally by running install_executorch.sh with
CMAKE_ARGS="-DEXECUTORCH_BUILD_QNN=ON", and then lowering and running a
simple add model. The CI set up further in this stack also leverage this
feature and test it extensively.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.release notes: noneDo not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@GregoryComer@cccclai@digantdesai