@@ -2302,12 +2302,7 @@ static struct ggml_cgraph * parakeet_build_graph_joint(
23022302 ggml_set_output (logits);
23032303 ggml_set_name (logits, " logits" );
23042304
2305- struct ggml_tensor * probs = ggml_soft_max (ctx0, logits);
2306- struct ggml_tensor * log_probs = ggml_log (ctx0, probs);
2307- ggml_set_output (log_probs);
2308- ggml_format_name (log_probs, " log_probs" );
2309-
2310- ggml_build_forward_expand (gf, log_probs);
2305+ ggml_build_forward_expand (gf, logits);
23112306
23122307 ggml_free (ctx0);
23132308
@@ -2473,19 +2468,25 @@ static parakeet_token_data create_token_data(
24732468 float token_logit,
24742469 int n_vocab_logits) {
24752470
2471+ float max_logit = token_logit;
2472+ for (int i = 0 ; i < n_vocab_logits; ++i) {
2473+ max_logit = std::max (max_logit, pstate.logits [i]);
2474+ }
2475+
24762476 float token_sum = 0 .0f ;
24772477 for (int i = 0 ; i < n_vocab_logits; ++i) {
2478- token_sum += expf (pstate.logits [i]);
2478+ token_sum += expf (pstate.logits [i] - max_logit );
24792479 }
2480- float token_p = expf (token_logit) / token_sum;
2480+
2481+ const float log_z = max_logit + logf (token_sum);
24812482
24822483 parakeet_token_data token_data;
24832484 token_data.id = token_id;
24842485 token_data.duration_idx = duration_idx;
24852486 token_data.duration_value = duration_value;
24862487 token_data.frame_index = frame_index;
2487- token_data.p = token_p ;
2488- token_data.plog = token_logit;
2488+ token_data.p = expf (token_logit - log_z) ;
2489+ token_data.plog = token_logit - log_z ;
24892490 token_data.t0 = frame_index * pctx.model .hparams .subsampling_factor ;
24902491 token_data.t1 = (frame_index + duration_value) * pctx.model .hparams .subsampling_factor ;
24912492 token_data.is_word_start = is_word_start_token (pctx.vocab , token_id);
@@ -2566,8 +2567,8 @@ static bool parakeet_decode(
25662567 // find the max index of the duration logits, and look up that index
25672568 // value in the tdt_durations array to get the actual duration value.
25682569 int best_duration_idx = 0 ;
2569- float best_duration_logit = -1e10f ;
2570- for (int i = 0 ; i < n_tdt_durations; ++i) {
2570+ float best_duration_logit = pstate. logits [n_vocab_logits] ;
2571+ for (int i = 1 ; i < n_tdt_durations; ++i) {
25712572 if (pstate.logits [n_vocab_logits + i] > best_duration_logit) {
25722573 best_duration_logit = pstate.logits [n_vocab_logits + i];
25732574 best_duration_idx = i;
0 commit comments