Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions tools/server/server-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ struct server_slot {
// stats
size_t n_sent_text = 0; // number of sent text character

int64_t t_print_last = 0;
int64_t t_start_process_prompt;
int64_t t_start_generation;
int64_t t_print_last = 0;
int32_t n_decoded_last = 0;

double t_prompt_processing = 0.0; // ms
double t_token_generation = 0.0; // ms
Expand Down Expand Up @@ -467,11 +468,13 @@ struct server_slot {
return;
}

t_print_last = t_now;
const double n_gen_second = 1e3 / (t_token_generation) * (n_decoded);
const double n_gen_second_win = 1e6 / (t_now - t_print_last) * (n_decoded - n_decoded_last);

const double n_gen_second = 1e3 / t_token_generation * n_decoded;
t_print_last = t_now;
n_decoded_last = n_decoded;

SLT_INF(*this, "n_decoded = %6d, tg = %6.2f t/s\n", n_decoded, n_gen_second);
SLT_INF(*this, "n_decoded = %6d, tg = %6.2f t/s, tg_3s = %6.2f t/s\n", n_decoded, n_gen_second, n_gen_second_win);
}

void print_timings_pp() const {
Expand Down Expand Up @@ -2937,8 +2940,8 @@ struct server_context_impl {
}
}

const int64_t t_current = ggml_time_us();
slot.t_prompt_processing = (t_current - slot.t_start_process_prompt) / 1e3;
const int64_t t_now = ggml_time_us();
slot.t_prompt_processing = (t_now - slot.t_start_process_prompt) / 1e3;
slot.print_timings_pp();

// truncate any tokens that are beyond n_past for this slot
Expand Down Expand Up @@ -3391,17 +3394,19 @@ struct server_context_impl {
common_sampler_accept(slot.smpl.get(), id, true);

// here we have synchronized the llama_context (due to the sampling above), so we can do time measurement
const int64_t t_current = ggml_time_us();
const int64_t t_now = ggml_time_us();

slot.n_decoded += 1;

if (slot.n_decoded == 1) {
slot.t_start_generation = t_current;
slot.t_start_generation = t_now;
slot.t_print_last = t_now;
slot.n_decoded_last = 0;
slot.t_prompt_processing = (slot.t_start_generation - slot.t_start_process_prompt) / 1e3;
metrics.on_prompt_eval(slot);
}

slot.t_token_generation = std::max<int64_t>(1, t_current - slot.t_start_generation) / 1e3;
slot.t_token_generation = std::max<int64_t>(1, t_now - slot.t_start_generation) / 1e3;

completion_token_output result;
result.tok = id;
Expand Down Expand Up @@ -3495,11 +3500,11 @@ struct server_context_impl {
slot.spec_draft = std::move(accepted);
}

const int64_t t_current = ggml_time_us();
const int64_t t_now = ggml_time_us();

const auto ids = std::move(slot.spec_draft);

slot.t_token_generation = std::max<int64_t>(1, t_current - slot.t_start_generation) / 1e3;
slot.t_token_generation = std::max<int64_t>(1, t_now - slot.t_start_generation) / 1e3;

// update how many tokens out of those tested were accepted
slot.n_draft_accepted += ids.size() - 1;
Expand Down