| 1789 | } |
| 1790 | |
| 1791 | static bool bark_eval_coarse_encoder(struct bark_context* bctx, int n_threads) { |
| 1792 | bark_codes out_coarse; |
| 1793 | bark_sequence out; |
| 1794 | |
| 1795 | bark_sequence input = bctx->semantic_tokens; |
| 1796 | |
| 1797 | auto& model = bctx->text_model.coarse_model; |
| 1798 | auto& allocr = bctx->allocr; |
| 1799 | auto& hparams = model.hparams; |
| 1800 | auto& params = bctx->params; |
| 1801 | |
| 1802 | const int n_vocab = hparams.n_out_vocab; |
| 1803 | |
| 1804 | std::vector<float> logits; |
| 1805 | logits.resize(n_vocab); |
| 1806 | |
| 1807 | int max_coarse_history = params.max_coarse_history; |
| 1808 | int sliding_window_size = params.sliding_window_size; |
| 1809 | int n_coarse_codebooks = params.n_coarse_codebooks; |
| 1810 | int semantic_vocab_size = params.semantic_vocab_size; |
| 1811 | int codebook_size = params.codebook_size; |
| 1812 | |
| 1813 | float coarse_rate_hz = params.coarse_rate_hz; |
| 1814 | float semantic_rate_hz = params.semantic_rate_hz; |
| 1815 | |
| 1816 | int32_t coarse_semantic_pad_token = params.coarse_semantic_pad_token; |
| 1817 | int32_t coarse_infer_token = params.coarse_infer_token; |
| 1818 | |
| 1819 | float temp = params.temp; |
| 1820 | |
| 1821 | float stc_ratio = coarse_rate_hz / semantic_rate_hz * n_coarse_codebooks; |
| 1822 | |
| 1823 | int max_semantic_history = floorf(max_coarse_history / stc_ratio); |
| 1824 | |
| 1825 | int n_steps = floorf(input.size() * stc_ratio / n_coarse_codebooks) * n_coarse_codebooks; |
| 1826 | assert(n_steps > 0); |
| 1827 | assert(n_steps % n_coarse_codebooks == 0); |
| 1828 | |
| 1829 | int n_window_steps = ceilf(static_cast<float>(n_steps) / sliding_window_size); |
| 1830 | |
| 1831 | int step_idx = 0; |
| 1832 | |
| 1833 | for (int i = 0; i < n_window_steps; i++) { |
| 1834 | int semantic_idx = roundf(step_idx / stc_ratio); |
| 1835 | |
| 1836 | bark_sequence input_in( |
| 1837 | input.begin() + std::max(semantic_idx - max_semantic_history, 0), |
| 1838 | input.end()); |
| 1839 | |
| 1840 | size_t original_size = input_in.size(); |
| 1841 | input_in.resize(256); |
| 1842 | |
| 1843 | // padding from the right side |
| 1844 | for (int ix = original_size; ix < 256; ix++) { |
| 1845 | input_in[ix] = coarse_semantic_pad_token; |
| 1846 | } |
| 1847 | input_in.push_back(coarse_infer_token); |
| 1848 |
no test coverage detected