Skip to content

[7/N] Add sugar syntax for module.update #11534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: gh/cccclai/27/base
Choose a base branch
from

Conversation

cccclai
Copy link
Contributor

@cccclai cccclai commented Jun 10, 2025

Stack from ghstack (oldest at bottom):

The update API in method is supposed to be portable, but we can make it more user friendly for the update API in module. Add a bit sugar syntax in module to improve UX. Such that user can update backend option in module like following:

Module module(stub_model_path_);
int new_num_threads = 4;

const auto update_result = module.update("forward",
      {
        {"StubBackend", {{IntKey("NumberOfThreads"), new_num_threads}}
      },
  );

Differential Revision: D76242292

The update API in method is supposed to be portable, but we can make it more user friendly for the update API in module. Add a bit sugar syntax in module to improve UX. Such that user can update backend option in module like following:
```
Module module(stub_model_path_);
int new_num_threads = 4;

const auto update_result = module.update("forward",
      {
        {"StubBackend", {{IntKey("NumberOfThreads"), new_num_threads}}
      },
  );
```

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

[ghstack-poisoned]
Copy link

pytorch-bot bot commented Jun 10, 2025

🔗 Helpful Links

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

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

❌ 4 New Failures, 3 Unrelated Failures

As of commit 8b3d944 with merge base f7cc72f (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but was 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.

@facebook-github-bot facebook-github-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 Jun 10, 2025
cccclai added a commit that referenced this pull request Jun 10, 2025
The update API in method is supposed to be portable, but we can make it more user friendly for the update API in module. Add a bit sugar syntax in module to improve UX. Such that user can update backend option in module like following:
```
Module module(stub_model_path_);
int new_num_threads = 4;

const auto update_result = module.update("forward",
      {
        {"StubBackend", {{IntKey("NumberOfThreads"), new_num_threads}}
      },
  );
```

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

ghstack-source-id: 289276526
Pull Request resolved: #11534
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.

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D76242292

Comment on lines 4 to 7
#include <vector>
#include <string>
#include <initializer_list>
#include <executorch/runtime/backend/backend_options.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#include <vector>
#include <string>
#include <initializer_list>
#include <executorch/runtime/backend/backend_options.h>
#include <executorch/runtime/backend/backend_options.h>
#include <vector>
#include <string>
#include <initializer_list>

Comment on lines 17 to 18
#include <executorch/runtime/executor/program.h>
#include <executorch/extension/module/dynamic_backend_options_map.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#include <executorch/runtime/executor/program.h>
#include <executorch/extension/module/dynamic_backend_options_map.h>
#include <executorch/extension/module/dynamic_backend_options_map.h>
#include <executorch/runtime/executor/program.h>

@@ -483,6 +484,12 @@ class Module {
return update("forward", backend_options);
}

ET_EXPERIMENTAL ET_NODISCARD inline runtime::Error update(
Copy link
Contributor

@shoumikhin shoumikhin Jun 10, 2025

Choose a reason for hiding this comment

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

Any comments on what this API does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update the comments

namespace executorch {
namespace runtime {

class DynamicBackendOptionsMap {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we somehow use only standard containers for this map in order to skip this extra class? E.g. std::vector<std::pair<const char*, ArrayRef<BackendOption>>> or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's an option, not sure how simple it is compared with update API exposed in #11533 If that one is simple enough for users, we may not need to add this PR. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand this PR correctly, it just makes it easier for devs to use the other update() API so that they don't need to keep the backend options preallocated and pass refs to them, but employ standard containers to keep the memory alive?

What I propose here is to skip any custom classes to keep the backend options and just use the standard containers directly. Then inside this new convenient update() override do the due conversion and call the original update().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see, update the PR based on the suggestion

The update API in method is supposed to be portable, but we can make it more user friendly for the update API in module. Add a bit sugar syntax in module to improve UX. Such that user can update backend option in module like following:
```
Module module(stub_model_path_);
int new_num_threads = 4;

const auto update_result = module.update("forward",
      {
        {"StubBackend", {{IntKey("NumberOfThreads"), new_num_threads}}
      },
  );
```

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

[ghstack-poisoned]
cccclai added a commit that referenced this pull request Jun 12, 2025
Pull Request resolved: #11534

The update API in method is supposed to be portable, but we can make it more user friendly for the update API in module. Add a bit sugar syntax in module to improve UX. Such that user can update backend option in module like following:
```
Module module(stub_model_path_);
int new_num_threads = 4;

const auto update_result = module.update("forward",
      {
        {"StubBackend", {{IntKey("NumberOfThreads"), new_num_threads}}
      },
  );
```
ghstack-source-id: 290073340
@exported-using-ghexport

Differential Revision: [D76242292](https://our.internmc.facebook.com/intern/diff/D76242292/)
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D76242292

The update API in method is supposed to be portable, but we can make it more user friendly for the update API in module. Add a bit sugar syntax in module to improve UX. Such that user can update backend option in module like following:
```
Module module(stub_model_path_);
int new_num_threads = 4;

const auto update_result = module.update("forward",
      {
        {"StubBackend", {{IntKey("NumberOfThreads"), new_num_threads}}
      },
  );
```

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

[ghstack-poisoned]
cccclai added a commit that referenced this pull request Jun 13, 2025
Pull Request resolved: #11534

The update API in method is supposed to be portable, but we can make it more user friendly for the update API in module. Add a bit sugar syntax in module to improve UX. Such that user can update backend option in module like following:
```
Module module(stub_model_path_);
int new_num_threads = 4;

const auto update_result = module.update("forward",
      {
        {"StubBackend", {{IntKey("NumberOfThreads"), new_num_threads}}
      },
  );
```
ghstack-source-id: 290372285
@exported-using-ghexport

Differential Revision: [D76242292](https://our.internmc.facebook.com/intern/diff/D76242292/)
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D76242292

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants