pythaiasr icon indicating copy to clipboard operation
pythaiasr copied to clipboard

Out of memory

Open tomudo opened this issue 2 years ago • 1 comments

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?

tomudo avatar Jul 13 '23 11:07 tomudo

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']

patharanordev avatar Aug 26 '23 04:08 patharanordev