11#include " engine/models/citrinet_asr/assets.h"
22
3- #include " engine/framework/assets/resource_bundle .h"
3+ #include " engine/framework/assets/model_package .h"
44#include " engine/framework/assets/tensor_source.h"
55#include " engine/framework/assets/weight_metadata.h"
66#include " engine/framework/io/filesystem.h"
1515namespace engine ::models::citrinet_asr {
1616namespace io = engine::io;
1717namespace asset_meta = engine::assets;
18- CitrinetAssetPaths resolve_citrinet_assets (const std::filesystem::path & checkpoint_path) {
19- assets::ResourceBundle resources (checkpoint_path.parent_path ());
20- resources.add_file (" weights" , checkpoint_path);
21- resources.add_file (" config" , assets::checkpoint_sidecar_config_path (checkpoint_path));
22-
23- const auto config = resources.parse_json (" config" );
24- const auto * vocab_file = config.find (" vocab_file" );
25- if (vocab_file == nullptr || !vocab_file->is_string ()) {
26- throw std::runtime_error (" Citrinet config is missing vocab_file" );
27- }
28- resources.add_model_file (" vocab" , vocab_file->as_string ());
29-
30- CitrinetAssetPaths paths;
31- paths.model_root = resources.model_root ();
32- paths.checkpoint_path = resources.require_file (" weights" );
33- paths.config_path = resources.require_file (" config" );
34- paths.vocab_path = resources.require_file (" vocab" );
35- return paths;
36- }
3718
3819namespace {
3920
@@ -153,20 +134,17 @@ CitrinetConfig parse_config(const io::json::Value & root) {
153134 return cfg;
154135}
155136
156- CitrinetWeights load_citrinet_weights (const std::filesystem::path & checkpoint_path) {
157- const auto assets = resolve_citrinet_assets (checkpoint_path);
137+ CitrinetWeights load_citrinet_weights (engine::assets::ResourceBundle resources) {
158138 CitrinetWeights weights;
159- engine::assets::ResourceBundle resources (assets.model_root );
160- resources.add_file (" weights" , assets.checkpoint_path );
161139 const auto source = resources.open_tensor_source (" weights" );
162140 weights.source = source;
163- weights.config = parse_config (io::json::parse_file (assets. config_path ));
141+ weights.config = parse_config (resources. parse_json ( " config " ));
164142 weights.window = source->require_f32 (" preprocessor.featurizer.window" , {weights.config .win_length });
165143 weights.fb = source->require_f32 (
166144 " preprocessor.featurizer.fb" ,
167145 {1 , weights.config .n_mels , weights.config .n_fft / 2 + 1 });
168146
169- weights.vocab = load_vocab_file (assets. vocab_path );
147+ weights.vocab = load_vocab_file (resources. require_file ( " vocab " ) );
170148 if (static_cast <int64_t >(weights.vocab .size ()) != weights.config .vocab_size ) {
171149 throw std::runtime_error (" vocab size mismatch" );
172150 }
@@ -262,10 +240,13 @@ std::string checkpoint_cache_key(const std::filesystem::path & checkpoint_path)
262240
263241} // namespace
264242
265- std::shared_ptr<const CitrinetWeights> load_citrinet_weights_cached (const std::filesystem::path & checkpoint_path ) {
243+ std::shared_ptr<const CitrinetWeights> load_citrinet_weights_cached (const std::filesystem::path & model_path ) {
266244 static std::mutex cache_mutex;
267245 static std::unordered_map<std::string, std::weak_ptr<const CitrinetWeights>> cache;
268- const auto key = checkpoint_cache_key (checkpoint_path);
246+ auto resources = engine::assets::load_resource_bundle_from_package_spec (
247+ model_path,
248+ engine::assets::default_model_package_spec_path (" citrinet_asr" ));
249+ const auto key = checkpoint_cache_key (resources.require_file (" weights" ));
269250 {
270251 std::lock_guard<std::mutex> lock (cache_mutex);
271252 if (const auto it = cache.find (key); it != cache.end ()) {
@@ -274,7 +255,7 @@ std::shared_ptr<const CitrinetWeights> load_citrinet_weights_cached(const std::f
274255 }
275256 }
276257 }
277- auto loaded = std::make_shared<const CitrinetWeights>(load_citrinet_weights (checkpoint_path ));
258+ auto loaded = std::make_shared<const CitrinetWeights>(load_citrinet_weights (std::move (resources) ));
278259 {
279260 std::lock_guard<std::mutex> lock (cache_mutex);
280261 cache[key] = loaded;
0 commit comments