@@ -21,6 +21,11 @@ void OfflineParaformerModelConfig::Register(ParseOptions *po) {
2121 " /path/to/encoder.om,/path/to/predictor.om,/path/to/decoder.om"
2222 " If you use RK NPU, it is "
2323 " /path/to/encoder.rknn,/path/to/predictor.rknn,/path/to/decoder.rknn" );
24+
25+ std::string prefix = " paraformer" ;
26+ ParseOptions p (prefix, po);
27+
28+ qnn_config.Register (&p);
2429}
2530
2631bool OfflineParaformerModelConfig::Validate () const {
@@ -46,6 +51,13 @@ bool OfflineParaformerModelConfig::Validate() const {
4651 return false ;
4752 }
4853
54+ for (const auto &name : filenames) {
55+ if (!FileExists (name)) {
56+ SHERPA_ONNX_LOGE (" Paraformer model '%s' does not exist" , name.c_str ());
57+ return false ;
58+ }
59+ }
60+
4961 return true ;
5062 }
5163
@@ -63,19 +75,96 @@ bool OfflineParaformerModelConfig::Validate() const {
6375 return false ;
6476 }
6577
78+ for (const auto &name : filenames) {
79+ if (!FileExists (name)) {
80+ SHERPA_ONNX_LOGE (" Paraformer model '%s' does not exist" , name.c_str ());
81+ return false ;
82+ }
83+ }
84+
6685 return true ;
6786 }
6887
69- SHERPA_ONNX_LOGE (" Please pass *.onnx, *.om, or *.rknn models. Given '%s'" ,
70- model.c_str ());
88+ if (EndsWith (model, " .so" )) {
89+ std::vector<std::string> filenames;
90+ SplitStringToVector (model, " ," , false , &filenames);
91+ if (filenames.size () != 3 || !EndsWith (filenames[0 ], " encoder.so" ) ||
92+ !EndsWith (filenames[1 ], " predictor.so" ) ||
93+ !EndsWith (filenames[2 ], " decoder.so" )) {
94+ SHERPA_ONNX_LOGE (
95+ " For QNN, you should pass "
96+ " /path/libencoder.so,/path/libpredictor.so,/path/libdecoder.so. "
97+ " Given '%s'" ,
98+ model.c_str ());
99+ return false ;
100+ }
101+
102+ for (const auto &name : filenames) {
103+ if (!FileExists (name)) {
104+ SHERPA_ONNX_LOGE (" Paraformer model '%s' does not exist" , name.c_str ());
105+ return false ;
106+ }
107+ }
108+
109+ if (!qnn_config.Validate ()) {
110+ return false ;
111+ }
112+
113+ return true ;
114+ }
115+
116+ if (model.empty () && !qnn_config.context_binary .empty ()) {
117+ // we require that the context_binary exists
118+ if (!FileExists (qnn_config.context_binary )) {
119+ SHERPA_ONNX_LOGE (
120+ " Model is empty, but you provide a context binary that does not "
121+ " exist" );
122+ return false ;
123+ }
124+
125+ std::vector<std::string> filenames;
126+ SplitStringToVector (model, " ," , false , &filenames);
127+ if (filenames.size () != 3 ) {
128+ SHERPA_ONNX_LOGE (
129+ " For Paraformer with QNN, you should pass "
130+ " /path/encoder.bin,/path/predictor.bin,/path/decoder.bin"
131+ " Given '%s'" ,
132+ model.c_str ());
133+ return false ;
134+ }
135+
136+ for (const auto &name : filenames) {
137+ if (!FileExists (name)) {
138+ SHERPA_ONNX_LOGE (" Paraformer context binary '%s' does not exist" ,
139+ name.c_str ());
140+ return false ;
141+ }
142+ }
143+
144+ if (!qnn_config.Validate ()) {
145+ return false ;
146+ }
147+
148+ return true ;
149+ }
150+
151+ SHERPA_ONNX_LOGE (
152+ " Please pass *.onnx, *.om, *.rknn, or *.so models. Given '%s'" ,
153+ model.c_str ());
71154 return false ;
72155}
73156
74157std::string OfflineParaformerModelConfig::ToString () const {
75158 std::ostringstream os;
76159
77160 os << " OfflineParaformerModelConfig(" ;
78- os << " model=\" " << model << " \" )" ;
161+ os << " model=\" " << model << " \" " ;
162+
163+ if (!qnn_config.backend_lib .empty ()) {
164+ os << " , qnn_config=" << qnn_config.ToString ();
165+ }
166+
167+ os << " )" ;
79168
80169 return os.str ();
81170}
0 commit comments