dlxj commited on
Commit
52f4978
·
1 Parent(s): b1b39c6

成功推理(流式)

Browse files
examples/asr/asr_cache_aware_streaming/speech_to_text_cache_aware_streaming_infer.py CHANGED
@@ -115,7 +115,7 @@ from nemo.collections.asr.parts.submodules.rnnt_decoding import RNNTDecodingConf
115
  from nemo.collections.asr.parts.utils.manifest_utils import read_manifest
116
  from nemo.collections.asr.parts.utils.rnnt_utils import Hypothesis
117
  from nemo.collections.asr.parts.utils.streaming_utils import CacheAwareStreamingAudioBuffer
118
- from nemo.collections.asr.parts.utils.transcribe_utils import get_inference_device, get_inference_dtype, setup_model
119
  from nemo.core.config import hydra_runner
120
  from nemo.utils import logging
121
 
@@ -309,7 +309,15 @@ def main(cfg: TranscriptionConfig):
309
  pl.seed_everything(cfg.random_seed)
310
 
311
  # setup device
312
- device = get_inference_device(cuda=cfg.cuda, allow_mps=cfg.allow_mps)
 
 
 
 
 
 
 
 
313
 
314
  if (cfg.compute_dtype is not None and cfg.compute_dtype != "float32") and cfg.amp:
315
  raise ValueError("amp=true is mutually exclusive with a compute_dtype other than float32")
@@ -321,7 +329,10 @@ def main(cfg: TranscriptionConfig):
321
  # with amp model weights required to be in float32
322
  compute_dtype = torch.float32
323
  else:
324
- compute_dtype = get_inference_dtype(compute_dtype=cfg.compute_dtype, device=device)
 
 
 
325
 
326
  if compute_dtype != torch.float32:
327
  # NB: cache-aware models do not currently work with compute_dtype != float32
@@ -405,8 +416,11 @@ def main(cfg: TranscriptionConfig):
405
  streaming_buffer=streaming_buffer,
406
  compute_dtype=compute_dtype,
407
  compare_vs_offline=cfg.compare_vs_offline,
 
408
  pad_and_drop_preencoded=cfg.pad_and_drop_preencoded,
409
  )
 
 
410
  else:
411
  # stream audio files in a manifest file in batched mode
412
  all_streaming_tran = []
@@ -486,4 +500,13 @@ def main(cfg: TranscriptionConfig):
486
 
487
 
488
  if __name__ == '__main__':
 
 
 
 
 
 
 
 
 
489
  main()
 
115
  from nemo.collections.asr.parts.utils.manifest_utils import read_manifest
116
  from nemo.collections.asr.parts.utils.rnnt_utils import Hypothesis
117
  from nemo.collections.asr.parts.utils.streaming_utils import CacheAwareStreamingAudioBuffer
118
+ from nemo.collections.asr.parts.utils.transcribe_utils import setup_model
119
  from nemo.core.config import hydra_runner
120
  from nemo.utils import logging
121
 
 
309
  pl.seed_everything(cfg.random_seed)
310
 
311
  # setup device
312
+ if cfg.cuda is None:
313
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
314
+ elif cfg.cuda < 0:
315
+ device = torch.device('cpu')
316
+ else:
317
+ device = torch.device(f'cuda:{cfg.cuda}')
318
+
319
+ if cfg.allow_mps and getattr(torch.backends, "mps", None) is not None and torch.backends.mps.is_available():
320
+ device = torch.device('mps')
321
 
322
  if (cfg.compute_dtype is not None and cfg.compute_dtype != "float32") and cfg.amp:
323
  raise ValueError("amp=true is mutually exclusive with a compute_dtype other than float32")
 
329
  # with amp model weights required to be in float32
330
  compute_dtype = torch.float32
331
  else:
332
+ if cfg.compute_dtype is None:
333
+ compute_dtype = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float32
334
+ else:
335
+ compute_dtype = getattr(torch, cfg.compute_dtype)
336
 
337
  if compute_dtype != torch.float32:
338
  # NB: cache-aware models do not currently work with compute_dtype != float32
 
416
  streaming_buffer=streaming_buffer,
417
  compute_dtype=compute_dtype,
418
  compare_vs_offline=cfg.compare_vs_offline,
419
+ debug_mode=cfg.debug_mode,
420
  pad_and_drop_preencoded=cfg.pad_and_drop_preencoded,
421
  )
422
+ # return early for single file mode
423
+ return
424
  else:
425
  # stream audio files in a manifest file in batched mode
426
  all_streaming_tran = []
 
500
 
501
 
502
  if __name__ == '__main__':
503
+ import sys
504
+ sys.argv.extend([
505
+ 'model_path=results/NeMo_Ja_FastConformer_Streaming/checkpoints/NeMo_Ja_FastConformer_Streaming.nemo',
506
+ "audio_file=E:/huggingface_echodict/NeMo/data/common_voice_11_0/ja/train/ja_train_0/common_voice_ja_25372057.wav",
507
+ 'batch_size=16',
508
+ 'compare_vs_offline=false',
509
+ 'debug_mode=true',
510
+ 'amp=true'
511
+ ])
512
  main()
readme.txt CHANGED
@@ -236,6 +236,10 @@ python examples/asr/transcribe_speech.py
236
  流式训练改三个参数,成功训练
237
 
238
 
 
 
 
 
239
 
240
 
241
  如果要训练一个 ASR 语音识别大模型,只用一条数据,它既是训练集,又是验证集,又是测试集。这样它正确率能正 100% 吗
 
236
  流式训练改三个参数,成功训练
237
 
238
 
239
+ 成功推理(流式)
240
+ python examples/asr/asr_cache_aware_streaming/speech_to_text_cache_aware_streaming_infer.py
241
+
242
+
243
 
244
 
245
  如果要训练一个 ASR 语音识别大模型,只用一条数据,它既是训练集,又是验证集,又是测试集。这样它正确率能正 100% 吗