Skip to content

Commit cd4fe81

Browse files
committed
Fixes after review
1 parent e0d3536 commit cd4fe81

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

sherpa-onnx/csrc/qnn/online-nemo-transducer-model-qnn.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ class OnlineNemoTransducerModelQnn::Impl {
127127
SHERPA_ONNX_EXIT(-1);
128128
}
129129

130+
if (states->size() < state_input_names_.size()) {
131+
SHERPA_ONNX_LOGE("states size %d is less than expected %d",
132+
static_cast<int32_t>(states->size()),
133+
static_cast<int32_t>(state_input_names_.size()));
134+
SHERPA_ONNX_EXIT(-1);
135+
}
136+
130137
std::lock_guard<std::mutex> lock(mutex_);
131138

132139
// Features come in as [num_frames, feat_dim] row-major, which matches
@@ -193,6 +200,11 @@ class OnlineNemoTransducerModelQnn::Impl {
193200
RunDecoder(int32_t token, std::vector<std::vector<float>> states) const {
194201
std::lock_guard<std::mutex> lock(mutex_);
195202

203+
if (states.size() < 2) {
204+
SHERPA_ONNX_LOGE("states should have at least 2 elements (h and c)");
205+
SHERPA_ONNX_EXIT(-1);
206+
}
207+
196208
// states[0] = h, states[1] = c
197209
decoder_->SetInputTensorData("y", &token, 1);
198210
decoder_->SetInputTensorData("h", states[0].data(),
@@ -403,6 +415,8 @@ class OnlineNemoTransducerModelQnn::Impl {
403415
SHERPA_ONNX_LOGE(
404416
"Invalid window size/shift in encoder input name '%s'",
405417
name.c_str());
418+
SHERPA_ONNX_EXIT(-1);
419+
}
406420

407421
normalization_type_.clear();
408422
if (parts.size() == 4) {
@@ -416,8 +430,6 @@ class OnlineNemoTransducerModelQnn::Impl {
416430
SHERPA_ONNX_EXIT(-1);
417431
}
418432
}
419-
SHERPA_ONNX_EXIT(-1);
420-
}
421433

422434
break;
423435
}

sherpa-onnx/csrc/qnn/online-recognizer-nemo-transducer-qnn-impl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ inline OnlineRecognizerResult ConvertResult(
3535
int32_t frames_since_start) {
3636
OnlineRecognizerResult r;
3737

38+
// The first token is the initial blank_id_ used to bootstrap the decoder.
39+
// Remove it before processing.
40+
if (!src.tokens.empty()) {
41+
src.tokens.erase(src.tokens.begin());
42+
}
43+
3844
r.tokens.reserve(src.tokens.size());
3945
r.timestamps.reserve(src.timestamps.size());
4046
r.ys_probs = std::move(src.ys_probs);
@@ -186,6 +192,7 @@ class OnlineRecognizerNemoTransducerQnnImpl : public OnlineRecognizerImpl {
186192
++t;
187193
}
188194
} else {
195+
++r.num_trailing_blanks;
189196
++t;
190197
num_symbols = 0;
191198
}

0 commit comments

Comments
 (0)