Download nemo-v2-streaming-punjabi.patch from baniguru/training_scripts: direct link, hf CLI and curl.
- Browser
- Download file 5.87 kB
-
https://huggingface.co/datasets/baniguru/training_scripts/resolve/main/nemo-v2-streaming-punjabi.patch
- Command line
-
hf download hf://datasets/baniguru/training_scripts/nemo-v2-streaming-punjabi.patch
-
curl -L -o nemo-v2-streaming-punjabi.patch https://huggingface.co/datasets/baniguru/training_scripts/resolve/main/nemo-v2-streaming-punjabi.patch
5.87 kB
| 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 | |
| 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 | |
| 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}") | |
| def perform_streaming( | |
| asr_model, step_num, pad_and_drop_preencoded | |
| ), | |
| return_transcription=True, | |
| + lang_ids=lang_ids, | |
| ) | |
| if debug_mode: | |
| 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, | |
| 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 | |
| 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 | |
| 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 | |
| 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. | |
| 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] | |