Skip to content

[wip] Support multimethod in export_llama_lib#17231

Open
lucylq wants to merge 2 commits intogh/lucylq/134/basefrom
gh/lucylq/134/head
Open

[wip] Support multimethod in export_llama_lib#17231
lucylq wants to merge 2 commits intogh/lucylq/134/basefrom
gh/lucylq/134/head

Conversation

@lucylq
Copy link
Contributor

@lucylq lucylq commented Feb 5, 2026

TODO: add CI test.

Differential Revision: [D92315602](https://our.internmc.facebook.com/intern/diff/D92315602/)

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Feb 5, 2026

🔗 Helpful Links

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

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

❌ 3 New Failures, 4 Unrelated Failures

As of commit 1de0598 with merge base eac0673 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

lucylq pushed a commit that referenced this pull request Feb 5, 2026
TODO: add CI test.

Differential Revision: [D92315602](https://our.internmc.facebook.com/intern/diff/D92315602/)

ghstack-source-id: 338339885
Pull Request resolved: #17231
@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 Feb 5, 2026
@github-actions
Copy link

github-actions bot commented Feb 5, 2026

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.

@lucylq lucylq changed the title Support multimethod in export_llama_lib [wip] Support multimethod in export_llama_lib Feb 5, 2026
TODO: add CI test.

Differential Revision: [D92315602](https://our.internmc.facebook.com/intern/diff/D92315602/)

[ghstack-poisoned]
lucylq pushed a commit that referenced this pull request Feb 5, 2026
Pull Request resolved: #17231

TODO: add CI test.

Note: multimethod export is currently limited to:
- xnnpack or portable lib
- only lora (does not support arbitrary nn.Modules in each method)
- if quant is enabled, lora models must share quant schemes at source transformation time
- no pt2e quant, as each model could have slightly different results after calibration

ghstack-source-id: 338339885
@exported-using-ghexport

Differential Revision: [D92315602](https://our.internmc.facebook.com/intern/diff/D92315602/)
@lucylq lucylq requested a review from Copilot February 5, 2026 19:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds multimethod export support to the Llama export library, enabling the export of multiple methods (base model and LoRA variants) into a single .pte file. This is part of a stack of PRs (#17228-#17231) that collectively add multimethod and LoRA support to the ExecuTorch runtime.

Changes:

  • Added _export_llama_multimethod() function to handle exporting multiple methods to a single .pte file
  • Added helper functions _get_xnnpack_partitioners() and _get_output_filename() to support multimethod export
  • Added validation logic to ensure multimethod export only works with XNNPACK backend or portable ops
  • Added configuration file for Qwen3 multimethod export with LoRA
  • Added comprehensive test script for validating multimethod export functionality
  • Updated build dependencies to include required tokenizer and weight conversion modules

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
examples/models/llama/export_llama_lib.py Core implementation of multimethod export logic, including validation, helper functions, and the main export function
examples/models/qwen3/config/qwen3_multimethod.yaml Configuration file demonstrating multimethod export with LoRA and base methods using environment variable interpolation
examples/models/llama/BUCK Added convert_weights.py to export library sources for proper dependency resolution
examples/models/llama/runner/targets.bzl Added regex_lookahead tokenizer dependency for enhanced tokenizer support
.ci/scripts/test_lora_multimethod.sh Comprehensive test script validating both LoRA and base method execution with expected output verification

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +867 to +868
"Multimethod export only supports XNNPACK backend or portable ops"
"Please disable other backends (coreml, vulkan, qnn, mps, openvino)."
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Missing period between sentences in error message. Should be: "Multimethod export only supports XNNPACK backend or portable ops. Please disable other backends..."

Suggested change
"Multimethod export only supports XNNPACK backend or portable ops"
"Please disable other backends (coreml, vulkan, qnn, mps, openvino)."
"Multimethod export only supports XNNPACK backend or portable ops."
" Please disable other backends (coreml, vulkan, qnn, mps, openvino)."

Copilot uses AI. Check for mistakes.
return builder


def _get_xnnpack_partitioners(llm_config: LlmConfig) -> Optional[List]:
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Return type annotation is too generic. The function returns either a list of partitioners or None, so the type should be Optional[List[Partitioner]] instead of Optional[List]. This would provide better type safety and match the usage pattern where partitioners are passed to to_edge_transform_and_lower.

Copilot uses AI. Check for mistakes.
method_to_program,
partitioner=partitioners,
compile_config=edge_config,
constant_methods=first_builder.metadata,
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The generate_etrecord configuration option is not being passed to the to_edge_transform_and_lower call. This means that ETRecord generation will not work with multimethod export even if llm_config.debug.generate_etrecord is set to True. Add generate_etrecord=llm_config.debug.generate_etrecord, to the function call.

Suggested change
constant_methods=first_builder.metadata,
constant_methods=first_builder.metadata,
generate_etrecord=llm_config.debug.generate_etrecord,

Copilot uses AI. Check for mistakes.
}

# Download LoRA adapter.
python -m pip install -q huggingface_hub
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

This script installs the huggingface_hub package directly from PyPI at runtime without any version pinning or integrity verification, which introduces a supply-chain risk: if the package (or the index it is fetched from) is compromised, arbitrary code could execute in the CI environment with access to repository data and any configured secrets. To reduce this risk, pin huggingface_hub to a known-good version (e.g., via a requirements/constraints file) and, where possible, enable hash-based verification or use a vetted internal package mirror instead of an unpinned direct install.

Copilot uses AI. Check for mistakes.
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. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant