Skip to content

Commit a15ca74

Browse files
committed
speculative : print encoding speed
1 parent c82c808 commit a15ca74

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

examples/speculative/speculative.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,17 @@ int main(int argc, char ** argv) {
6767

6868
fflush(stderr);
6969

70+
const int n_input = inp.size();
71+
72+
const auto t_enc_start = ggml_time_us();
73+
7074
// eval the prompt with both models
7175
llama_eval(ctx_tgt, inp.data(), int(inp.size() - 1), 0, params.n_threads);
7276
llama_eval(ctx_tgt, &inp.back(), 1, inp.size() - 1, params.n_threads);
7377
llama_eval(ctx_dft, inp.data(), int(inp.size()), 0, params.n_threads);
7478

79+
const auto t_enc_end = ggml_time_us();
80+
7581
// the 2 models should have the same vocab
7682
const int n_ctx = llama_n_ctx(ctx_tgt);
7783
const int n_vocab = llama_n_vocab(ctx_tgt);
@@ -103,7 +109,7 @@ int main(int argc, char ** argv) {
103109
// used to determine end of generation
104110
bool has_eos = false;
105111

106-
const auto t_gen_start = ggml_time_us();
112+
const auto t_dec_start = ggml_time_us();
107113

108114
while (true) {
109115
LOG("drafted: %s\n", LOG_TOKENS_TOSTR_PRETTY(ctx_dft, drafted));
@@ -193,11 +199,12 @@ int main(int argc, char ** argv) {
193199
drafted.erase(drafted.begin());
194200
}
195201

196-
auto t_gen_end = ggml_time_us();
202+
auto t_dec_end = ggml_time_us();
197203

198204
LOG_TEE("\n\n");
199205

200-
LOG_TEE("generated %d tokens in %.3f seconds, speed: %.3f t/s\n", n_predict, (t_gen_end - t_gen_start) / 1e6f, n_predict / ((t_gen_end - t_gen_start) / 1e6f));
206+
LOG_TEE("encoded %4d tokens in %8.3f seconds, speed: %8.3f t/s\n", n_input, (t_enc_end - t_enc_start) / 1e6f, inp.size() / ((t_enc_end - t_enc_start) / 1e6f));
207+
LOG_TEE("decoded %4d tokens in %8.3f seconds, speed: %8.3f t/s\n", n_predict, (t_dec_end - t_dec_start) / 1e6f, n_predict / ((t_dec_end - t_dec_start) / 1e6f));
201208

202209
// TODO: make sure these numbers are computed correctly
203210
LOG_TEE("\n");

0 commit comments

Comments
 (0)