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]