| 2008 | } |
| 2009 | |
| 2010 | static bool bark_eval_fine_encoder(struct bark_context* bctx, int n_threads) { |
| 2011 | // input shape: [N, n_codes] |
| 2012 | bark_codes input = bctx->coarse_tokens; |
| 2013 | |
| 2014 | std::vector<float> logits; |
| 2015 | logits.resize(1024 * 1056); |
| 2016 | |
| 2017 | auto& model = bctx->text_model.fine_model; |
| 2018 | auto& hparams = model.hparams; |
| 2019 | auto& params = bctx->params; |
| 2020 | |
| 2021 | float temp = params.fine_temp; |
| 2022 | |
| 2023 | int32_t n_coarse_codebooks = params.n_coarse_codebooks; |
| 2024 | int32_t n_fine_codebooks = params.n_fine_codebooks; |
| 2025 | int32_t codebook_size = params.codebook_size; |
| 2026 | |
| 2027 | int n_coarse = input[0].size(); |
| 2028 | int original_seq_len = input.size(); |
| 2029 | int n_remove_from_end = 0; |
| 2030 | |
| 2031 | // channel padding |
| 2032 | for (int i = 0; i < (int)input.size(); i++) { |
| 2033 | for (int j = n_coarse_codebooks; j < n_fine_codebooks; j++) { |
| 2034 | input[i].push_back(codebook_size); |
| 2035 | } |
| 2036 | } |
| 2037 | |
| 2038 | // spatial padding if sequence is too short |
| 2039 | if (original_seq_len < 1024) { |
| 2040 | n_remove_from_end = 1024 - original_seq_len; |
| 2041 | for (int i = original_seq_len; i < 1024; i++) { |
| 2042 | bark_sequence _tmp(n_fine_codebooks, codebook_size); |
| 2043 | input.push_back(_tmp); |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | int n_loops = std::max(0, (int)ceilf((input.size() - 1024) / 512.f)) + 1; |
| 2048 | |
| 2049 | bark_codes in_arr = input; // [seq_length, n_codes] |
| 2050 | |
| 2051 | for (int n = 0; n < n_loops; n++) { |
| 2052 | int start_idx = std::min(n * 512, (int)in_arr.size() - 1024); |
| 2053 | int start_fill_idx = std::min(n * 512, (int)in_arr.size() - 512); |
| 2054 | int rel_start_fill_idx = start_fill_idx - start_idx; |
| 2055 | |
| 2056 | // in_buffer: [n_codes*seq_length] (sequences are contiguous) |
| 2057 | bark_sequence in_buffer; |
| 2058 | for (int i = 0; i < n_fine_codebooks; i++) { |
| 2059 | for (int j = start_idx; j < start_idx + 1024; j++) { |
| 2060 | in_buffer.push_back(in_arr[j][i]); |
| 2061 | } |
| 2062 | } |
| 2063 | |
| 2064 | for (int nn = n_coarse; nn < n_fine_codebooks; nn++) { |
| 2065 | if (params.progress_callback) { |
| 2066 | const int progress_cur = 100*(n*(n_fine_codebooks-n_coarse)+(nn-n_coarse+1))/(n_loops*(n_fine_codebooks-n_coarse)); |
| 2067 |
no test coverage detected