Skip to content

Qualcomm AI Engine Direct - Allow selective graph loading from multi-graph context - #25189

Open
quic-xiyushi wants to merge 1 commit into
pytorch:mainfrom
CodeLinaro:dev1/ichowdhu/qnn_multi_graph
Open

quic-xiyushi wants to merge 1 commit into
pytorch:mainfrom
CodeLinaro:dev1/ichowdhu/qnn_multi_graph

Conversation

@quic-xiyushi

Copy link
Copy Markdown
Contributor

This change was authored by Iftekhar Chowdhury (@iftekhar-hc).

Summary

This PR adds a new runtime option, qnn_runtime_load_method_graph_only (bool). When it is set, init passes QNN_CONTEXT_CONFIG_ENABLE_GRAPHS={method_name}, so only the loaded method's graph is deserialized from a multi-graph context binary.

  • Best effort: all graphs are loaded, without failing, when:
    • the binary holds a single graph, or doesn't contain the method's graph;
    • the payload is online-prepare (DLC);
    • the backend lacks QNN_PROPERTY_CONTEXT_SUPPORT_CONFIG_ENABLE_GRAPHS (also guarded at compile time).
  • Delegate cache: builds on the (signature, allocator) key from Isolate cached delegates by Module lifetime (#24462) #24462 by adding a graph name. A context holding every graph is stored with an empty name and serves every method of the Module. A method-only context is stored under its method's name and serves only that method. The existing refcounting and spill-fill groups are unchanged.
  • Fixes:
    • update_spill_fill_size with a list of programs only updated the last program's delegates.
    • The target QnnDlcManager::Destroy() now frees its logger before the backend implementation is released.
  • Runner (testing only):
    • --load_method_graph_only sets the option.
    • --preload_method_index loads another method, with its own planned memory but the main method's allocator, before the main one.
    • --destroy_preload_after_load keeps that method alive until the main one is loaded. This covers destroying a spill-fill group owner while a member is still alive, and destroying the method that created a shared cached delegate.

With weight sharing, each method loaded this way keeps its own copy of the shared weights, so the option only helps when one method is resident at a time.

Test results (QNN SDK 2.46.0, on device)

test_qnn_delegate.py (SM8850): 13/13 passed.

Test FP Quantized
test_qnn_backend_runtime_option_load_method_graph_only (new) pass pass
test_qnn_backend_runtime_option_load_method_graph_only_single_graph (new) pass pass
test_qnn_backend_runtime_option_load_method_graph_only_reload (new) pass –
test_qnn_backend_multi_graphs pass pass
test_qnn_backend_multi_contexts pass pass
test_qnn_backend_multi_contexts_composite pass pass
test_qnn_backend_spill_fill_buffer_size pass pass
  • ..._load_method_graph_only: only the selected graph is loaded.
  • ..._single_graph: falls back to the full context.
  • ..._reload, with multi-context and spill-fill, has four variants:
    • all graphs loaded, preload destroyed before graph_b loads (2 groups);
    • all graphs loaded, preload destroyed after graph_b hits the delegate cache (1 group, shared delegate outlives its creator);
    • method-only, group owner destroyed before graph_b loads (2 groups);
    • method-only, group owner destroyed while graph_b is alive (1 group).

Rework (tests/rework/htp/feature/v{81,79}/test.py -k "load_method_graph_only or multi_graph"): 3/3 passed with 6/6 subtests on both SM8850 and SM8750. The new test_load_method_graph_only runs the same multi-graph, single-graph, group-owner and shared-delegate cases as named subtests, and is skipped on x86.

QnnExecuTorchBackendTest (C++): 11/11 passed, including the new FullContextServesEveryMethod and MethodOnlyContextServesOnlyItsMethod.

lintrunner -a: no lint issues.

@quic-xiyushi
quic-xiyushi requested a review from psiddh as a code owner November 17, 2026 21:45
@pytorch-bot

pytorch-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 24 Awaiting Approval

As of commit 9681244 with merge base ef93dd8 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

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

@meta-cla

meta-cla Bot commented Nov 17, 2026

Copy link
Copy Markdown

Hi @quic-xiyushi!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@linux-foundation-easycla

linux-foundation-easycla Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: iftekhar-hc / name: iftekhar-hc (9681244)

@quic-xiyushi

Copy link
Copy Markdown
Contributor Author

@pytorchbot label "release notes: qualcomm"

@pytorch-bot pytorch-bot Bot added the release notes: qualcomm Changes to the Qualcomm backend delegate label Nov 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release notes: qualcomm Changes to the Qualcomm backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants