| 1627 | } |
| 1628 | |
| 1629 | static bool bark_eval_encoder_internal( |
| 1630 | gpt_model& model, |
| 1631 | ggml_allocr* allocr, |
| 1632 | bark_sequence& input, |
| 1633 | std::vector<float>& logits, |
| 1634 | int* n_past, |
| 1635 | bool merge_ctx, |
| 1636 | int n_threads) { |
| 1637 | auto& hparams = model.hparams; |
| 1638 | const int n_vocab = hparams.n_out_vocab; |
| 1639 | |
| 1640 | const int64_t t_predict_us_start = ggml_time_us(); |
| 1641 | |
| 1642 | // reset the allocator to free all the memory allocated during the previous inference |
| 1643 | ggml_allocr_reset(allocr); |
| 1644 | |
| 1645 | struct ggml_cgraph* gf = bark_build_gpt_graph( |
| 1646 | &model, allocr, input, n_past, merge_ctx, n_threads); |
| 1647 | |
| 1648 | // allocate tensors |
| 1649 | ggml_allocr_alloc_graph(allocr, gf); |
| 1650 | |
| 1651 | // run the computation |
| 1652 | if (ggml_backend_is_cpu(model.backend)) { |
| 1653 | ggml_backend_cpu_set_n_threads(model.backend, n_threads); |
| 1654 | } |
| 1655 | #ifdef GGML_USE_METAL |
| 1656 | if (ggml_backend_is_metal(model.backend)) { |
| 1657 | ggml_backend_metal_set_n_cb(model.backend, n_threads); |
| 1658 | } |
| 1659 | #endif |
| 1660 | ggml_backend_graph_compute(model.backend, gf); |
| 1661 | |
| 1662 | struct ggml_tensor* inpL = gf->nodes[gf->n_nodes - 1]; |
| 1663 | |
| 1664 | int N = input.size(); |
| 1665 | if (merge_ctx && *n_past == 0) { |
| 1666 | N -= 256; |
| 1667 | } |
| 1668 | |
| 1669 | logits.resize(n_vocab); |
| 1670 | ggml_backend_tensor_get(inpL, logits.data(), 0, sizeof(float) * n_vocab); |
| 1671 | |
| 1672 | // updating n_past with N (-256 if merge_ctx) |
| 1673 | if (n_past) { |
| 1674 | *n_past += N; |
| 1675 | } |
| 1676 | |
| 1677 | model.t_predict_us += ggml_time_us() - t_predict_us_start; |
| 1678 | |
| 1679 | return true; |
| 1680 | } |
| 1681 | |
| 1682 | static bool bark_eval_text_encoder(struct bark_context* bctx, int n_threads) { |
| 1683 | bark_sequence input = bctx->tokens; |
no test coverage detected