| 420 | storage_type, |
| 421 | out_channels, |
| 422 | config.res_kernel_size)); |
| 423 | } |
| 424 | weights.blocks.push_back(std::move(block)); |
| 425 | in_channels = out_channels; |
| 426 | } |
| 427 | const int64_t post_index = 1 + static_cast<int64_t>(config.upsample_factors.size()); |
| 428 | weights.post_processor.conv = binding::conv1d_from_source( |
| 429 | store, |
| 430 | source, |
| 431 | "scalar_model.decoder." + std::to_string(post_index) + ".conv", |
| 432 | storage_type, |
| 433 | config.init_channel, |
| 434 | config.init_channel, |
| 435 | config.default_kernel_size, |
| 436 | true); |
| 437 | weights.post_processor.activation = |
| 438 | load_prelu(store, source, "scalar_model.decoder." + std::to_string(post_index) + ".activation"); |
| 439 | weights.output_conv = load_weight_norm_conv1d( |
| 440 | store, |
| 441 | source, |
| 442 | "scalar_model.decoder." + std::to_string(post_index + 1), |
| 443 | storage_type, |
| 444 | config.num_bands, |
| 445 | config.init_channel, |
| 446 | config.default_kernel_size); |
| 447 | return weights; |
| 448 | } |
| 449 | |
| 450 | core::TensorValue scale(core::ModuleBuildContext & ctx, const core::TensorValue & input, float value) { |
| 451 | return core::wrap_tensor(ggml_scale(ctx.ggml, core::ensure_backend_addressable_layout(ctx, input).tensor, value), input.shape, GGML_TYPE_F32); |
| 452 | } |
| 453 | |
| 454 | core::TensorValue add_one(core::ModuleBuildContext & ctx, const core::TensorValue & input) { |
| 455 | return core::wrap_tensor(ggml_scale_bias(ctx.ggml, core::ensure_backend_addressable_layout(ctx, input).tensor, 1.0F, 1.0F), input.shape, GGML_TYPE_F32); |
| 456 | } |
| 457 | |
| 458 | core::TensorValue quantize_scalar_latent(core::ModuleBuildContext & ctx, const core::TensorValue & input) { |
| 459 | auto scaled = scale(ctx, input, 9.0F); |
| 460 | auto rounded = core::wrap_tensor(ggml_round(ctx.ggml, core::ensure_backend_addressable_layout(ctx, scaled).tensor), scaled.shape, GGML_TYPE_F32); |
| 461 | return scale(ctx, rounded, 1.0F / 9.0F); |
| 462 | } |
| 463 | |
| 464 | core::TensorValue causal_left_pad_bct( |
| 465 | core::ModuleBuildContext & ctx, |
| 466 | const core::TensorValue & input, |
| 467 | int64_t left_pad) { |
| 468 | if (left_pad == 0) { |
| 469 | return input; |
| 470 | } |
| 471 | auto * padded = ggml_pad_ext( |
| 472 | ctx.ggml, |
| 473 | core::ensure_backend_addressable_layout(ctx, input).tensor, |
| 474 | static_cast<int>(left_pad), |
| 475 | 0, |
| 476 | 0, |
| 477 | 0, |
| 478 | 0, |
| 479 | 0, |
no test coverage detected