| 192 | } |
| 193 | |
| 194 | std::shared_ptr<const CitrinetBackendWeights> load_backend_weights( |
| 195 | const CitrinetWeights & weights, |
| 196 | ggml_backend_t backend, |
| 197 | core::BackendType backend_type, |
| 198 | assets::TensorStorageType storage_type) { |
| 199 | auto out = std::make_shared<CitrinetBackendWeights>(); |
| 200 | out->store = std::make_shared<core::BackendWeightStore>( |
| 201 | backend, backend_type, "citrinet_asr.weights", 256ull * 1024ull * 1024ull); |
| 202 | auto & store = *out->store; |
| 203 | if (weights.source == nullptr) { |
| 204 | throw std::runtime_error("Citrinet weights require a tensor source"); |
| 205 | } |
| 206 | const auto & source = *weights.source; |
| 207 | out->blocks.reserve(weights.blocks.size()); |
| 208 | for (const auto & block : weights.blocks) { |
| 209 | BackendJasperBlockWeights dst; |
| 210 | dst.separable = block.separable; |
| 211 | dst.has_residual = block.has_residual; |
| 212 | dst.has_se = block.has_se; |
| 213 | dst.separable_repeats.reserve(block.separable_repeats.size()); |
| 214 | for (const auto & repeat : block.separable_repeats) { |
| 215 | dst.separable_repeats.push_back({ |
| 216 | make_backend_conv(store, source, repeat.depthwise, storage_type), |
| 217 | make_backend_conv_bn(store, source, repeat.pointwise, repeat.bn, storage_type), |
| 218 | }); |
| 219 | } |
| 220 | dst.conv_repeats.reserve(block.conv_repeats.size()); |
| 221 | for (const auto & repeat : block.conv_repeats) { |
| 222 | dst.conv_repeats.push_back({ |
| 223 | make_backend_conv_bn(store, source, repeat.conv, repeat.bn, storage_type), |
| 224 | }); |
| 225 | } |
| 226 | if (block.has_residual) { |
| 227 | dst.residual_conv = make_backend_conv_bn(store, source, block.residual_conv, block.residual_bn, storage_type); |
| 228 | } |
| 229 | if (block.has_se) { |
| 230 | dst.se.fc1 = make_backend_conv(store, source, block.se.fc1, storage_type); |
| 231 | dst.se.fc2 = make_backend_conv(store, source, block.se.fc2, storage_type); |
| 232 | } |
| 233 | out->blocks.push_back(std::move(dst)); |
| 234 | } |
| 235 | out->decoder = make_backend_conv(store, source, weights.decoder, storage_type); |
| 236 | store.upload(); |
| 237 | weights.source->release_storage(); |
| 238 | return out; |
| 239 | } |
| 240 | |
| 241 | std::shared_ptr<const CitrinetWeights> require_weights(std::shared_ptr<const CitrinetWeights> weights) { |
| 242 | if (weights == nullptr) { |
no test coverage detected