MCPcopy Create free account
hub / github.com/PABannier/bark.cpp / bark_forward_text_encoder

Function bark_forward_text_encoder

bark.cpp:1742–1789  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1740}
1741
1742bool bark_forward_text_encoder(struct bark_context* bctx, int n_threads) {
1743 const int64_t t_main_start_us = ggml_time_us();
1744
1745 auto& model = bctx->text_model.semantic_model;
1746 auto& allocr = bctx->allocr;
1747 auto& hparams = model.hparams;
1748 auto& verbosity = bctx->params.verbosity;
1749
1750 // allocate the compute buffer
1751 {
1752 // alignment required by the backend
1753 size_t align = ggml_backend_get_alignment(model.backend);
1754 bctx->allocr = ggml_allocr_new_measure(align);
1755
1756 // create the worst-case graph for memory usage estimation
1757 int n_past = 0;
1758 std::vector<bark_vocab::id> decoy_tokens(256 + 256 + 1, 0);
1759 struct ggml_cgraph* gf = bark_build_gpt_graph(
1760 &model, allocr, decoy_tokens, &n_past, true /* merge_ctx */, n_threads);
1761
1762 // compute the required memory
1763 size_t mem_size = ggml_allocr_alloc_graph(bctx->allocr, gf);
1764
1765 // recreate the allocator with the required memory
1766 ggml_allocr_free(bctx->allocr);
1767 bctx->buf_compute = ggml_backend_alloc_buffer(model.backend, mem_size);
1768 bctx->allocr = ggml_allocr_new_from_buffer(bctx->buf_compute);
1769
1770 if (verbosity == bark_verbosity_level::MEDIUM || verbosity == bark_verbosity_level::HIGH) {
1771 fprintf(stderr, "%s: compute buffer size: %.2f MB\n\n", __func__, mem_size / 1024.0 / 1024.0);
1772 }
1773 }
1774
1775 if (!bark_eval_text_encoder(bctx, n_threads)) {
1776 fprintf(stderr, "%s: failed to forward text encoder\n", __func__);
1777 return false;
1778 }
1779
1780 model.t_main_us = ggml_time_us() - t_main_start_us;
1781 bctx->stats.t_semantic_us = model.t_main_us;
1782
1783 bark_print_statistics(&model);
1784
1785 ggml_backend_buffer_free(bctx->buf_compute);
1786 ggml_allocr_free(bctx->allocr);
1787
1788 return true;
1789}
1790
1791static bool bark_eval_coarse_encoder(struct bark_context* bctx, int n_threads) {
1792 bark_codes out_coarse;

Callers 1

bark_forward_evalFunction · 0.70

Calls 3

bark_build_gpt_graphFunction · 0.70
bark_eval_text_encoderFunction · 0.70
bark_print_statisticsFunction · 0.70

Tested by

no test coverage detected