You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Android: Closeable lifecycle, error reporting, thread safety, and test coverage
Combines all previously reverted Android improvement PRs (#18669,
#19012, #19028, #19092, #19099, #19124) plus new Module lifecycle
tests into a single atomic change.
Error reporting: all sync errors throw exceptions instead of
returning status codes or logging silently. Module.loadMethod()
throws ExecutorchRuntimeException on failure. LlmModule.generate()
and load() throw on error. Native methods renamed with "Native"
suffix; public wrappers check status and throw.
Lifecycle: Module, LlmModule, and TrainingModule implement
Closeable for try-with-resources. LlmModule adds ReentrantLock
to serialize access to non-thread-safe native state. stop()
remains lock-free (C++ atomic flag). TrainingModule replaces
Log.e silent failures with IllegalStateException.
Error consistency: ExecuTorchRuntime.validateFilePath throws
IllegalArgumentException. SGD throws IllegalStateException.
AsrModule throws ExecutorchRuntimeException. Cause-chaining
constructor added to ExecutorchRuntimeException.
JNI safety: Module and LlmModule constructors wrapped in
try-catch to surface native initialization failures.
LlmModule.load() uses throwExecutorchException with diagnostic
detail. All @DoNotStrip annotations preserved on JNI-called
methods; new @DoNotStrip added to renamed private native methods
(generateNative, resetContextNative, loadNative).
Tests: fix 4 @ignored Module tests by providing required input
tensor. Add 13 new lifecycle/API coverage tests. Add LlmModule
use-after-close and idempotent-close tests. Fix ModelRunner crash
on loadMethod failure.
This PR was authored with the help of Claude.
Copy file name to clipboardExpand all lines: extension/android/executorch_android/src/androidTest/java/org/pytorch/executorch/LlmModuleInstrumentationTest.kt
+17-4Lines changed: 17 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -54,9 +54,7 @@ class LlmModuleInstrumentationTest : LlmCallback {
Copy file name to clipboardExpand all lines: extension/android/executorch_android/src/androidTest/java/org/pytorch/executorch/ModuleInstrumentationTest.kt
@@ -40,49 +39,49 @@ class ModuleInstrumentationTest {
40
39
inputStream.close()
41
40
}
42
41
43
-
@Ignore(
44
-
"The forward has failure that needs to be fixed before enabling this test: [Executorch Error 0x12] Invalid argument: Execution failed for method: forward "
val module =Module.load(getTestFilePath(TEST_FILE_NAME))
58
+
module.destroy()
59
59
}
60
60
61
-
@Ignore(
62
-
"The forward has failure that needs to be fixed before enabling this test: [Executorch Error 0x12] Invalid argument: Execution failed for method: forward "
63
-
)
64
61
@Test
65
62
@Throws(IOException::class)
66
63
funtestModuleLoadMethodAndForward() {
67
64
val module =Module.load(getTestFilePath(TEST_FILE_NAME))
"The forward has failure that needs to be fixed before enabling this test: [Executorch Error 0x12] Invalid argument: Execution failed for method: forward "
78
-
)
79
75
@Test
80
76
@Throws(IOException::class)
81
77
funtestModuleLoadForwardExplicit() {
82
78
val module =Module.load(getTestFilePath(TEST_FILE_NAME))
83
-
84
-
val results = module.execute(FORWARD_METHOD)
85
-
Assert.assertTrue(results[0].isTensor)
79
+
try {
80
+
val results = module.execute(FORWARD_METHOD, EValue.from(dummyInput()))
81
+
Assert.assertTrue(results[0].isTensor)
82
+
} finally {
83
+
module.destroy()
84
+
}
86
85
}
87
86
88
87
@Test(expected =RuntimeException::class)
@@ -95,18 +94,26 @@ class ModuleInstrumentationTest {
95
94
@Throws(IOException::class)
96
95
funtestModuleLoadMethodNonExistantMethod() {
97
96
val module =Module.load(getTestFilePath(TEST_FILE_NAME))
"The forward has failure that needs to be fixed before enabling this test: [Executorch Error 0x12] Invalid argument: Execution failed for method: forward "
0 commit comments