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

Function bark_eval_fine_encoder_internal

bark.cpp:1963–2008  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1961}
1962
1963static bool bark_eval_fine_encoder_internal(
1964 struct bark_context* bctx,
1965 bark_sequence& input,
1966 std::vector<float>& logits,
1967 int nn,
1968 int n_threads) {
1969 auto& model = bctx->text_model.fine_model;
1970 auto& allocr = bctx->allocr;
1971 auto& hparams = model.hparams;
1972 auto& params = bctx->params;
1973
1974 const int n_vocab = hparams.n_out_vocab;
1975 const int block_size = hparams.block_size;
1976
1977 const int n_fine_codebooks = params.n_fine_codebooks;
1978
1979 const int64_t t_predict_us_start = ggml_time_us();
1980
1981 // reset the allocator to free all the memory allocated during the previous inference
1982 ggml_allocr_reset(allocr);
1983
1984 struct ggml_cgraph* gf = bark_build_fine_gpt_graph(
1985 &model, allocr, input, nn, n_fine_codebooks, n_threads);
1986
1987 // allocate tensors
1988 ggml_allocr_alloc_graph(allocr, gf);
1989
1990 // run the computation
1991 if (ggml_backend_is_cpu(model.backend)) {
1992 ggml_backend_cpu_set_n_threads(model.backend, n_threads);
1993 }
1994#ifdef GGML_USE_METAL
1995 if (ggml_backend_is_metal(model.backend)) {
1996 ggml_backend_metal_set_n_cb(model.backend, n_threads);
1997 }
1998#endif
1999 ggml_backend_graph_compute(model.backend, gf);
2000
2001 struct ggml_tensor* inpL = gf->nodes[gf->n_nodes - 1];
2002
2003 ggml_backend_tensor_get(inpL, logits.data(), 0, sizeof(float) * n_vocab * block_size);
2004
2005 model.t_predict_us += ggml_time_us() - t_predict_us_start;
2006
2007 return true;
2008}
2009
2010static bool bark_eval_fine_encoder(struct bark_context* bctx, int n_threads) {
2011 // input shape: [N, n_codes]

Callers 1

bark_eval_fine_encoderFunction · 0.70

Calls 2

dataMethod · 0.80

Tested by

no test coverage detected