File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
extension/benchmark/android/benchmark/app
src/main/java/org/pytorch/minibench Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ dependencies {
39
39
implementation(" com.facebook.soloader:soloader:0.10.5" )
40
40
implementation(" com.facebook.fbjni:fbjni:0.5.1" )
41
41
implementation(" com.google.code.gson:gson:2.8.6" )
42
+ implementation(" org.json:json:20250107" )
42
43
testImplementation(" junit:junit:4.13.2" )
43
44
androidTestImplementation(" androidx.test.ext:junit:1.2.1" )
44
45
androidTestImplementation(" androidx.test.espresso:espresso-core:3.6.1" )
Original file line number Diff line number Diff line change 23
23
import java .util .List ;
24
24
import java .util .regex .Matcher ;
25
25
import java .util .regex .Pattern ;
26
+ import org .json .JSONException ;
27
+ import org .json .JSONObject ;
26
28
27
29
public class LlmBenchmarkActivity extends Activity implements ModelRunnerCallback {
28
30
ModelRunner mModelRunner ;
@@ -80,8 +82,17 @@ public void onTokenGenerated(String token) {}
80
82
81
83
@ Override
82
84
public void onStats (String result ) {
83
- // TODO: Add tps
84
- // mStatsInfo.tokens = stats;
85
+ float tps = 0 ;
86
+ try {
87
+ JSONObject jsonObject = new JSONObject (stats );
88
+ int numGeneratedTokens = jsonObject .getInt ("num_generated_tokens" );
89
+ int inferenceEndMs = jsonObject .getInt ("inference_end_ms" );
90
+ int promptEvalEndMs = jsonObject .getInt ("prompt_eval_end_ms" );
91
+ tps = (float ) numGeneratedTokens / (inferenceEndMs - promptEvalEndMs ) * 1000 ;
92
+ mStatsInfo .tokens = String .valueOf (tps );
93
+ } catch (JSONException e ) {
94
+ Log .e ("LLM" , "Error parsing JSON: " + e .getMessage ());
95
+ }
85
96
}
86
97
87
98
@ Override
You can’t perform that action at this time.
0 commit comments