| 306 | out.mlp.down_proj = binding::linear_data(constants, weights.down_proj); |
| 307 | return out; |
| 308 | } |
| 309 | |
| 310 | modules::CausalDecoderWeights make_qwen3_decoder_weights( |
| 311 | core::ConstantTensorCache & constants, |
| 312 | const std::vector<TalkerLayerWeights> & layers, |
| 313 | const assets::TensorDataF32 & norm, |
| 314 | const core::TensorValue & lm_head) { |
| 315 | modules::CausalDecoderWeights out; |
| 316 | out.stack.layers.reserve(layers.size()); |
| 317 | for (const auto & layer : layers) { |
| 318 | out.stack.layers.push_back(make_qwen3_decoder_layer_weights(constants, layer)); |
| 319 | } |
| 320 | out.final_norm = binding::norm_data(constants, norm); |
| 321 | out.lm_head = binding::linear_data(constants, lm_head); |
| 322 | return out; |
| 323 | } |
| 324 | |
| 325 | float silu(float value) { |
| 326 | return value / (1.0F + std::exp(-value)); |
| 327 | } |
| 328 | |
| 329 | std::vector<float> linear_host( |
| 330 | const std::vector<float> & input, |
| 331 | int64_t rows, |
| 332 | int64_t in_features, |
| 333 | const LinearTensorWeights & weights) { |
| 334 | if (weights.weight.shape.dims[0] <= 0 || weights.weight.shape.dims[1] != in_features) { |
| 335 | throw std::runtime_error("Qwen3 talker host linear weight shape mismatch"); |
| 336 | } |
| 337 | const int64_t out_features = weights.weight.shape.dims[0]; |
| 338 | const auto weight_values = assets::tensor_data_to_f32("Qwen3 talker host linear weight", weights.weight); |
| 339 | const auto bias_values = weights.bias.has_value() |
| 340 | ? assets::tensor_data_to_f32("Qwen3 talker host linear bias", *weights.bias) |
| 341 | : std::vector<float>{}; |
| 342 | std::vector<float> output(static_cast<size_t>(rows * out_features), 0.0F); |
| 343 | for (int64_t row = 0; row < rows; ++row) { |
| 344 | for (int64_t out = 0; out < out_features; ++out) { |
| 345 | float sum = weights.bias.has_value() ? bias_values[static_cast<size_t>(out)] : 0.0F; |
| 346 | for (int64_t in = 0; in < in_features; ++in) { |
| 347 | sum += weight_values[static_cast<size_t>(out * in_features + in)] * |
| 348 | input[static_cast<size_t>(row * in_features + in)]; |
| 349 | } |
| 350 | output[static_cast<size_t>(row * out_features + out)] = sum; |
| 351 | } |
| 352 | } |
| 353 | return output; |
| 354 | } |
| 355 | |
| 356 | class Qwen3TalkerTextProjectionGraph { |
| 357 | public: |
| 358 | Qwen3TalkerTextProjectionGraph(ggml_backend_t backend, int threads, |
| 359 | const Qwen3TalkerWeights & weights, |
| 360 | const Qwen3TTSTalkerConfig & config, bool bf16_activations) |
| 361 | : backend_(backend), threads_(threads), weights_(weights), config_(config), |
| 362 | constants_(backend, threads, "qwen3_tts.text_projection", 4ull * 1024 * 1024), |
| 363 | bf16_activations_(bf16_activations) {} |
| 364 | |
| 365 | std::vector<float> run(const std::vector<float> & input, int64_t rows) { |
no test coverage detected