Fix initializing fp32 Qwen3-ASR models.#3480
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughBuild configuration whitespace cleanup and refactoring of model initialization in Qwen3 ASR model to use path-based Ort::Session construction instead of file buffer reading, with corresponding updates to initialization functions to handle null input case. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request refactors the OfflineQwen3ASRModel to initialize ONNX sessions directly from file paths and updates the initialization logic to handle null model data. Feedback suggests restoring path validation to prevent potential crashes and using const void* for model data parameters to improve type safety.
| conv_sess_ = std::make_unique<Ort::Session>( | ||
| env_, SHERPA_ONNX_TO_ORT_PATH(c.conv_frontend), sess_opts_conv_); | ||
|
|
||
| InitConvFrontend(nullptr, 0); | ||
|
|
||
| encoder_sess_ = std::make_unique<Ort::Session>( | ||
| env_, SHERPA_ONNX_TO_ORT_PATH(c.encoder), sess_opts_encoder_); | ||
|
|
||
| InitEncoder(nullptr, 0); | ||
|
|
||
| decoder_sess_ = std::make_unique<Ort::Session>( | ||
| env_, SHERPA_ONNX_TO_ORT_PATH(c.decoder), sess_opts_decoder_); | ||
|
|
||
| InitDecoder(nullptr, 0); |
There was a problem hiding this comment.
The previous implementation used ReadFile which explicitly checked if the model paths were valid and if the files could be read. The new implementation directly creates Ort::Session from file paths. If a path is empty or the file is missing, Ort::Session will throw an exception, which might result in a crash if not caught, and the error message might be less specific than before. Consider adding explicit checks for empty paths to maintain robust error reporting.
if (c.conv_frontend.empty()) {
SHERPA_ONNX_LOGE("qwen3_asr.conv_frontend is empty");
SHERPA_ONNX_EXIT(-1);
}
conv_sess_ = std::make_unique<Ort::Session>(
env_, SHERPA_ONNX_TO_ORT_PATH(c.conv_frontend), sess_opts_conv_);
InitConvFrontend(nullptr, 0);
if (c.encoder.empty()) {
SHERPA_ONNX_LOGE("qwen3_asr.encoder is empty");
SHERPA_ONNX_EXIT(-1);
}
encoder_sess_ = std::make_unique<Ort::Session>(
env_, SHERPA_ONNX_TO_ORT_PATH(c.encoder), sess_opts_encoder_);
InitEncoder(nullptr, 0);
if (c.decoder.empty()) {
SHERPA_ONNX_LOGE("qwen3_asr.decoder is empty");
SHERPA_ONNX_EXIT(-1);
}
decoder_sess_ = std::make_unique<Ort::Session>(
env_, SHERPA_ONNX_TO_ORT_PATH(c.decoder), sess_opts_decoder_);
InitDecoder(nullptr, 0);| @@ -224,8 +213,16 @@ class OfflineQwen3ASRModel::Impl { | |||
| } | |||
|
|
|||
| void InitConvFrontend(void *model_data, size_t model_data_length) { | |||
| @@ -243,8 +240,16 @@ class OfflineQwen3ASRModel::Impl { | |||
| } | |||
|
|
|||
| void InitEncoder(void *model_data, size_t model_data_length) { | |||
| @@ -267,8 +272,16 @@ class OfflineQwen3ASRModel::Impl { | |||
| } | |||
|
|
|||
| void InitDecoder(void *model_data, size_t model_data_length) { | |||
Summary by CodeRabbit
Chores
Refactor