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

Function bark_forward_fine_encoder

bark.cpp:2110–2159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2108}
2109
2110bool bark_forward_fine_encoder(struct bark_context* bctx, int n_threads) {
2111 const int64_t t_main_start_us = ggml_time_us();
2112
2113 auto& model = bctx->text_model.fine_model;
2114 auto& allocr = bctx->allocr;
2115 auto& hparams = model.hparams;
2116 auto& params = bctx->params;
2117 auto& verbosity = bctx->params.verbosity;
2118
2119 int32_t n_fine_codebooks = params.n_fine_codebooks;
2120
2121 // allocate the compute buffer
2122 {
2123 // alignment required by the backend
2124 size_t align = ggml_backend_get_alignment(model.backend);
2125 bctx->allocr = ggml_allocr_new_measure(align);
2126
2127 // create the worst-case graph for memory usage estimation
2128 std::vector<bark_vocab::id> decoy_tokens(hparams.block_size * n_fine_codebooks, 0);
2129 struct ggml_cgraph* gf = bark_build_fine_gpt_graph(
2130 &model, allocr, decoy_tokens, 2 /* codebook_idx */, n_fine_codebooks, n_threads);
2131
2132 // compute the required memory
2133 size_t mem_size = ggml_allocr_alloc_graph(bctx->allocr, gf);
2134
2135 // recreate the allocator with the required memory
2136 ggml_allocr_free(bctx->allocr);
2137 bctx->buf_compute = ggml_backend_alloc_buffer(model.backend, mem_size);
2138 bctx->allocr = ggml_allocr_new_from_buffer(bctx->buf_compute);
2139
2140 if (verbosity == bark_verbosity_level::MEDIUM || verbosity == bark_verbosity_level::HIGH) {
2141 fprintf(stderr, "%s: compute buffer size: %.2f MB\n\n", __func__, mem_size / 1024.0 / 1024.0);
2142 }
2143 }
2144
2145 if (!bark_eval_fine_encoder(bctx, n_threads)) {
2146 fprintf(stderr, "%s: failed to forward coarse encoder\n", __func__);
2147 return false;
2148 }
2149
2150 model.t_main_us = ggml_time_us() - t_main_start_us;
2151 bctx->stats.t_fine_us = model.t_main_us;
2152
2153 bark_print_statistics(&model);
2154
2155 ggml_backend_buffer_free(bctx->buf_compute);
2156 ggml_allocr_free(bctx->allocr);
2157
2158 return true;
2159}
2160
2161static bool bark_forward_eval(struct bark_context* bctx, int n_threads) {
2162 if (!bark_forward_text_encoder(bctx, n_threads)) {

Callers 1

bark_forward_evalFunction · 0.70

Calls 3

bark_eval_fine_encoderFunction · 0.70
bark_print_statisticsFunction · 0.70

Tested by

no test coverage detected