| 398 | } |
| 399 | |
| 400 | core::TensorValue build_conv1d( |
| 401 | core::ModuleBuildContext & ctx, |
| 402 | const core::TensorValue & input, |
| 403 | const WeightNormConv1dWeights & weights, |
| 404 | int64_t in_channels, |
| 405 | int64_t out_channels, |
| 406 | bool use_bias) { |
| 407 | const auto input_contiguous = ensure_f32(ctx, ensure_contiguous_nontransposed(ctx, input)); |
| 408 | const auto weight_contiguous = regular_conv_weight(weights.conv.weight, "ACE-Step VAE Conv1d"); |
| 409 | core::TensorValue bias_matrix; |
| 410 | if (use_bias) { |
| 411 | if (!weights.conv.bias.has_value()) { |
| 412 | throw std::runtime_error("ACE-Step VAE Conv1d requires bias"); |
| 413 | } |
| 414 | const auto bias = require_f32_weight(*weights.conv.bias, "ACE-Step VAE Conv1d bias"); |
| 415 | bias_matrix = core::reshape_tensor(ctx, bias, core::TensorShape::from_dims({out_channels, 1})); |
| 416 | } |
| 417 | core::TensorValue output; |
| 418 | for (int64_t batch_index = 0; batch_index < input.shape.dims[0]; ++batch_index) { |
| 419 | const auto batch_input = view_batch_matrix(ctx, input_contiguous, batch_index, in_channels, input.shape.dims[2]); |
| 420 | auto * batch_output = ggml_conv_1d( |
| 421 | ctx.ggml, |
| 422 | weight_contiguous.tensor, |
| 423 | batch_input.tensor, |
| 424 | weights.stride, |
| 425 | weights.padding, |
| 426 | weights.dilation); |
| 427 | if (use_bias) { |
| 428 | batch_output = ggml_add(ctx.ggml, batch_output, bias_matrix.tensor); |
| 429 | } |
| 430 | auto batch_value = core::wrap_tensor( |
| 431 | ggml_reshape_3d(ctx.ggml, batch_output, batch_output->ne[0], batch_output->ne[1], 1), |
| 432 | core::TensorShape::from_dims({1, out_channels, batch_output->ne[0]}), |
| 433 | GGML_TYPE_F32); |
| 434 | output = output.valid() ? modules::ConcatModule({0}).build(ctx, output, batch_value) : batch_value; |
| 435 | } |
| 436 | return output; |
| 437 | } |
| 438 | |
| 439 | core::TensorValue build_conv_transpose1d( |
| 440 | core::ModuleBuildContext & ctx, |
no test coverage detected