Skip to content

Commit

Permalink
Add a tok/sec field to the response
Browse files Browse the repository at this point in the history
  • Loading branch information
EricLBuehler committed Mar 6, 2024
1 parent 5a40e09 commit 40b38d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mistralrs-core/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ impl Engine {
},
};

let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time travel has occurred!")
.as_secs();
#[allow(clippy::cast_precision_loss)]
let tok_per_sec = deref_refcell!(seq).len() as f32
/ (now - deref_refcell!(seq).timestamp()) as f32;

// NOTE(EricLBuehler): Unwrap reasoning: The receiver should really be there, otherwise it is their fault.
deref_refcell!(seq)
.responder()
Expand All @@ -167,6 +175,7 @@ impl Engine {
completion_tokens: deref_refcell!(seq).logprobs().len(),
prompt_tokens: deref_refcell!(seq).prompt_tokens(),
total_tokens: deref_refcell!(seq).len(),
tok_per_sec,
},
}))
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions mistralrs-core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct ChatCompletionUsage {
pub completion_tokens: usize,
pub prompt_tokens: usize,
pub total_tokens: usize,
pub tok_per_sec: f32,
}

#[derive(Debug, Clone, Serialize)]
Expand Down

0 comments on commit 40b38d7

Please sign in to comment.