| 251 | } |
| 252 | |
| 253 | std::shared_ptr<const EcapaBackendWeights> load_backend_weights( |
| 254 | const EcapaWeights & weights, |
| 255 | ggml_backend_t backend, |
| 256 | core::BackendType backend_type, |
| 257 | assets::TensorStorageType storage_type) { |
| 258 | auto out = std::make_shared<EcapaBackendWeights>(); |
| 259 | out->store = std::make_shared<core::BackendWeightStore>( |
| 260 | backend, backend_type, "ecapa_tdnn_spk.weights", 256ull * 1024ull * 1024ull); |
| 261 | auto & store = *out->store; |
| 262 | if (weights.source == nullptr) { |
| 263 | throw std::runtime_error("ECAPA weights require a tensor source"); |
| 264 | } |
| 265 | const auto & source = *weights.source; |
| 266 | out->block0 = make_backend_tdnn(store, source, weights.block0, storage_type); |
| 267 | out->se_blocks.reserve(weights.se_blocks.size()); |
| 268 | for (const auto & block : weights.se_blocks) { |
| 269 | BackendSERes2NetBlockWeights dst; |
| 270 | dst.tdnn1 = make_backend_tdnn(store, source, block.tdnn1, storage_type); |
| 271 | dst.res2net.scale = block.res2net.scale; |
| 272 | dst.res2net.width = block.res2net.width; |
| 273 | dst.res2net.blocks.reserve(block.res2net.blocks.size()); |
| 274 | for (const auto & res2 : block.res2net.blocks) { |
| 275 | dst.res2net.blocks.push_back(make_backend_tdnn(store, source, res2, storage_type)); |
| 276 | } |
| 277 | dst.tdnn2 = make_backend_tdnn(store, source, block.tdnn2, storage_type); |
| 278 | dst.se.conv1 = make_backend_conv(store, source, block.se.conv1, storage_type); |
| 279 | dst.se.conv2 = make_backend_conv(store, source, block.se.conv2, storage_type); |
| 280 | out->se_blocks.push_back(std::move(dst)); |
| 281 | } |
| 282 | out->mfa = make_backend_tdnn(store, source, weights.mfa, storage_type); |
| 283 | if (engine::core::uses_host_graph_plan(backend)) { |
| 284 | auto [tdnn_x_conv, tdnn_stats_conv] = make_backend_split_pool_conv( |
| 285 | store, |
| 286 | source, |
| 287 | weights.asp.tdnn.conv, |
| 288 | weights.mfa.conv.out_channels, |
| 289 | storage_type); |
| 290 | out->asp.tdnn_x_conv = std::move(tdnn_x_conv); |
| 291 | out->asp.tdnn_stats_conv = std::move(tdnn_stats_conv); |
| 292 | out->asp.tdnn_norm = bind_batch_norm_weights(weights.asp.tdnn.norm, store); |
| 293 | out->asp.tdnn_norm_channels = static_cast<int64_t>(weights.asp.tdnn.norm.running_mean.size()); |
| 294 | } else { |
| 295 | out->asp.tdnn = make_backend_tdnn(store, source, weights.asp.tdnn, storage_type); |
| 296 | } |
| 297 | out->asp.conv = make_backend_conv(store, source, weights.asp.conv, storage_type); |
| 298 | out->asp_bn = bind_batch_norm_weights(weights.asp_bn, store); |
| 299 | out->asp_bn_channels = static_cast<int64_t>(weights.asp_bn.running_mean.size()); |
| 300 | out->fc = make_backend_conv(store, source, weights.fc, storage_type); |
| 301 | out->stats_eps = store_f32(store, core::TensorShape::from_dims({1, 1, 1}), std::vector<float>{kStatsEps}); |
| 302 | store.upload(); |
| 303 | weights.source->release_storage(); |
| 304 | return out; |
| 305 | } |
| 306 | |
| 307 | std::shared_ptr<const EcapaWeights> require_weights(std::shared_ptr<const EcapaWeights> weights) { |
| 308 | if (weights == nullptr) { |
no test coverage detected