MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / build_conv1d

Function build_conv1d

src/models/ace_step/vae_decoder.cpp:400–437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

398}
399
400core::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
439core::TensorValue build_conv_transpose1d(
440 core::ModuleBuildContext & ctx,

Callers 4

build_residual_unitFunction · 0.85
buildMethod · 0.85
build_encoder_blockFunction · 0.85
buildMethod · 0.85

Calls 13

require_f32_weightFunction · 0.85
reshape_tensorFunction · 0.85
ggml_conv_1dFunction · 0.85
ggml_addFunction · 0.85
wrap_tensorFunction · 0.85
ggml_reshape_3dFunction · 0.85
ConcatModuleClass · 0.85
validMethod · 0.80
ensure_f32Function · 0.70
regular_conv_weightFunction · 0.70
view_batch_matrixFunction · 0.70

Tested by

no test coverage detected