| 492 | } |
| 493 | |
| 494 | core::TensorValue build_conv_transpose1d_col2im( |
| 495 | core::ModuleBuildContext & ctx, |
| 496 | const core::TensorValue & input, |
| 497 | const WeightNormConvTranspose1dWeights & weights, |
| 498 | int64_t in_channels, |
| 499 | int64_t out_channels, |
| 500 | bool use_bias) { |
| 501 | const auto input_contiguous = ensure_f32(ctx, ensure_contiguous_nontransposed(ctx, input)); |
| 502 | const auto weight_contiguous = |
| 503 | require_contiguous_nontransposed_weight(weights.col_weight, "ACE-Step VAE ConvTranspose1d col2im weight"); |
| 504 | if (weight_contiguous.type != GGML_TYPE_F32) { |
| 505 | throw std::runtime_error("ACE-Step VAE ConvTranspose1d col2im requires uploaded F32 weights"); |
| 506 | } |
| 507 | core::TensorValue bias_matrix; |
| 508 | if (use_bias) { |
| 509 | if (!weights.conv.bias.has_value()) { |
| 510 | throw std::runtime_error("ACE-Step VAE ConvTranspose1d requires bias"); |
| 511 | } |
| 512 | const auto bias = require_f32_weight(*weights.conv.bias, "ACE-Step VAE ConvTranspose1d bias"); |
| 513 | bias_matrix = core::reshape_tensor(ctx, bias, core::TensorShape::from_dims({out_channels, 1})); |
| 514 | } |
| 515 | core::TensorValue output; |
| 516 | for (int64_t batch_index = 0; batch_index < input.shape.dims[0]; ++batch_index) { |
| 517 | const auto batch_input = view_batch_matrix(ctx, input_contiguous, batch_index, in_channels, input.shape.dims[2]); |
| 518 | auto * transposed_input = ggml_cont(ctx.ggml, ggml_transpose(ctx.ggml, batch_input.tensor)); |
| 519 | auto * columns = ggml_mul_mat(ctx.ggml, weight_contiguous.tensor, transposed_input); |
| 520 | auto * batch_output = ggml_col2im_1d( |
| 521 | ctx.ggml, |
| 522 | columns, |
| 523 | weights.stride, |
| 524 | static_cast<int>(out_channels), |
| 525 | weights.padding); |
| 526 | if (use_bias) { |
| 527 | batch_output = ggml_add(ctx.ggml, batch_output, bias_matrix.tensor); |
| 528 | } |
| 529 | auto batch_value = core::wrap_tensor( |
| 530 | ggml_reshape_3d(ctx.ggml, batch_output, batch_output->ne[0], batch_output->ne[1], 1), |
| 531 | core::TensorShape::from_dims({1, out_channels, batch_output->ne[0]}), |
| 532 | GGML_TYPE_F32); |
| 533 | output = output.valid() ? modules::ConcatModule({0}).build(ctx, output, batch_value) : batch_value; |
| 534 | } |
| 535 | return output; |
| 536 | } |
| 537 | |
| 538 | core::TensorValue build_residual_unit( |
| 539 | core::ModuleBuildContext & ctx, |
no test coverage detected