Skip to content

Commit 56355a4

Browse files
committed
Try again
1 parent e705e6c commit 56355a4

2 files changed

Lines changed: 39 additions & 15 deletions

File tree

llm/android/LlamaDemo/app/src/androidTest/java/com/example/executorchllamademo/E2E.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

llm/android/LlamaDemo/app/src/androidTest/java/com/example/executorchllamademo/PerfTest.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,49 @@
2929
public class PerfTest implements LlmCallback {
3030

3131
private static final String RESOURCE_PATH = "/data/local/tmp/llama/";
32-
private static final String TOKENIZER_BIN = "tokenizer.json";
32+
private static final String TOKENIZER_PATH = "tokenizer.json";
33+
private static final String MODEL_PATH = "model.pte";
3334

3435
private final List<String> results = new ArrayList<>();
3536
private final List<Float> tokensPerSecond = new ArrayList<>();
36-
@Test public void testSanity() {}
3737

38+
@Test
39+
public void testLoadAndGenerate() {
40+
String tokenizerPath = RESOURCE_PATH + TOKENIZER_PATH;
41+
// Find out the model name
42+
File model = new File(RESOURCE_PATH + MODEL_PATH);
43+
LlmModule mModule = new LlmModule(model.getPath(), tokenizerPath, 0.8f);
44+
// Print the model name because there might be more than one of them
45+
report("ModelName", model.getName());
46+
47+
int loadResult = mModule.load();
48+
// Check that the model can be load successfully
49+
assertEquals(0, loadResult);
50+
51+
// Run a testing prompt
52+
mModule.generate("How do you do! I'm testing llm on mobile device", PerfTest.this);
53+
}
54+
55+
@Test
56+
public void testTokensPerSecond() {
57+
String tokenizerPath = RESOURCE_PATH + TOKENIZER_PATH;
58+
// Find out the model name
59+
File model = new File(RESOURCE_PATH + MODEL_PATH);
60+
LlmModule mModule = new LlmModule(model.getPath(), tokenizerPath, 0.8f);
61+
// Print the model name because there might be more than one of them
62+
report("ModelName", model.getName());
63+
64+
int loadResult = mModule.load();
65+
// Check that the model can be load successfully
66+
assertEquals(0, loadResult);
67+
68+
// Run a testing prompt
69+
mModule.generate("How do you do! I'm testing llm on mobile device", PerfTest.this);
70+
assertFalse(tokensPerSecond.isEmpty());
71+
72+
final Float tps = tokensPerSecond.get(tokensPerSecond.size() - 1);
73+
report("TPS", tps);
74+
}
3875

3976
@Override
4077
public void onResult(String result) {

0 commit comments

Comments
 (0)