Skip to content

Commit bd8d489

Browse files
committed
[Android] test for async invoke
Add testcase for async invoke with flexible tensor using llama.cpp. Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
1 parent 1250870 commit bd8d489

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

java/android/nnstreamer/src/androidTest/assets/README.txt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ $ tree .
77
│   ├── config_pipeline_imgclf.conf
88
│   ├── config_pipeline_imgclf_key.conf
99
│   ├── config_single_imgclf.conf
10-
│   └── config_single_imgclf_key.conf
10+
│   ├── config_single_imgclf_key.conf
11+
│   └── config_single_llamacpp_async.conf
12+
├── llamacpp_data
13+
│   └── tinyllama-1.1b-chat-v1.0.Q2_K.gguf
1114
├── pytorch_data
1215
│   ├── mobilenetv2-quant_core-nnapi.pt
1316
│   └── orange_float.raw
@@ -28,3 +31,23 @@ $ tree .
2831
├── orange.png
2932
├── orange.raw
3033
└── test_video.mp4
34+
35+
36+
Configuration example:
37+
The configuration file is a json formatted string for ML-service feature, which describes the configuration to run an inference application with model-agnostic method.
38+
If you implement new Android application with ML-service and need to get a model from application's internal storage, you can set the predefined entity string '@APP_DATA_PATH@'.
39+
Then it will be replaced with the application's data path.
40+
41+
Below is an example of asynchronous inference using LLaMA C++.
42+
43+
config_single_llamacpp_async.conf
44+
{
45+
"single" :
46+
{
47+
"framework" : "llamacpp",
48+
"model" : ["@APP_DATA_PATH@/nnstreamer/llamacpp_data/tinyllama-1.1b-chat-v1.0.Q2_K.gguf"],
49+
"custom" : "num_predict:32",
50+
"invoke_dynamic" : "true",
51+
"invoke_async" : "true"
52+
}
53+
}

java/android/nnstreamer/src/androidTest/java/org/nnsuite/nnstreamer/APITestMLService.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,4 +1025,55 @@ public void testRunSingleShotRegistered() {
10251025
MLService.Model.delete(name, 0);
10261026
}
10271027
}
1028+
1029+
@Test
1030+
public void testRunAsyncInvoke() {
1031+
if (!NNStreamer.isAvailable(NNStreamer.NNFWType.LLAMACPP)) {
1032+
/* cannot run the test */
1033+
return;
1034+
}
1035+
1036+
String config = APITestCommon.getConfigPath() + "/config_single_llamacpp_async.conf";
1037+
1038+
try {
1039+
MLService.EventListener asyncEventListener = new MLService.EventListener() {
1040+
@Override
1041+
public void onNewDataReceived(String name, TensorsData data) {
1042+
if (data == null || data.getTensorsCount() != 1) {
1043+
mInvalidState = true;
1044+
return;
1045+
}
1046+
1047+
mReceived++;
1048+
}
1049+
};
1050+
1051+
MLService service = new MLService(config, asyncEventListener);
1052+
1053+
service.start();
1054+
1055+
/* push input buffer */
1056+
String inputText = "Hello my name is";
1057+
ByteBuffer buffer = TensorsData.allocateByteBuffer(inputText);
1058+
1059+
TensorsInfo info = service.getInputInformation(null);
1060+
assertEquals(NNStreamer.TensorFormat.FLEXIBLE, info.getFormat());
1061+
1062+
TensorsData input = TensorsData.allocate(info);
1063+
input.setTensorData(0, buffer);
1064+
1065+
service.inputData(null, input);
1066+
1067+
/* sleep 3 seconds to invoke */
1068+
Thread.sleep(3000);
1069+
1070+
/* check received data from output node */
1071+
assertFalse(mInvalidState);
1072+
assertTrue(mReceived > 1);
1073+
1074+
service.close();
1075+
} catch (Exception e) {
1076+
fail();
1077+
}
1078+
}
10281079
}

0 commit comments

Comments
 (0)