Skip to content

Commit

Permalink
whisper : return ptr for whisper_get_timings
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Nov 10, 2024
1 parent b1cd3be commit 60238af
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ actor WhisperContext {
whisper_print_timings(context)

let system_info = self.system_info()
let timings: whisper_timings = whisper_get_timings(context)
let timings: whisper_timings = whisper_get_timings(context).pointee
let encode_ms = String(format: "%.2f", timings.encode_ms)
let decode_ms = String(format: "%.2f", timings.decode_ms)
let batchd_ms = String(format: "%.2f", timings.batchd_ms)
Expand Down
2 changes: 1 addition & 1 deletion include/whisper.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ extern "C" {
float batchd_ms;
float prompt_ms;
};
WHISPER_API struct whisper_timings whisper_get_timings(struct whisper_context * ctx);
WHISPER_API struct whisper_timings * whisper_get_timings(struct whisper_context * ctx);
WHISPER_API void whisper_print_timings(struct whisper_context * ctx);
WHISPER_API void whisper_reset_timings(struct whisper_context * ctx);

Expand Down
9 changes: 1 addition & 8 deletions scripts/bench-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@ else
fattn="-fa"
fi

models=( \
"tiny" "tiny-q4_0" "tiny-q4_1" "tiny-q5_0" "tiny-q5_1" "tiny-q8_0" \
"base" "base-q4_0" "base-q4_1" "base-q5_0" "base-q5_1" "base-q8_0" \
"small" "small-q4_0" "small-q4_1" "small-q5_0" "small-q5_1" "small-q8_0" \
"medium" "medium-q4_0" "medium-q4_1" "medium-q5_0" "medium-q5_1" "medium-q8_0" "medium-dis" \
"large-v2" "large-v2-q4_0" "large-v2-q4_1" "large-v2-q5_0" "large-v2-q5_1" "large-v2-q8_0" "large-v2-dis" \
"large-v3-turbo" "large-v3-turbo-q5_0" "large-v3-turbo-q8_0" \
)
models=("tiny")

if [ "$encoder_only" -eq 0 ]; then
printf "\n"
Expand Down
12 changes: 3 additions & 9 deletions src/whisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4186,22 +4186,16 @@ whisper_token whisper_token_transcribe(struct whisper_context * ctx) {
return ctx->vocab.token_transcribe;
}

struct whisper_timings whisper_get_timings(struct whisper_context * ctx) {
struct whisper_timings * whisper_get_timings(struct whisper_context * ctx) {
if (ctx->state == nullptr) {
return whisper_timings {
.sample_ms = 0,
.encode_ms = 0,
.decode_ms = 0,
.batchd_ms = 0,
.prompt_ms = 0,
};
return nullptr;
}
const int32_t n_sample = std::max(1, ctx->state->n_sample);
const int32_t n_encode = std::max(1, ctx->state->n_encode);
const int32_t n_decode = std::max(1, ctx->state->n_decode);
const int32_t n_batchd = std::max(1, ctx->state->n_batchd);
const int32_t n_prompt = std::max(1, ctx->state->n_prompt);
return whisper_timings {
return new whisper_timings {
.sample_ms = 1e-3f * ctx->state->t_sample_us / n_sample,
.encode_ms = 1e-3f * ctx->state->t_encode_us / n_encode,
.decode_ms = 1e-3f * ctx->state->t_decode_us / n_decode,
Expand Down

0 comments on commit 60238af

Please sign in to comment.