File size: 5,865 Bytes
6b20c33 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | diff --git a/examples/asr/asr_cache_aware_streaming/speech_to_text_cache_aware_streaming_infer.py b/examples/asr/asr_cache_aware_streaming/speech_to_text_cache_aware_streaming_infer.py
index 7726c2b27..981c099ef 100644
--- a/examples/asr/asr_cache_aware_streaming/speech_to_text_cache_aware_streaming_infer.py
+++ b/examples/asr/asr_cache_aware_streaming/speech_to_text_cache_aware_streaming_infer.py
@@ -120,9 +120,19 @@ def calc_drop_extra_pre_encoded(asr_model, step_num, pad_and_drop_preencoded):
def perform_streaming(
- asr_model, streaming_buffer, compare_vs_offline=False, debug_mode=False, pad_and_drop_preencoded=False
+ asr_model,
+ streaming_buffer,
+ compare_vs_offline=False,
+ debug_mode=False,
+ pad_and_drop_preencoded=False,
+ target_lang=None,
):
batch_size = len(streaming_buffer.streams_length)
+
+ lang_ids = None
+ if target_lang is not None:
+ lang_ids = [target_lang] * batch_size
+
if compare_vs_offline:
# would pass the whole audio at once through the model like offline mode in order to compare the results with the stremaing mode
# the output of the model in the offline and streaming mode should be exactly the same
@@ -141,6 +151,7 @@ def perform_streaming(
processed_signal=processed_signal,
processed_signal_length=processed_signal_length,
return_transcription=True,
+ lang_ids=lang_ids,
)
final_offline_tran = extract_transcriptions(transcribed_texts)
logging.info(f" Final offline transcriptions: {final_offline_tran}")
@@ -181,6 +192,7 @@ def perform_streaming(
asr_model, step_num, pad_and_drop_preencoded
),
return_transcription=True,
+ lang_ids=lang_ids,
)
if debug_mode:
@@ -276,6 +288,13 @@ def main():
help="Selects the decoder for Hybrid ASR models which has both the CTC and RNNT decoder. Supported decoders are ['ctc', 'rnnt']",
)
+ parser.add_argument(
+ "--target_lang",
+ type=str,
+ default=None,
+ help="Language ID for multilingual models, e.g. pa",
+ )
+
parser.add_argument(
"--att_context_size",
type=str,
@@ -376,7 +395,9 @@ def main():
asr_model=asr_model,
streaming_buffer=streaming_buffer,
compare_vs_offline=args.compare_vs_offline,
+ debug_mode=args.debug_mode,
pad_and_drop_preencoded=args.pad_and_drop_preencoded,
+ target_lang=args.target_lang,
)
else:
# stream audio files in a manifest file in batched mode
@@ -409,6 +430,7 @@ def main():
compare_vs_offline=args.compare_vs_offline,
debug_mode=args.debug_mode,
pad_and_drop_preencoded=args.pad_and_drop_preencoded,
+ target_lang=args.target_lang,
)
all_streaming_tran.extend(streaming_tran)
if args.compare_vs_offline:
diff --git a/nemo/collections/asr/models/hybrid_rnnt_ctc_models.py b/nemo/collections/asr/models/hybrid_rnnt_ctc_models.py
index 3e9f21e04..29c97e02a 100644
--- a/nemo/collections/asr/models/hybrid_rnnt_ctc_models.py
+++ b/nemo/collections/asr/models/hybrid_rnnt_ctc_models.py
@@ -163,12 +163,34 @@ class EncDecHybridRNNTCTCModel(EncDecRNNTModel, ASRBPEMixin, InterCTCMixin):
self.ctc_decoder.unfreeze()
def _transcribe_forward(self, batch: Any, trcfg: TranscribeConfig):
-
+
+ # AI4Bharat multilingual GPU transcribe fix:
+ # transcribe() dataloader yields CPU audio tensors even when model is CUDA.
+ device = next(self.parameters()).device
+
+ if isinstance(batch, tuple):
+ batch = (
+ batch[0].to(device, non_blocking=True),
+ batch[1].to(device, non_blocking=True),
+ *batch[2:],
+ )
+ elif isinstance(batch, list):
+ batch = list(batch)
+ batch[0] = batch[0].to(device, non_blocking=True)
+ batch[1] = batch[1].to(device, non_blocking=True)
+ else:
+ raise TypeError(f"Unexpected transcribe batch type: {type(batch)}")
+
if self.cur_decoder == "rnnt":
return super()._transcribe_forward(batch, trcfg)
# CTC Path
- encoded, encoded_len = self.forward(input_signal=batch[0], input_signal_length=batch[1])
+ input_signal = batch[0]
+ input_signal_length = batch[1]
+ encoded, encoded_len = self.forward(
+ input_signal=input_signal,
+ input_signal_length=input_signal_length,
+ )
if "multisoftmax" not in self.cfg.decoder:
language_ids = None
else:
diff --git a/nemo/collections/asr/parts/mixins/mixins.py b/nemo/collections/asr/parts/mixins/mixins.py
index 57dc95da8..9256e5444 100644
--- a/nemo/collections/asr/parts/mixins/mixins.py
+++ b/nemo/collections/asr/parts/mixins/mixins.py
@@ -584,6 +584,7 @@ class ASRModuleMixin(ASRAdapterModelMixin):
drop_extra_pre_encoded: int = None,
return_transcription: bool = True,
return_log_probs: bool = False,
+ lang_ids: List[str] = None, # AI4Bharat multilingual streaming
):
"""
It simulates a forward step with caching for streaming purposes.
@@ -689,6 +690,7 @@ class ASRModuleMixin(ASRAdapterModelMixin):
encoded_lengths=encoded_len,
return_hypotheses=True,
partial_hypotheses=previous_hypotheses,
+ lang_ids=lang_ids,
)
greedy_predictions = [hyp.y_sequence for hyp in best_hyp]
|