File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed
extension/apple/ExecuTorch Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,14 @@ __attribute__((deprecated("This API is experimental.")))
187
187
*/
188
188
- (BOOL )isMethodLoaded:(NSString *)methodName NS_SWIFT_NAME (isLoaded(_:));
189
189
190
+ /* *
191
+ * Unloads a method and releases its native resources and planned buffers.
192
+ *
193
+ * @param methodName The method to unload.
194
+ * @return YES if the method was unloaded; NO if it was not loaded at all.
195
+ */
196
+ - (BOOL )unloadMethod:(NSString *)methodName NS_SWIFT_NAME (unload(_:));
197
+
190
198
/* *
191
199
* Retrieves the set of method names available in the loaded program.
192
200
*
Original file line number Diff line number Diff line change @@ -304,6 +304,13 @@ - (BOOL)isMethodLoaded:(NSString *)methodName {
304
304
return _module->is_method_loaded (methodName.UTF8String );
305
305
}
306
306
307
+ - (BOOL )unloadMethod : (NSString *)methodName {
308
+ const auto didUnload = _module->unload_method (methodName.UTF8String );
309
+ [_inputs removeObjectForKey: methodName];
310
+ [_outputs removeObjectForKey: methodName];
311
+ return didUnload;
312
+ }
313
+
307
314
- (nullable NSSet <NSString *> *)methodNames : (NSError **)error {
308
315
const auto result = _module->method_names ();
309
316
if (!result.ok ()) {
Original file line number Diff line number Diff line change @@ -171,4 +171,26 @@ class ModuleTest: XCTestCase {
171
171
172
172
XCTAssertThrowsError ( try module. setInputs ( Tensor < Float > ( [ 1 ] ) ) )
173
173
}
174
+
175
+ func testUnloadMethod( ) {
176
+ guard let modelPath = resourceBundle. path ( forResource: " add " , ofType: " pte " ) else {
177
+ XCTFail ( " Couldn't find the model file " )
178
+ return
179
+ }
180
+ let module = Module ( filePath: modelPath)
181
+ XCTAssertNoThrow ( try module. load ( " forward " ) )
182
+ XCTAssertTrue ( module. isLoaded ( " forward " ) )
183
+
184
+ XCTAssertNoThrow ( try module. setInputs ( Tensor < Float > ( [ 1 ] ) , Tensor < Float > ( [ 2 ] ) ) )
185
+ XCTAssertEqual ( try module. forward ( ) , Tensor < Float > ( [ 3 ] ) )
186
+
187
+ XCTAssertTrue ( module. unload ( " forward " ) )
188
+ XCTAssertFalse ( module. isLoaded ( " forward " ) )
189
+ XCTAssertFalse ( module. unload ( " forward " ) )
190
+
191
+ XCTAssertThrowsError ( try module. forward ( ) )
192
+ XCTAssertTrue ( module. isLoaded ( " forward " ) )
193
+ XCTAssertNoThrow ( try module. setInputs ( Tensor < Float > ( [ 2 ] ) , Tensor < Float > ( [ 3 ] ) ) )
194
+ XCTAssertEqual ( try module. forward ( ) , Tensor < Float > ( [ 5 ] ) )
195
+ }
174
196
}
You can’t perform that action at this time.
0 commit comments