Skip to content

Commit d888c24

Browse files
committed
throw exception if native result is not OK
1 parent f975556 commit d888c24

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

extension/android/src/main/java/org/pytorch/executorch/LlamaModule.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,12 @@ public native int generate(
104104
* @param startPos The starting position in KV cache of the input in the LLM.
105105
* @return The updated starting position in KV cache of the input in the LLM.
106106
*/
107-
public long prefillImages(
108-
int[] image, int width, int height, int channels, long startPos) {
109-
return prefillImagesNative(image, width, height, channels, startPos)[1];
107+
public long prefillImages(int[] image, int width, int height, int channels, long startPos) {
108+
long[] nativeResult = prefillImagesNative(image, width, height, channels, startPos);
109+
if (nativeResult[0] != 0) {
110+
throw new RuntimeException("Prefill failed with error code: " + nativeResult[0]);
111+
}
112+
return nativeResult[1];
110113
}
111114

112115
// returns a tuple of (error code, updated startPos)
@@ -124,13 +127,15 @@ private native long[] prefillImagesNative(
124127
* @return The updated starting position in KV cache of the input in the LLM.
125128
*/
126129
public long prefillPrompt(String prompt, long startPos, int bos, int eos) {
127-
return prefillPromptNative(prompt, startPos, bos, eos)[2];
130+
long[] nativeResult = prefillPromptNative(prompt, startPos, bos, eos);
131+
if (nativeResult[0] != 0) {
132+
throw new RuntimeException("Prefill failed with error code: " + nativeResult[0]);
133+
}
134+
return nativeResult[2];
128135
}
129136

130-
131137
// returns a tuple of (error, token, updated startPos)
132-
private native long[] prefillPromptNative(
133-
String prompt, long startPos, int bos, int eos);
138+
private native long[] prefillPromptNative(String prompt, long startPos, int bos, int eos);
134139

135140
/**
136141
* Generate tokens from the given prompt, starting from the given position.

0 commit comments

Comments
 (0)