Skip to content

[PoC ONLY] Qualcomm AI Engine Direct - HF Exporter Mininal Script - #22400

Draft
winskuo-quic wants to merge 2 commits into
pytorch:mainfrom
CodeLinaro:dev1/winskuo/executorch_hf_trial_run
Draft

[PoC ONLY] Qualcomm AI Engine Direct - HF Exporter Mininal Script#22400
winskuo-quic wants to merge 2 commits into
pytorch:mainfrom
CodeLinaro:dev1/winskuo/executorch_hf_trial_run

Conversation

@winskuo-quic

@winskuo-quic winskuo-quic commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR serves as a PoC demo how to use hf-transformer exporter to export a HF LLM model.
Since this is just a PoC, a lot of stuff in the patch and this PR is hardcoded. e.g., the example script is set to Llama3.2 1B. A lot of implementations for hf-transformer exporter patch is hardcoded and not the best design, it is just to prove we can get the same performance using hf-transformer exporter flow.

Steps

Notes: All these will be done in a single conda environment, you don't need to create multiple environments.

Step 1

Checkout to this branch. Enter your conda environment, do all the basic setups as usual, e.g., PYTHONPATH=$EXECUTORCH_ROOT/.., git submodule sync, git submodule update --init, python install_executorch.py, etc.

Step 2

Next, create an empty folder and inside do the following.
git clone the hugging face repo to your local machine: https://github.com/huggingface/transformers

Step 2

Checkout to this PR: huggingface/transformers#47747

Step 3

Apply the PoC patch to HF repo, under ./hf-transformers/transformers

Step 4

After you apply the patch, do:
pip uninstall -y transformers # Probably optional buy highly recommended
pip install -e . --no-deps # --no-deps in case it overrides some executorch dependencies.

Step 5

Execute
python examples/qualcomm/oss_scripts/hf_exporter.py --prompt "Simply put, the theory of relativity states that" --soc_model SM8750 --device $DEVICE --build_folder build-android/ --max_seq_len 1024

Performance Check

This is a quick to ensure that the model lowered through HF-Exporter API is similar as ExecuTorch directly lowering HF model, we have checked the final performance and compared the number of Executorch nodes. After checking both, the node number and performance does match.

Original Flow
image image
HF-Exporter Flow
image image

However, this is only for quick validation and does not guarantee the final QNN graph is identical.

Test plan

NA

@pytorch-bot

pytorch-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 4 New Failures

As of commit fe92052 with merge base d750618 (image):

NEW FAILURES - The following jobs have failed:

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

@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 Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

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.


if not args.pre_gen_pte:
# The whole export is this one call; everything after it is this script's business.
et_program_manager = ExecutorchExporter().export(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hi @psiddh,
This is a PoC to demo how to run HuggingFace Exporter API with ExecuTorch. Please take a look at the summary section of this PR to see how to reproduce.
It requires applying another patch to HuggingFace repo.

Overall, we followed HuggingFace convention and design, using only this single API call to lower a model to backend.

This PR looks a little messy because I applied this on top of my HF model optimization PR: #22170, so please ignore the 2nd commit and just focus on the top commit of this PR.
Thanks

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.

1 participant