| 1680 | } |
| 1681 | |
| 1682 | static bool bark_eval_text_encoder(struct bark_context* bctx, int n_threads) { |
| 1683 | bark_sequence input = bctx->tokens; |
| 1684 | bark_sequence output; |
| 1685 | |
| 1686 | auto& params = bctx->params; |
| 1687 | |
| 1688 | int32_t n_steps_text_encoder = params.n_steps_text_encoder; |
| 1689 | int32_t semantic_vocab_size = params.semantic_vocab_size; |
| 1690 | int32_t semantic_pad_token = params.semantic_pad_token; |
| 1691 | |
| 1692 | auto& model = bctx->text_model.semantic_model; |
| 1693 | auto& allocr = bctx->allocr; |
| 1694 | auto& hparams = model.hparams; |
| 1695 | |
| 1696 | const int n_vocab = hparams.n_out_vocab; |
| 1697 | |
| 1698 | float min_eos_p = bctx->params.min_eos_p; |
| 1699 | float temp = bctx->params.temp; |
| 1700 | |
| 1701 | std::vector<float> logits; |
| 1702 | logits.resize(n_vocab); |
| 1703 | |
| 1704 | float eos_p = 0; |
| 1705 | int n_past = 0; |
| 1706 | |
| 1707 | for (int i = 0; i < n_steps_text_encoder; i++) { |
| 1708 | if (params.progress_callback) { |
| 1709 | const int progress_cur = 100*(i+1)/n_steps_text_encoder; |
| 1710 | |
| 1711 | params.progress_callback( |
| 1712 | bctx, bark_encoding_step::SEMANTIC, progress_cur, params.progress_callback_user_data); |
| 1713 | } |
| 1714 | |
| 1715 | if (!bark_eval_encoder_internal(model, allocr, input, logits, &n_past, true, n_threads)) { |
| 1716 | fprintf(stderr, "%s: Could not generate token\n", __func__); |
| 1717 | return false; |
| 1718 | } |
| 1719 | |
| 1720 | std::vector<float> relevant_logits(logits.begin(), logits.begin() + semantic_vocab_size); |
| 1721 | relevant_logits.push_back(logits[semantic_pad_token]); |
| 1722 | |
| 1723 | input.clear(); |
| 1724 | |
| 1725 | bark_token next = gpt_sample( |
| 1726 | logits, bctx->rng, temp, &eos_p, &model.t_sample_us, &model.n_sample); |
| 1727 | |
| 1728 | if (next == semantic_vocab_size || eos_p >= min_eos_p) { |
| 1729 | break; |
| 1730 | } |
| 1731 | |
| 1732 | input.push_back(next); |
| 1733 | output.push_back(next); |
| 1734 | } |
| 1735 | |
| 1736 | bctx->semantic_tokens = output; |
| 1737 | bctx->stats.n_sample_semantic = model.n_sample; |
| 1738 | |
| 1739 | return true; |
no test coverage detected