-
Notifications
You must be signed in to change notification settings - Fork 539
Native Objective‑C/Swift Wrapper for the ExecuTorch Module #8363
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
Labels
module: ios
Issues related to iOS code, build, and execution
module: user experience
Issues related to reducing friction for users
triaged
This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Comments
facebook-github-bot
pushed a commit
that referenced
this issue
Mar 27, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71915597
facebook-github-bot
pushed a commit
that referenced
this issue
Mar 27, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71916550
Merged
kirklandsign
added a commit
that referenced
this issue
Mar 27, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71916550 Co-authored-by: Anthony Shoumikhin <[email protected]>
facebook-github-bot
pushed a commit
that referenced
this issue
Mar 27, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71917236
kirklandsign
added a commit
that referenced
this issue
Mar 27, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71917236 Co-authored-by: Anthony Shoumikhin <[email protected]>
facebook-github-bot
pushed a commit
that referenced
this issue
Mar 27, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71918193
kirklandsign
added a commit
that referenced
this issue
Mar 27, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71918193 Co-authored-by: Anthony Shoumikhin <[email protected]>
facebook-github-bot
pushed a commit
that referenced
this issue
Mar 27, 2025
Summary: #8363 Reviewed By: bsoyluoglu Differential Revision: D71919658
kirklandsign
added a commit
that referenced
this issue
Mar 27, 2025
Summary: #8363 Reviewed By: bsoyluoglu Differential Revision: D71919658 Co-authored-by: Anthony Shoumikhin <[email protected]>
facebook-github-bot
pushed a commit
that referenced
this issue
Mar 27, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71921054
kirklandsign
added a commit
that referenced
this issue
Mar 27, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71921054 Co-authored-by: Anthony Shoumikhin <[email protected]>
facebook-github-bot
pushed a commit
that referenced
this issue
Mar 27, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71924237
kirklandsign
added a commit
that referenced
this issue
Mar 27, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71924237 Co-authored-by: Anthony Shoumikhin <[email protected]>
facebook-github-bot
pushed a commit
that referenced
this issue
Mar 27, 2025
Summary: #8363 Reviewed By: bsoyluoglu Differential Revision: D71936820
kirklandsign
added a commit
that referenced
this issue
Mar 27, 2025
Summary: #8363 Reviewed By: bsoyluoglu Differential Revision: D71936820 Co-authored-by: Anthony Shoumikhin <[email protected]>
This was referenced Mar 27, 2025
kirklandsign
added a commit
that referenced
this issue
Apr 11, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71916550 Co-authored-by: Anthony Shoumikhin <[email protected]>
kirklandsign
added a commit
that referenced
this issue
Apr 11, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71917236 Co-authored-by: Anthony Shoumikhin <[email protected]>
kirklandsign
added a commit
that referenced
this issue
Apr 11, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71918193 Co-authored-by: Anthony Shoumikhin <[email protected]>
kirklandsign
added a commit
that referenced
this issue
Apr 11, 2025
Summary: #8363 Reviewed By: bsoyluoglu Differential Revision: D71919658 Co-authored-by: Anthony Shoumikhin <[email protected]>
kirklandsign
added a commit
that referenced
this issue
Apr 11, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71921054 Co-authored-by: Anthony Shoumikhin <[email protected]>
kirklandsign
added a commit
that referenced
this issue
Apr 11, 2025
Summary: #8363 Reviewed By: mergennachin Differential Revision: D71924237 Co-authored-by: Anthony Shoumikhin <[email protected]>
kirklandsign
added a commit
that referenced
this issue
Apr 11, 2025
Summary: #8363 Reviewed By: bsoyluoglu Differential Revision: D71936820 Co-authored-by: Anthony Shoumikhin <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
module: ios
Issues related to iOS code, build, and execution
module: user experience
Issues related to reducing friction for users
triaged
This issue has been looked at a team member, and triaged and prioritized into an appropriate module
🚀 The feature, motivation and pitch
Introduce a native Objective‑C wrapper (
ExecuTorchModule
) for the C++ Module class, enabling model loading, execution, and basic input/output management from Objective‑C and Swift. In Swift, the wrapper appears asModule
thanks toNS_SWIFT_NAME
annotations.Alternatives
See the parent issue #8360 for motivation and alternatives overview.
Additional context
Some capabilities from the underlying C++ Module are intentionally omitted in this initial wrapper to keep the minimal API subset. For example:
Method Metadata (e.g.
method_meta
)Per‑Method Event Tracer
Custom Memory Allocators
These advanced features require additional wrap classes or more granular control that is not yet part of this proposal. We may add them in future iterations if there is demand.
Usage Examples:
Objective‑C:
Swift (auto‑bridged):
Conversions between
NSArray
ofExecuTorchValue
andstd::vector<EValue>
are implemented with minimal overhead. All bridging logic resides in the wrapper, so user code remains concise.RFC (Optional)
Internal Representation
The wrapper keeps a unique pointer to the native
Module
. Methods like-load:
and-executeMethod:withInputs:error:
directly call corresponding C++ functions (_module->load()
,_module->execute()
) and convert results or error codes into Objective‑C types.Key Methods:
Constructs a
Module
from a file path and an optional load mode (file vs. mmap, etc.).Objective-C
Swift:
Invokes corresponding
Module
methods, e.g._module->load();
and returnsYES
on success, and on failure populates error.Objective-C
Swift:
Converts input
ExecuTorchValues
to C++EValues
, calls_module->execute(methodName, inputs)
, and wraps outputs back into Objective‑C objects.Objective-C
Swift:
Convenience variations for calling the “forward” method.
Objective-C
Swift:
For advanced usage, allows specifying input/output
EValues
on a per‑index basis (e.g._module->set_input(...)
).Objective-C
Swift:
Error Handling & Reporting:
::executorch::runtime::Error
are mapped toNSError
instances (using domainExecuTorchErrorDomain
).Example of a method throwing an error:
To achieve the minimal overhead during value conversions, Module can use something like the following helper functions internally:
cc @mergennachin @byjlw
The text was updated successfully, but these errors were encountered: