| 1912 | } |
| 1913 | |
| 1914 | bool bark_forward_coarse_encoder(struct bark_context* bctx, int n_threads) { |
| 1915 | const int64_t t_main_start_us = ggml_time_us(); |
| 1916 | |
| 1917 | auto& model = bctx->text_model.coarse_model; |
| 1918 | auto& allocr = bctx->allocr; |
| 1919 | auto& hparams = model.hparams; |
| 1920 | auto& verbosity = bctx->params.verbosity; |
| 1921 | |
| 1922 | // allocate the compute buffer |
| 1923 | { |
| 1924 | // alignment required by the backend |
| 1925 | size_t align = ggml_backend_get_alignment(model.backend); |
| 1926 | bctx->allocr = ggml_allocr_new_measure(align); |
| 1927 | |
| 1928 | // create the worst-case graph for memory usage estimation |
| 1929 | int n_past = 0; |
| 1930 | std::vector<bark_vocab::id> decoy_tokens(hparams.block_size, 0); |
| 1931 | struct ggml_cgraph* gf = bark_build_gpt_graph( |
| 1932 | &model, allocr, decoy_tokens, &n_past, false /* merge_ctx */, n_threads); |
| 1933 | |
| 1934 | // compute the required memory |
| 1935 | size_t mem_size = ggml_allocr_alloc_graph(bctx->allocr, gf); |
| 1936 | |
| 1937 | // recreate the allocator with the required memory |
| 1938 | ggml_allocr_free(bctx->allocr); |
| 1939 | bctx->buf_compute = ggml_backend_alloc_buffer(model.backend, mem_size); |
| 1940 | bctx->allocr = ggml_allocr_new_from_buffer(bctx->buf_compute); |
| 1941 | |
| 1942 | if (verbosity == bark_verbosity_level::MEDIUM || verbosity == bark_verbosity_level::HIGH) { |
| 1943 | fprintf(stderr, "%s: compute buffer size: %.2f MB\n\n", __func__, mem_size / 1024.0 / 1024.0); |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | if (!bark_eval_coarse_encoder(bctx, n_threads)) { |
| 1948 | fprintf(stderr, "%s: failed to forward coarse encoder\n", __func__); |
| 1949 | return false; |
| 1950 | } |
| 1951 | |
| 1952 | model.t_main_us = ggml_time_us() - t_main_start_us; |
| 1953 | bctx->stats.t_coarse_us = model.t_main_us; |
| 1954 | |
| 1955 | bark_print_statistics(&model); |
| 1956 | |
| 1957 | ggml_backend_buffer_free(bctx->buf_compute); |
| 1958 | ggml_allocr_free(bctx->allocr); |
| 1959 | |
| 1960 | return true; |
| 1961 | } |
| 1962 | |
| 1963 | static bool bark_eval_fine_encoder_internal( |
| 1964 | struct bark_context* bctx, |
no test coverage detected