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 {
3939 implementation(" com.facebook.soloader:soloader:0.10.5" )
4040 implementation(" com.facebook.fbjni:fbjni:0.5.1" )
4141 implementation(" com.google.code.gson:gson:2.8.6" )
42+ implementation(" org.json:json:20250107" )
4243 testImplementation(" junit:junit:4.13.2" )
4344 androidTestImplementation(" androidx.test.ext:junit:1.2.1" )
4445 androidTestImplementation(" androidx.test.espresso:espresso-core:3.6.1" )
Original file line number Diff line number Diff line change 2323import java .util .List ;
2424import java .util .regex .Matcher ;
2525import java .util .regex .Pattern ;
26+ import org .json .JSONException ;
27+ import org .json .JSONObject ;
2628
2729public class LlmBenchmarkActivity extends Activity implements ModelRunnerCallback {
2830 ModelRunner mModelRunner ;
@@ -80,8 +82,17 @@ public void onTokenGenerated(String token) {}
8082
8183 @ Override
8284 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+ }
8596 }
8697
8798 @ Override
You can’t perform that action at this time.
0 commit comments