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

Method build

src/models/ace_step/vae_encoder.cpp:242–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240}
241
242void AceStepVAEEncodeGraph::build(size_t graph_arena_bytes) {
243 const auto & config = assets_->config.vae;
244 ggml_init_params params{graph_arena_bytes, nullptr, true};
245 ctx_.reset(ggml_init(params));
246 if (ctx_ == nullptr) {
247 throw std::runtime_error("ACE-Step VAE encoder ggml context initialization failed");
248 }
249 core::ModuleBuildContext ctx{ctx_.get(), "ace_step.vae_encoder", backend_type_};
250
251 input_value_ = core::make_tensor(
252 ctx,
253 GGML_TYPE_F32,
254 core::TensorShape::from_dims({1, config.audio_channels, audio_frames_}));
255 ggml_set_input(input_value_.tensor);
256
257 auto hidden = build_conv1d(
258 ctx,
259 input_value_,
260 weights_->encoder_conv1,
261 config.audio_channels,
262 config.decoder_channels,
263 true);
264 for (size_t i = 0; i < weights_->encoder_blocks.size(); ++i) {
265 const auto & block = weights_->encoder_blocks[i];
266 const int64_t in_channels = hidden.shape.dims[1];
267 const int64_t out_channels = block.conv.conv.weight.shape.dims[0];
268 hidden = build_encoder_block(ctx, hidden, block, in_channels, out_channels);
269 }
270 hidden = build_snake1d_exact_bct(
271 ctx,
272 hidden,
273 weights_->encoder_snake_out,
274 hidden.shape.dims[1]);
275 hidden = build_conv1d(
276 ctx,
277 hidden,
278 weights_->encoder_conv2,
279 hidden.shape.dims[1],
280 config.encoder_hidden_size,
281 true);
282 output_value_ = hidden;
283 latent_frames_ = output_value_.shape.dims[2];
284 if (output_value_.shape.dims[1] % 2 != 0) {
285 throw std::runtime_error("ACE-Step VAE encoder output channels must split into mean/scale pairs");
286 }
287 latent_channels_ = output_value_.shape.dims[1] / 2;
288 ggml_set_output(output_value_.tensor);
289 graph_ = ggml_new_graph_custom(ctx_.get(), 131072, false);
290 ggml_build_forward_expand(graph_, output_value_.tensor);
291 gallocr_ = ggml_gallocr_new(ggml_backend_get_default_buffer_type(backend_));
292 if (gallocr_ == nullptr || !ggml_gallocr_alloc_graph(gallocr_, graph_)) {
293 throw std::runtime_error("ACE-Step VAE encoder backend buffer allocation failed");
294 }
295}
296
297AceStepVAEEncoderRuntimeCore::AceStepVAEEncoderRuntimeCore(
298 std::shared_ptr<const AceStepAssets> assets,

Callers 15

glu_channelsFunction · 0.45
build_feed_forwardFunction · 0.45
build_dconvFunction · 0.45
build_dconv_freqFunction · 0.45

Calls 15

ggml_initFunction · 0.85
make_tensorFunction · 0.85
ggml_set_inputFunction · 0.85
build_conv1dFunction · 0.85
build_encoder_blockFunction · 0.85
build_snake1d_exact_bctFunction · 0.85
ggml_set_outputFunction · 0.85
ggml_new_graph_customFunction · 0.85
ggml_gallocr_newFunction · 0.85
ggml_gallocr_alloc_graphFunction · 0.85

Tested by

no test coverage detected