-
Notifications
You must be signed in to change notification settings - Fork 332
Add QNN EP documentation to OGA including Genie note #2158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
baijumeswani
merged 5 commits into
microsoft:main
from
CodeLinaro:dev/qti-kromero/qnn-genie-docs
May 18, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4668af0
Add QNN EP documentation
qti-kromero 122ce78
Add note on Genie API integration via DLC EPContext models
qti-kromero c0df352
Address review comments: fix tokenizer decode, clarify Genie API, cla…
qti-kromero 94ef305
Refactor Genie paragraph to user-facing recommendation
qti-kromero b64ad37
Use onnxruntime_qnn helpers for EP registration in QNN docs
qti-kromero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # QNN Execution Provider | ||
|
|
||
| ONNX Runtime GenAI supports running models on Qualcomm Snapdragon NPUs via the QNN Execution | ||
| Provider (EP). This enables hardware-accelerated LLM inference on Snapdragon-based devices on | ||
| Windows ARM64 and Linux ARM64. | ||
|
|
||
| For best performance, use the newer QAIRT-targeting pipelines from | ||
| [olive-recipes](https://github.com/microsoft/olive-recipes), which optimize models for | ||
| accelerated NPU inference via the Genie runtime. Older QNN-targeting recipes produce | ||
| standard QNN models that also work but do not use this acceleration pathway. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| **Packages** | ||
|
|
||
| - `onnxruntime-genai` — the OGA runtime | ||
| - `onnxruntime-qnn` — the QNN EP plugin ([PyPI](https://pypi.org/project/onnxruntime-qnn/) / | ||
| [NuGet](https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime.QNN)) | ||
|
|
||
| **Model** | ||
|
|
||
| QNN inference requires a model prepared for the QNN EP, packaged as an ONNX file containing | ||
| compiled QNN graph artifacts. The `genai_config.json` and model files are produced by the | ||
| [olive-recipes](https://github.com/microsoft/olive-recipes) pipeline targeting the QNN backend. | ||
|
|
||
| ## Usage | ||
|
|
||
| The QNN EP is a plugin and must be registered before loading the model. The `onnxruntime-qnn` | ||
| package provides helpers to locate the library and EP name: | ||
|
|
||
| ```python | ||
| import onnxruntime_genai as og | ||
| import onnxruntime_qnn | ||
|
|
||
| # Register the QNN EP plugin before loading the model. | ||
| og.register_execution_provider_library( | ||
| onnxruntime_qnn.get_ep_name(), # "QNNExecutionProvider" | ||
| onnxruntime_qnn.get_library_path() # platform-aware path to the QNN EP shared library | ||
| ) | ||
|
|
||
| # Load model. The genai_config.json from the olive-recipes pipeline already | ||
| # specifies the QNN provider, so no further config is needed in the common case. | ||
| # To override options, use og.Config directly: | ||
| # config = og.Config("/path/to/model") | ||
| # config.set_provider_option("QNN", "htp_performance_mode", "burst") | ||
| # model = og.Model(config) | ||
|
baijumeswani marked this conversation as resolved.
|
||
| model = og.Model("/path/to/model") | ||
| tokenizer = og.Tokenizer(model) | ||
| tokenizer_stream = tokenizer.create_stream() | ||
|
|
||
| params = og.GeneratorParams(model) | ||
| params.set_search_options(max_length=200) | ||
| generator = og.Generator(model, params) | ||
| generator.append_tokens(tokenizer.encode("What color is the sky?")) | ||
|
|
||
| while not generator.is_done(): | ||
| generator.generate_next_token() | ||
| print(tokenizer_stream.decode(generator.get_next_tokens()[0]), end="", flush=True) | ||
|
qti-kromero marked this conversation as resolved.
|
||
| print() | ||
|
qti-kromero marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
|
qti-kromero marked this conversation as resolved.
|
||
| ## Provider Options | ||
|
|
||
| Options are set via `config.set_provider_option("QNN", key, value)`. | ||
|
|
||
| | Option | Description | Values | | ||
| |---|---|---| | ||
| | `htp_performance_mode` | NPU power/performance profile | `burst`, `balanced`, `high_performance`, `power_saver` | | ||
| | `vtcm_mb` | VTCM allocation size in MB | `"8"`, `"16"`, etc. | | ||
| | `enable_htp_shared_memory_allocator` | Enable shared memory allocator for direct OGA/QNN tensor handoff | `"1"` to enable | | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.