File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
extension/android/executorch_android
src/androidTest/java/org/pytorch/executorch Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ dependencies {
47
47
androidTestImplementation ' androidx.test.ext:junit:1.1.5'
48
48
androidTestImplementation ' androidx.test:rules:1.2.0'
49
49
androidTestImplementation ' commons-io:commons-io:2.4'
50
+ androidTestImplementation ' org.json:json:20250107'
50
51
}
51
52
52
53
import com.vanniktech.maven.publish.SonatypeHost
Original file line number Diff line number Diff line change 34
34
import org .apache .commons .io .FileUtils ;
35
35
import androidx .test .ext .junit .runners .AndroidJUnit4 ;
36
36
import androidx .test .InstrumentationRegistry ;
37
+ import org .json .JSONException ;
38
+ import org .json .JSONObject ;
37
39
import org .pytorch .executorch .extension .llm .LlmCallback ;
38
40
import org .pytorch .executorch .extension .llm .LlmModule ;
39
41
@@ -94,9 +96,17 @@ public void onResult(String result) {
94
96
}
95
97
96
98
@ Override
97
- public void onStats (String result ) {
98
- // TODO: Calculate tps
99
- // LlmModuleInstrumentationTest.this.onStats(tps);
99
+ public void onStats (String stats ) {
100
+ float tps = 0 ;
101
+ try {
102
+ JSONObject jsonObject = new JSONObject (stats );
103
+ int numGeneratedTokens = jsonObject .getInt ("generated_tokens" );
104
+ int inferenceEndMs = jsonObject .getInt ("inference_end_ms" );
105
+ int promptEvalEndMs = jsonObject .getInt ("prompt_eval_end_ms" );
106
+ tps = (float ) numGeneratedTokens / (inferenceEndMs - promptEvalEndMs ) * 1000 ;
107
+ LlmModuleInstrumentationTest .this .onStats (tps );
108
+ } catch (JSONException e ) {
109
+ }
100
110
}
101
111
});
102
112
You can’t perform that action at this time.
0 commit comments