Skip to content

Conversation

cccclai
Copy link
Contributor

@cccclai cccclai commented Jun 10, 2025

Stack from ghstack (oldest at bottom):

  • Expose the update API in module. Inside the module. invoke the method. Update API
  • Did a bit refactor for the StubBackend test code, such that it can shared between backend_interface_update_test.cpp and module_test.cpp

Differential Revision: D76172680

- Expose the update API in module. Inside the module. invoke the method. Update API
- Did a bit refactor for the `StubBackend` test code, such that it can shared between `backend_interface_update_test.cpp` and `module_test.cpp`

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

[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/11533

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

❌ 27 New Failures, 2 Unrelated Failures

As of commit f0c47a6 with merge base f7cc72f (image):

NEW FAILURES - The following jobs have failed:

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.

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: D76172680

- Expose the update API in module. Inside the module. invoke the method. Update API
- Did a bit refactor for the `StubBackend` test code, such that it can shared between `backend_interface_update_test.cpp` and `module_test.cpp`

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

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

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

Comment on lines +312 to +319
runtime::Error Module::update(
const std::string& method_name,
runtime::ArrayRef<runtime::Entry> backend_options) {
ET_CHECK_OK_OR_RETURN_ERROR(load_method(method_name));
auto& method = methods_.at(method_name).method;
return method->update(backend_options);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

This is exactly my problem. none of the piping being done here is module or method name specific. Because the options being sent down are to the global singleton of backend. It would make sense only if we have a way to set options on an instance of the backend class that is tied to a given method and model.

Also I apologize if this was already discussed in review. It has been a while so likely I forgot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we want to provide backend flexibility to decide whether it's global or per session. There is one single instance of the backend class. It is a singleton and processes all the .pte files (including all methods) even from different processes. We want the backend to have the option as needed.

Additionally, currently users don't interact with backend directly, Users just load the .pte file, construct the method. ET runtime is responsible for passing the information between user and the backends.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want to provide backend flexibility to decide whether it's global or per session.

I think these would need to be different apis. Otherwise it seems like a huge nightmare for users to reason about what options are local state and what are global. Its not also that easy to debug since ET allows closed source delegates.

Additionally, currently users don't interact with backend directly, Users just load the .pte file, construct the method.

Yeah but since the current backend api is primarily driven towards setting global state, I think it would be more natural for there to be some ET global api for them to call.

Also as an aside these options sort of feel similar to contextGuards in regular torch like inference mode. Maybe we should explore that as an api option here (not sure how portable it is especially since wed want them to be thread local.

- Expose the update API in module. Inside the module. invoke the method. Update API
- Did a bit refactor for the `StubBackend` test code, such that it can shared between `backend_interface_update_test.cpp` and `module_test.cpp`

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

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

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

kedarnath03 pushed a commit to kedarnath03/executorch that referenced this pull request Jun 25, 2025
Pull Request resolved: pytorch/executorch#11533

- Expose the update API in module. Inside the module. invoke the method. Update API
- Did a bit refactor for the `StubBackend` test code, such that it can shared between `backend_interface_update_test.cpp` and `module_test.cpp`
ghstack-source-id: 290372284
@exported-using-ghexport

Differential Revision: [D76172680](https://our.internmc.facebook.com/intern/diff/D76172680/)
*/
ET_EXPERIMENTAL ET_NODISCARD runtime::Error update(
const std::string& method_name,
runtime::ArrayRef<runtime::Entry> backend_options);
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think we should expose arrayref options in Module. You should just skip to the syntactic sugar vector/map version you have in the next PR.

Unrelated to this PR but similar motivations to why I dont want ArrayRef here. I think its probably a mistake we used EValue in module. I wish we had a different type like extension/OwningEValue or something that let us include Dict and List for unflattened IO and let us have stronger ownership semantics on module IO cc @shoumikhin

Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly Im not sure its valuable to have module return Error vs throwing exception

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.

4 participants