Skip to content

QNN: construct partitioners from options and allocate LLM I/O in rpcmem - #24569

Draft
psiddh wants to merge 4 commits into
pytorch:mainfrom
psiddh:stack2/pr04-qnn-options-allocator
Draft

psiddh wants to merge 4 commits into
pytorch:mainfrom
psiddh:stack2/pr04-qnn-options-allocator

Conversation

@psiddh

@psiddh psiddh commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

QNN: construct partitioners from options and allocate LLM I/O in rpcmem

Exporters often have backend option dictionaries rather than ready-made compiler specs. QnnPartitioner.from_options() routes each setting to the correct compiler-spec builder or partitioner and rejects unknown names. The rpcmem allocator registers through the preceding PR's generic I/O-buffer hook, so LLM runner code remains independent of QNN.

Review order: QnnPartitioner.from_options, option-routing tests, llm/io_buffer_allocator.cpp, build / llama-main link wiring, then the allocator tests. The allocator forwards allocation alignment, binding and free calls; a failed allocation remains nullptr so the IOManager can use heap fallback.

This is PR 4 of the Stack 2 series. Its local parent is stack2/pr03-runner-contracts; its GitHub base is main, with earlier stack commits included. The QNN delegate output-order change is not in this PR; it follows separately for Qualcomm review.

Test Plan

On this PR's source tree:

python -m pytest -q backends/qualcomm/tests/test_partitioner_options.py
8 passed in 4.05s

python -m pytest -q backends/qualcomm/tests/test_passes.py \
  -k 'partitioner_carries or partitioner_runs or partitioner_from_options'
3 passed, 38 deselected in 4.42s

cmake -S backends/qualcomm/tests -B qnn-tests -DCMAKE_BUILD_TYPE=RelWithDebInfo \
  -DPYTHON_EXECUTABLE=$(command -v python)
cmake --build qnn-tests -j8 --target qnn_io_buffer_allocator_test
ctest --test-dir qnn-tests --output-on-failure
100% tests passed, 0 tests failed out of 2

QNN SDK 2.37 was used. HTP / GPU specs are checked; the LPAI test verifies the genuine >=2.39 SDK rejection rather than claiming LPAI compilation. Allocator tests compile the real allocator and stub only the rpcmem C APIs; hardware shared-memory registration was not rerun. The full host QNN build also compiled the allocator library. Buck parity could not start because the local dotslash wrapper requires a missing worktree .buck2; no Buck-green claim is made.

No external cache-memory-planning cherry-pick is included.

Stack (review in order)

  1. Partitioner: run backend-contributed edge transform passes #24566 Partitioner: run backend-contributed edge transform passes
  2. Export: avoid reused lifted-constant names #24567 Export: avoid reused lifted-constant names
  3. LLM runner: select I/O contracts and accept custom buffer allocators #24568 LLM runner: select I/O contracts and accept custom buffer allocators
  4. QNN: construct partitioners from options and allocate LLM I/O in rpcmem #24569 QNN: construct partitioners from options and allocate LLM I/O in rpcmem
  5. QNN: bind delegate outputs in exported program order #24570 QNN: bind delegate outputs in exported program order
  6. Export hf_static float-cache programs and register their Python runner #24571 Export hf_static float-cache programs and register their Python runner
  7. LLM runner: validate and drive hf_static float-cache programs #24572 LLM runner: validate and drive hf_static float-cache programs
  8. Document the version-1 hf_static I/O contract #24573 Document the version-1 hf_static I/O contract

Each PR includes the commits of the ones above it; review only its own top commits.

Run each partitioner’s edge transforms after caller-supplied passes so backends can use the standard lowering entry point. QNN contributes its existing transforms through the new hook.
Reserve names for constant tensors already present in the exported program before lifting new constants, so methods with folded tables retain distinct constants.
Choose the registered IOManager and its logits, method names and step sizes, rejecting unknown contracts and invalid metadata. Load and reset the selected methods; route prompt tails to decode with a side-effect-free capacity check. Preserve module and I/O-buffer lifetimes and expose a backend-neutral allocator hook.
Route backend options through QnnPartitioner.from_options and register an allocator that supplies QNN shared-memory buffers through the generic IOManager hook. The LLM runner remains backend-neutral.
@pytorch-bot

pytorch-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit df791aa with merge base 5f72739 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@github-actions

github-actions Bot commented Nov 3, 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.

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

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