PyThaiNLP / pythaiasr

Python Thai Automatic Speech Recognition
Apache License 2.0
62 stars 13 forks source link

Out of memory #16

Open tomudo opened 1 year ago

tomudo commented 1 year ago

I test with 1:00 min wav file but it run out of GPU memory.

torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 138.00 MiB (GPU 0; 5.93 GiB total capacity; 4.99 GiB already allocated; 126.19 MiB free; 5.08 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

How could I run with a larger file?

patharanordev commented 1 year ago

Me too. So I try 30 sec wav instead, it works!.

For the large file, please try to split out your audio file (.wav) to be multi-parts(or files). In each part, should have maximum range of wav file to be 30 sec.

Then loop get the result or write into your output file, ex. :

os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'max_split_size_mb:512'

for fname in os.listdir(audio_folder):
  # Split your video into "temp_folder", 
  # you should clear this directory before split the new one
  split_audio(audio_folder, fname, temp_folder)

  # Loop get result
  for wavfile in os.listdir(temp_folder):
    torch.cuda.empty_cache()
    result = asr(data=f'{temp_folder}/{wavfile}', model=model, sampling_rate=16_000)
    print(result)

torch.cuda.empty_cache()
del os.environ['PYTORCH_CUDA_ALLOC_CONF']