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

Method MelBandGraph

src/models/roformer/runtime.cpp:528–604  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

526 std::shared_ptr<const RoformerAssets> assets,
527 core::ExecutionContext & execution_context,
528 assets_ns::TensorStorageType weight_storage_type)
529 : FixedShapeGraph(execution_context.backend(), std::max(1, execution_context.config().threads)) {
530 if (assets == nullptr) {
531 throw std::runtime_error("mel_band_roformer graph requires assets");
532 }
533 const auto build_start = Clock::now();
534 const auto & config = assets->config;
535 weights_ = load_mel_band_weights(*assets, execution_context.backend(), execution_context.backend_type(), weight_storage_type);
536
537 init_context(256ull * 1024ull * 1024ull);
538 constants_ = std::make_unique<common::ConstantTensorCache>(
539 backend_,
540 compute_threads_,
541 "mel_band_roformer.constants",
542 4ull * 1024ull * 1024ull);
543 auto build_ctx = make_build_context(execution_context, "mel_band_roformer");
544 constants_->begin_graph();
545 input_shape_ = core::TensorShape::from_dims({1, config.chunk_frames, config.total_band_input_dim});
546 output_shape_ = core::TensorShape::from_dims({1, config.chunk_frames, config.total_band_input_dim});
547
548 auto input = core::make_tensor(build_ctx, GGML_TYPE_F32, input_shape_);
549 input_ = input.tensor;
550
551 const auto time_positions_host = make_positions(config.chunk_frames);
552 const auto time_positions = constants_->make_tensor(
553 core::TensorShape::from_dims({config.chunk_frames}),
554 GGML_TYPE_I32,
555 time_positions_host.data(),
556 time_positions_host.size() * sizeof(int32_t));
557
558 const auto freq_positions_host = make_positions(config.num_bands);
559 const auto freq_positions = constants_->make_tensor(
560 core::TensorShape::from_dims({config.num_bands}),
561 GGML_TYPE_I32,
562 freq_positions_host.data(),
563 freq_positions_host.size() * sizeof(int32_t));
564
565 core::TensorValue x = build_band_split(build_ctx, input, weights_, config);
566 for (const auto & layer : weights_.layers) {
567 x = modules::TransposeModule({{0, 2, 1, 3}, x.shape.rank}).build(build_ctx, x);
568 x = core::reshape_tensor(
569 build_ctx,
570 ensure_contiguous(build_ctx, x),
571 core::TensorShape::from_dims({config.num_bands, config.chunk_frames, config.dim}));
572 x = build_transformer_branch(build_ctx, x, time_positions, layer.time_branch, config);
573 x = core::reshape_tensor(
574 build_ctx,
575 ensure_contiguous(build_ctx, x),
576 core::TensorShape::from_dims({1, config.num_bands, config.chunk_frames, config.dim}));
577 x = modules::TransposeModule({{0, 2, 1, 3}, x.shape.rank}).build(build_ctx, x);
578 x = ensure_contiguous(build_ctx, x);
579
580 x = core::reshape_tensor(
581 build_ctx,
582 x,
583 core::TensorShape::from_dims({config.chunk_frames, config.num_bands, config.dim}));
584 x = build_transformer_branch(build_ctx, x, freq_positions, layer.freq_branch, config);
585 x = core::reshape_tensor(

Callers

nothing calls this directly

Calls 15

maxFunction · 0.85
load_mel_band_weightsFunction · 0.85
make_tensorFunction · 0.85
make_positionsFunction · 0.85
build_band_splitFunction · 0.85
TransposeModuleClass · 0.85
reshape_tensorFunction · 0.85
build_transformer_branchFunction · 0.85
build_mask_outputFunction · 0.85
ggml_set_outputFunction · 0.85
begin_graphMethod · 0.80
finish_graphMethod · 0.80

Tested by

no test coverage detected