Skip to content

Module API to execute with a single Tensor. #9706

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

Merged
merged 1 commit into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion extension/apple/ExecuTorch/Exported/ExecuTorchModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,21 @@ __attribute__((deprecated("This API is experimental.")))
error:(NSError **)error
NS_SWIFT_NAME(execute(_:_:));

/**
* Executes a specific method with the provided single input tensor.
*
* The method is loaded on demand if not already loaded.
*
* @param methodName A string representing the method name.
* @param tensor An ExecuTorchTensor object representing the input.
* @param error A pointer to an NSError pointer that is set if an error occurs.
* @return An NSArray of ExecuTorchValue objects representing the outputs, or nil in case of an error.
*/
- (nullable NSArray<ExecuTorchValue *> *)executeMethod:(NSString *)methodName
withTensor:(ExecuTorchTensor *)tensor
error:(NSError **)error
NS_SWIFT_NAME(execute(_:_:));

/**
* Executes the "forward" method with the provided input values.
*
Expand Down Expand Up @@ -210,7 +225,7 @@ __attribute__((deprecated("This API is experimental.")))
- (nullable NSArray<ExecuTorchValue *> *)forward:(NSError **)error;

/**
* Executes the "forward" method with no inputs.
* Executes the "forward" method with the provided input tensors.
*
* This is a convenience method that calls the executeMethod with "forward" as the method name.
*
Expand All @@ -222,6 +237,19 @@ __attribute__((deprecated("This API is experimental.")))
error:(NSError **)error
NS_SWIFT_NAME(forward(_:));

/**
* Executes the "forward" method with the provided single input tensor.
*
* This is a convenience method that calls the executeMethod with "forward" as the method name.
*
* @param tensor An ExecuTorchTensor object representing the input.
* @param error A pointer to an NSError pointer that is set if an error occurs.
* @return An NSArray of ExecuTorchValue objects representing the outputs, or nil in case of an error.
*/
- (nullable NSArray<ExecuTorchValue *> *)forwardWithTensor:(ExecuTorchTensor *)tensor
error:(NSError **)error
NS_SWIFT_NAME(forward(_:));

+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;

Expand Down
15 changes: 15 additions & 0 deletions extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ - (BOOL)isMethodLoaded:(NSString *)methodName {
error:error];
}

- (nullable NSArray<ExecuTorchValue *> *)executeMethod:(NSString *)methodName
withTensor:(ExecuTorchTensor *)tensor
error:(NSError **)error {
return [self executeMethod:methodName
withInputs:@[[ExecuTorchValue valueWithTensor:tensor]]
error:error];
}

- (nullable NSArray<ExecuTorchValue *> *)forwardWithInputs:(NSArray<ExecuTorchValue *> *)values
error:(NSError **)error {
return [self executeMethod:@"forward"
Expand Down Expand Up @@ -222,4 +230,11 @@ - (BOOL)isMethodLoaded:(NSString *)methodName {
error:error];
}

- (nullable NSArray<ExecuTorchValue *> *)forwardWithTensor:(ExecuTorchTensor *)tensor
error:(NSError **)error {
return [self executeMethod:@"forward"
withInputs:@[[ExecuTorchValue valueWithTensor:tensor]]
error:error];
}

@end
Loading