File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
executorch_android/src/main/java/org/pytorch/executorch/extension/llm Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -31,8 +31,22 @@ public interface LlmCallback {
31
31
/**
32
32
* Called when the statistics for the generate() is available.
33
33
*
34
+ * Note: This is a deprecated API and will be removed in the future. Please use onStats(String stats)
35
+ *
34
36
* @param tps Tokens/second for generated tokens.
35
37
*/
38
+ @ Deprecated
36
39
@ DoNotStrip
37
40
public void onStats (float tps );
41
+
42
+ /**
43
+ * Called when the statistics for the generate() is available.
44
+ *
45
+ * The result will be a JSON string. See extension/llm/stats.h for the field
46
+ * definitions.
47
+ *
48
+ * @param stats JSON string containing the statistics for the generate()
49
+ */
50
+ @ DoNotStrip
51
+ default public void onStats (String stats ) {}
38
52
}
Original file line number Diff line number Diff line change @@ -100,14 +100,20 @@ class ExecuTorchLlmCallbackJni
100
100
101
101
void onStats (const llm::Stats& result) const {
102
102
static auto cls = ExecuTorchLlmCallbackJni::javaClassStatic ();
103
- static const auto method = cls->getMethod <void (jfloat)>(" onStats" );
103
+ static const auto tps_method = cls->getMethod <void (jfloat)>(" onStats" );
104
104
double eval_time =
105
105
(double )(result.inference_end_ms - result.prompt_eval_end_ms );
106
106
107
107
float tps = result.num_generated_tokens / eval_time *
108
108
result.SCALING_FACTOR_UNITS_PER_SECOND ;
109
-
110
- method (self (), tps);
109
+ tps_method (self (), tps);
110
+
111
+ static const auto on_stats_method =
112
+ cls->getMethod <void (facebook::jni::local_ref<jstring>)>(" onStats" );
113
+ on_stats_method (
114
+ self (),
115
+ facebook::jni::make_jstring (
116
+ executorch::extension::llm::stats_to_json_string (result)));
111
117
}
112
118
};
113
119
You can’t perform that action at this time.
0 commit comments