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

Function load_backend_weights

src/models/silero_vad/runtime.cpp:64–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64std::shared_ptr<const SileroBackendWeights> load_backend_weights(
65 const SileroWeights & weights,
66 ggml_backend_t backend,
67 core::BackendType backend_type,
68 assets::TensorStorageType storage_type) {
69 auto out = std::make_shared<SileroBackendWeights>();
70 out->store = std::make_shared<core::BackendWeightStore>(
71 backend, backend_type, "silero_vad.weights", 16ull * 1024ull * 1024ull);
72 auto & store = *out->store;
73 if (weights.source == nullptr) {
74 throw std::runtime_error("Silero VAD weights require a tensor source");
75 }
76 const auto & source = *weights.source;
77 out->stft_conv_weight = store.load_tensor(source, "stft_conv.weight", storage_type, {258, 1, 256});
78 out->conv1_weight = store.load_tensor(source, "conv1.weight", storage_type, {128, 129, 3});
79 out->conv1_bias = load_f32_bias(store, source, "conv1.bias", {128});
80 out->conv2_weight = store.load_tensor(source, "conv2.weight", storage_type, {64, 128, 3});
81 out->conv2_bias = load_f32_bias(store, source, "conv2.bias", {64});
82 out->conv3_weight = store.load_tensor(source, "conv3.weight", storage_type, {64, 64, 3});
83 out->conv3_bias = load_f32_bias(store, source, "conv3.bias", {64});
84 out->conv4_weight = store.load_tensor(source, "conv4.weight", storage_type, {128, 64, 3});
85 out->conv4_bias = load_f32_bias(store, source, "conv4.bias", {128});
86 out->lstm_weight_ih = store.load_tensor(source, "lstm_cell.weight_ih", storage_type, {4 * kHiddenSize, kHiddenSize});
87 out->lstm_weight_hh = store.load_tensor(source, "lstm_cell.weight_hh", storage_type, {4 * kHiddenSize, kHiddenSize});
88 out->lstm_bias_ih = load_f32_bias(store, source, "lstm_cell.bias_ih", {4 * kHiddenSize});
89 out->lstm_bias_hh = load_f32_bias(store, source, "lstm_cell.bias_hh", {4 * kHiddenSize});
90 out->final_conv_weight = store.load_tensor(source, "final_conv.weight", storage_type, {1, kHiddenSize, 1});
91 out->final_conv_bias = load_f32_bias(store, source, "final_conv.bias", {1});
92 store.upload();
93 weights.source->release_storage();
94 return out;
95}
96
97std::shared_ptr<const SileroWeights> require_weights(std::shared_ptr<const SileroWeights> weights) {
98 if (!weights) {

Callers 1

SileroRuntimeMethod · 0.70

Calls 4

load_f32_biasFunction · 0.85
load_tensorMethod · 0.80
uploadMethod · 0.80
release_storageMethod · 0.45

Tested by

no test coverage detected