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

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