Skip to content

Gate weights cache on runtime option instead of compile-time macro (#19603)#19603

Open
hboyraz wants to merge 2 commits into
pytorch:mainfrom
hboyraz:export-D105123995
Open

Gate weights cache on runtime option instead of compile-time macro (#19603)#19603
hboyraz wants to merge 2 commits into
pytorch:mainfrom
hboyraz:export-D105123995

Conversation

@hboyraz
Copy link
Copy Markdown

@hboyraz hboyraz commented May 14, 2026

Summary:

Replaces the compile-time #ifdef ENABLE_XNNPACK_WEIGHTS_CACHE gate in
XNNCompiler.cpp with a runtime boolean plumbed from
XnnpackBackendOptions::resolve_weight_cache(context) through
XNNPACKBackend::init to XNNCompiler::compileModel.

This fixes a silent-disable bug: previously, runtime opt-in via
set_option(weight_cache_option_key, true) was silently a no-op unless
the build also set -c executorch.xnnpack_weights_cache=1, because the
cache pointer handed to xnn_create_runtime_v4 was hardcoded to nullptr
when the macro was undefined. Multimethod LoRA models re-packed the entire backbone for every method load, costing
hundreds of MB of resident memory.

The runtime path now keys all three cache-relevant code regions
(unpacked-data load, cache pointer handoff to xnn_create_runtime_v4, and
finalize_for_runtime) on bool use_weight_cache resolved per-init from
the BackendInitContext.

The Result<vector<string>> declaration in compileModel was reshaped to
plain vector<string> since Result<> is non-assignable, which is
required for the new runtime branch.

Reviewed By: GregoryComer

Differential Revision: D105123995

@hboyraz hboyraz requested a review from digantdesai as a code owner May 14, 2026 19:23
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 14, 2026

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

⏳ No Failures, 138 Pending

As of commit 8601d3b with merge base 09a7cbe (image):
💚 Looks good so far! There are no failures yet. 💚

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 May 14, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented May 14, 2026

@hboyraz has exported this pull request. If you are a Meta employee, you can view the originating Diff in D105123995.

@github-actions
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.

@hboyraz
Copy link
Copy Markdown
Author

hboyraz commented May 14, 2026

@pytorchbot label "release notes: bug fix"

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 14, 2026

Didn't find following labels among repository labels: release notes: bug fix

@meta-codesync meta-codesync Bot changed the title Gate weights cache on runtime option instead of compile-time macro Gate weights cache on runtime option instead of compile-time macro (#19603) May 15, 2026
hboyraz pushed a commit to hboyraz/executorch that referenced this pull request May 15, 2026
…ytorch#19603)

Summary:

Replaces the compile-time `#ifdef ENABLE_XNNPACK_WEIGHTS_CACHE` gate in
XNNCompiler.cpp with a runtime boolean plumbed from
`XnnpackBackendOptions::resolve_weight_cache(context)` through
`XNNPACKBackend::init` to `XNNCompiler::compileModel`.

This fixes a silent-disable bug: previously, runtime opt-in via
`set_option(weight_cache_option_key, true)` was silently a no-op unless
the build also set `-c executorch.xnnpack_weights_cache=1`, because the
cache pointer handed to `xnn_create_runtime_v4` was hardcoded to nullptr
when the macro was undefined. Multimethod LoRA models re-packed the entire backbone for every method load, costing
hundreds of MB of resident memory.

The runtime path now keys all three cache-relevant code regions
(unpacked-data load, cache pointer handoff to xnn_create_runtime_v4, and
finalize_for_runtime) on `bool use_weight_cache` resolved per-init from
the BackendInitContext.

The `Result<vector<string>>` declaration in compileModel was reshaped to
plain `vector<string>` since `Result<>` is non-assignable, which is
required for the new runtime branch.

Reviewed By: GregoryComer

Differential Revision: D105123995
@hboyraz hboyraz force-pushed the export-D105123995 branch from e33c3f9 to fcbc108 Compare May 15, 2026 02:32
…ytorch#19603)

Summary:

Replaces the compile-time `#ifdef ENABLE_XNNPACK_WEIGHTS_CACHE` gate in
XNNCompiler.cpp with a runtime boolean plumbed from
`XnnpackBackendOptions::resolve_weight_cache(context)` through
`XNNPACKBackend::init` to `XNNCompiler::compileModel`.

This fixes a silent-disable bug: previously, runtime opt-in via
`set_option(weight_cache_option_key, true)` was silently a no-op unless
the build also set `-c executorch.xnnpack_weights_cache=1`, because the
cache pointer handed to `xnn_create_runtime_v4` was hardcoded to nullptr
when the macro was undefined. Multimethod LoRA models re-packed the entire backbone for every method load, costing
hundreds of MB of resident memory.

The runtime path now keys all three cache-relevant code regions
(unpacked-data load, cache pointer handoff to xnn_create_runtime_v4, and
finalize_for_runtime) on `bool use_weight_cache` resolved per-init from
the BackendInitContext.

The `Result<vector<string>>` declaration in compileModel was reshaped to
plain `vector<string>` since `Result<>` is non-assignable, which is
required for the new runtime branch.

Reviewed By: GregoryComer

Differential Revision: D105123995
@hboyraz hboyraz force-pushed the export-D105123995 branch from fcbc108 to bbf2b17 Compare May 15, 2026 02:33
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.

3 participants