| 1773 | x = apply_bct_sequence_mask(ctx, x, *block_mask); |
| 1774 | } |
| 1775 | x = build_residual_unit(ctx, x, block.res2, channels, 3); |
| 1776 | if (block_mask != nullptr) { |
| 1777 | x = apply_bct_sequence_mask(ctx, x, *block_mask); |
| 1778 | } |
| 1779 | x = build_residual_unit(ctx, x, block.res3, channels, 9); |
| 1780 | if (block_mask != nullptr) { |
| 1781 | x = apply_bct_sequence_mask(ctx, x, *block_mask); |
| 1782 | } |
| 1783 | } |
| 1784 | x = build_snake1d_exact(ctx, x, weights.acoustic_decoder.snake, channels); |
| 1785 | return modules::Conv1dModule({channels, 1, 7, 1, 3, 1, true}) |
| 1786 | .build(ctx, x, make_conv1d_weights(ctx, weights.acoustic_decoder.conv2)); |
| 1787 | } |
| 1788 | |
| 1789 | core::TensorValue build_quantizer_decode_sequence( |
| 1790 | core::ModuleBuildContext & ctx, |
| 1791 | const std::vector<ggml_tensor *> & code_inputs, |
| 1792 | const HiggsAudioV2TokenizerWeights & weights, |
| 1793 | int64_t frames) { |
| 1794 | std::optional<core::TensorValue> latent; |
| 1795 | for (size_t quantizer_index = 0; quantizer_index < code_inputs.size(); ++quantizer_index) { |
| 1796 | const auto codes = core::wrap_tensor( |
| 1797 | code_inputs[quantizer_index], |
| 1798 | core::TensorShape::from_dims({1, frames}), |
| 1799 | GGML_TYPE_I32); |
| 1800 | auto embedded = modules::CodebookLookupModule({ |
| 1801 | static_cast<int64_t>(weights.quantizers[quantizer_index].codebook.shape.dims[0]), |
| 1802 | static_cast<int64_t>(weights.quantizers[quantizer_index].codebook.shape.dims[1]), |
| 1803 | }).build(ctx, codes, weights.quantizers[quantizer_index].codebook); |
| 1804 | auto projected = modules::LinearModule({ |
| 1805 | embedded.shape.dims[2], |
| 1806 | weights.quantizers[quantizer_index].project_out.weight.shape.dims[0], |
| 1807 | true, |
| 1808 | }).build(ctx, embedded, weights.quantizers[quantizer_index].project_out); |
| 1809 | auto projected_bct = transpose_btc_to_bct(ctx, projected); |
| 1810 | latent = latent.has_value() ? modules::AddModule().build(ctx, *latent, projected_bct) : projected_bct; |
| 1811 | } |
| 1812 | if (!latent.has_value()) { |
| 1813 | throw std::runtime_error("OmniVoice quantizer decode requires at least one codebook"); |
| 1814 | } |
| 1815 | return *latent; |
| 1816 | } |
| 1817 | |
| 1818 | struct HiggsAudioV2EncoderGraph { |
| 1819 | HiggsAudioV2EncoderGraph( |
| 1820 | std::shared_ptr<const OmniVoiceAssets> assets, |
| 1821 | std::shared_ptr<const HiggsAudioV2TokenizerWeights> weights, |
| 1822 | core::ExecutionContext & execution_context, |
| 1823 | size_t graph_arena_bytes, |
| 1824 | int64_t acoustic_samples, |
| 1825 | int64_t semantic_samples, |
| 1826 | int64_t frames) |
| 1827 | : assets_(std::move(assets)), |
| 1828 | weights_(std::move(weights)), |
| 1829 | backend_(execution_context.backend()), |
| 1830 | backend_type_(execution_context.backend_type()), |
| 1831 | compute_threads_(std::max(1, execution_context.config().threads)), |
| 1832 | acoustic_sample_capacity_(acoustic_samples), |
nothing calls this directly
no test coverage detected