| 1729 | state_->decoder_backend = {}; |
| 1730 | } |
| 1731 | |
| 1732 | std::shared_ptr<const S3FlowEncoderWeights> load_s3_flow_encoder_weights( |
| 1733 | const engine::assets::TensorSource & source, |
| 1734 | const engine::core::ExecutionContext & execution_context, |
| 1735 | engine::assets::TensorStorageType weight_storage_type) { |
| 1736 | auto weights = std::make_shared<S3FlowEncoderWeights>(); |
| 1737 | weights->execution_context = &execution_context; |
| 1738 | weights->store = std::make_shared<engine::core::BackendWeightStore>( |
| 1739 | execution_context.backend(), |
| 1740 | execution_context.backend_type(), |
| 1741 | "chatterbox.s3_flow_encoder.weights", |
| 1742 | 1024ull * 1024ull * 1024ull); |
| 1743 | weights->input_embedding_tensor = weights->store->load_tensor( |
| 1744 | source, |
| 1745 | "flow.input_embedding.weight", |
| 1746 | weight_storage_type, |
| 1747 | {6561, 512}); |
| 1748 | weights->speaker_affine = load_flow_linear(*weights->store, source, "flow.spk_embed_affine_layer", 80, 192, true, weight_storage_type); |
| 1749 | weights->encoder_proj = load_flow_linear(*weights->store, source, "flow.encoder_proj", 80, 512, true, weight_storage_type); |
| 1750 | weights->embed_linear = load_flow_linear(*weights->store, source, "flow.encoder.embed.out.0", 512, 512, true, weight_storage_type); |
| 1751 | weights->embed_norm = load_flow_layer_norm(*weights->store, source, "flow.encoder.embed.out.1", 512); |
| 1752 | weights->prelook_conv1 = |
| 1753 | load_flow_conv1d(*weights->store, source, "flow.encoder.pre_lookahead_layer.conv1", 512, 512, 4, 1, 0, weight_storage_type); |
| 1754 | weights->prelook_conv2 = |
| 1755 | load_flow_conv1d(*weights->store, source, "flow.encoder.pre_lookahead_layer.conv2", 512, 512, 3, 1, 0, weight_storage_type); |
| 1756 | auto load_layer = [&](const std::string & prefix) { |
| 1757 | S3FlowEncoderWeights::EncoderLayerWeights layer; |
| 1758 | layer.norm_mha = load_flow_layer_norm(*weights->store, source, prefix + ".norm_mha", 512); |
| 1759 | layer.attn.q = load_flow_linear(*weights->store, source, prefix + ".self_attn.linear_q", 512, 512, true, weight_storage_type); |
| 1760 | layer.attn.k = load_flow_linear(*weights->store, source, prefix + ".self_attn.linear_k", 512, 512, true, weight_storage_type); |
| 1761 | layer.attn.v = load_flow_linear(*weights->store, source, prefix + ".self_attn.linear_v", 512, 512, true, weight_storage_type); |
| 1762 | layer.attn.out = load_flow_linear(*weights->store, source, prefix + ".self_attn.linear_out", 512, 512, true, weight_storage_type); |
| 1763 | layer.attn.pos = load_flow_linear(*weights->store, source, prefix + ".self_attn.linear_pos", 512, 512, false, weight_storage_type); |
| 1764 | layer.attn.pos_bias_u_tensor = weights->store->load_f32_tensor(source, prefix + ".self_attn.pos_bias_u", {8, 64}); |
| 1765 | layer.attn.pos_bias_v_tensor = weights->store->load_f32_tensor(source, prefix + ".self_attn.pos_bias_v", {8, 64}); |
| 1766 | layer.norm_ff = load_flow_layer_norm(*weights->store, source, prefix + ".norm_ff", 512); |
| 1767 | layer.ff.w1 = load_flow_linear(*weights->store, source, prefix + ".feed_forward.w_1", 2048, 512, true, weight_storage_type); |
| 1768 | layer.ff.w2 = load_flow_linear(*weights->store, source, prefix + ".feed_forward.w_2", 512, 2048, true, weight_storage_type); |
| 1769 | return layer; |
| 1770 | }; |
| 1771 | for (int i = 0; i < 6; ++i) { |
| 1772 | weights->encoders.push_back(load_layer("flow.encoder.encoders." + std::to_string(i))); |
| 1773 | } |
| 1774 | weights->up_layer_conv = load_flow_conv1d(*weights->store, source, "flow.encoder.up_layer.conv", 512, 512, 5, 1, 0, weight_storage_type); |
| 1775 | weights->up_embed_linear = load_flow_linear(*weights->store, source, "flow.encoder.up_embed.out.0", 512, 512, true, weight_storage_type); |
| 1776 | weights->up_embed_norm = load_flow_layer_norm(*weights->store, source, "flow.encoder.up_embed.out.1", 512); |
| 1777 | for (int i = 0; i < 4; ++i) { |
| 1778 | weights->up_encoders.push_back(load_layer("flow.encoder.up_encoders." + std::to_string(i))); |
| 1779 | } |
| 1780 | weights->after_norm = load_flow_layer_norm(*weights->store, source, "flow.encoder.after_norm", 512); |
| 1781 | weights->store->upload(); |
| 1782 | return weights; |
| 1783 | } |
| 1784 | |
| 1785 | S3FlowEncoderOutputs compute_s3_flow_encoder_forward( |
| 1786 | S3FlowSessionCache & cache, |
no test coverage detected