| 437 | } |
| 438 | |
| 439 | core::TensorValue build_conv_transpose1d( |
| 440 | core::ModuleBuildContext & ctx, |
| 441 | const core::TensorValue & input, |
| 442 | const WeightNormConvTranspose1dWeights & weights, |
| 443 | int64_t in_channels, |
| 444 | int64_t out_channels, |
| 445 | bool use_bias) { |
| 446 | const auto input_contiguous = ensure_f32(ctx, ensure_contiguous_nontransposed(ctx, input)); |
| 447 | const auto weight_contiguous = conv_transpose1d_weight(weights.conv.weight); |
| 448 | core::TensorValue bias_matrix; |
| 449 | if (use_bias) { |
| 450 | if (!weights.conv.bias.has_value()) { |
| 451 | throw std::runtime_error("ACE-Step VAE ConvTranspose1d requires bias"); |
| 452 | } |
| 453 | const auto bias = require_f32_weight(*weights.conv.bias, "ACE-Step VAE ConvTranspose1d bias"); |
| 454 | bias_matrix = core::reshape_tensor(ctx, bias, core::TensorShape::from_dims({out_channels, 1})); |
| 455 | } |
| 456 | core::TensorValue output; |
| 457 | for (int64_t batch_index = 0; batch_index < input.shape.dims[0]; ++batch_index) { |
| 458 | const auto batch_input = view_batch_matrix(ctx, input_contiguous, batch_index, in_channels, input.shape.dims[2]); |
| 459 | auto * batch_output = ggml_conv_transpose_1d( |
| 460 | ctx.ggml, |
| 461 | weight_contiguous.tensor, |
| 462 | batch_input.tensor, |
| 463 | weights.stride, |
| 464 | 0, |
| 465 | weights.dilation); |
| 466 | if (weights.padding != 0) { |
| 467 | const int64_t full_frames = batch_output->ne[0]; |
| 468 | const int64_t trimmed_frames = full_frames - 2 * weights.padding; |
| 469 | if (trimmed_frames <= 0) { |
| 470 | throw std::runtime_error("ACE-Step VAE transposed convolution trim produced non-positive frame count"); |
| 471 | } |
| 472 | batch_output = ggml_cont( |
| 473 | ctx.ggml, |
| 474 | ggml_view_2d( |
| 475 | ctx.ggml, |
| 476 | batch_output, |
| 477 | trimmed_frames, |
| 478 | out_channels, |
| 479 | batch_output->nb[1], |
| 480 | static_cast<size_t>(weights.padding) * batch_output->nb[0])); |
| 481 | } |
| 482 | if (use_bias) { |
| 483 | batch_output = ggml_add(ctx.ggml, batch_output, bias_matrix.tensor); |
| 484 | } |
| 485 | auto batch_value = core::wrap_tensor( |
| 486 | ggml_reshape_3d(ctx.ggml, batch_output, batch_output->ne[0], batch_output->ne[1], 1), |
| 487 | core::TensorShape::from_dims({1, out_channels, batch_output->ne[0]}), |
| 488 | GGML_TYPE_F32); |
| 489 | output = output.valid() ? modules::ConcatModule({0}).build(ctx, output, batch_value) : batch_value; |
| 490 | } |
| 491 | return output; |
| 492 | } |
| 493 | |
| 494 | core::TensorValue build_conv_transpose1d_col2im( |
| 495 | core::ModuleBuildContext & ctx, |
no test coverage detected