Skip to content

Conversation

@kimishpatel
Copy link
Contributor

@kimishpatel kimishpatel commented Nov 11, 2025

We observed that on iOS it improves perf by 6% because SDPA op does temp allocations.

No significant difference on android though.

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

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Nov 11, 2025

🔗 Helpful Links

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

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

❌ 122 New Failures

As of commit 5cecbfc with merge base 7600df8 (image):

NEW FAILURES - The following jobs have failed:

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

kimishpatel added a commit that referenced this pull request Nov 11, 2025
We observed that on iOS it improves perf by 6% because SDPA op does temp allocations.

No significant difference on android though.

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

ghstack-source-id: 322321964
Pull Request resolved: #15730
@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 Nov 11, 2025
@github-actions
Copy link

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.

We observed that on iOS it improves perf by 6% because SDPA op does temp allocations.

No significant difference on android though.

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

[ghstack-poisoned]
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 integrates a CPU caching allocator into the LLM runner to improve performance by reducing temporary memory allocation overhead during inference. According to the PR description, this change provides a 6% performance improvement on iOS for operations like SDPA that perform temporary allocations, though no significant difference was observed on Android.

Key changes:

  • Added CPUCachingAllocator as a temporary memory allocator for Module instances
  • Updated build system dependencies in targets.bzl, CMakeLists.txt files
  • Configured allocator with a 10MB cache size for temporary allocations

Reviewed Changes

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

File Description
extension/llm/runner/targets.bzl Added dependency on cpu_caching_allocator for Buck build system
extension/llm/runner/llm_runner_helper.cpp Instantiated CPUCachingAllocator with 10MB cache for Module temp allocations
extension/llm/runner/CMakeLists.txt Added extension_memory_allocator to runner dependencies for CMake
CMakeLists.txt Added memory_allocator subdirectory to build when LLM runner is enabled

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

endif()

if(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/memory_allocator/runner)
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

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

The path extension/memory_allocator/runner does not exist in the repository. The memory allocator CMakeLists.txt is located at extension/memory_allocator/CMakeLists.txt. This line should be:

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/memory_allocator)
Suggested change
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/memory_allocator/runner)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/memory_allocator)

Copilot uses AI. Check for mistakes.

// Create the Module
std::unique_ptr<Module> module;
uint32_t max_cached_memory_size_bytes_ = 1024 * 1024 * 10; // 10MB
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

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

The hardcoded value of 10MB for the caching allocator size should be documented or made configurable. According to the PR description, this improves performance by 6% on iOS for SDPA op temp allocations, but different models or use cases may benefit from different cache sizes. Consider:

  1. Adding a comment explaining why 10MB was chosen
  2. Making this value configurable through a parameter or constant
  3. Documenting the performance implications in code comments

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.

2 participants