DeepFilterNet icon indicating copy to clipboard operation
DeepFilterNet copied to clipboard

DeepFilterNet not clearing GPU cache

Open drohack opened this issue 1 year ago • 3 comments

Issue: When running DeepFilterNet on a piece of audio, then running faster_whisper on that audio to get the transcript the faster_whisper transcribe runs really slow (like 10x slower). Both are using Torch to use the GPU.

Fix: if I run torch.cuda.empty_cache() then faster_whisper runs just fine.

This could be an issue where DeepFilterNet is not running the empty_cache() when it's done. Or faster_whisper not running it ahead of time (though I wouldn't normally expect that to happen as empty_cache() isn't exactly instantaneous, so it's not guaranteed to clear the cache before it's function runs).

So please run torch.cuda.empty_cache() at the end of the enhance() function.

My code:

    print_with_timestamp("Reduce audio start")
    reduce_audio_file_path = os.path.join(temp_dir, "temp_reduced_audio.wav")
    df_model, df_state, _ = init_df()
    audio, _ = load_audio(temp_audio_file_path, sr=df_state.sr())
    enhanced = enhance(df_model, df_state, audio, atten_lim_db=6)
    # Save for listening
    save_audio(reduce_audio_file_path, enhanced, df_state.sr())
    # Clear GPU memory
    torch.cuda.empty_cache()
    print_with_timestamp("Reduce audio end")

drohack avatar Jan 08 '24 05:01 drohack

Not directly related, but you might want to be aware of https://github.com/Rikorose/DeepFilterNet/issues/483.

lnicola avatar Jan 08 '24 06:01 lnicola

You can clear the cache on your own. I need to run enhance() multiple times so I do not want to clear the cache after each run.

Rikorose avatar Jan 08 '24 07:01 Rikorose

You can clear the cache on your own. I need to run enhance() multiple times so I do not want to clear the cache after each run.

You are right. There are use cases where you don't want to clear the cache right away. And I don't know which way would be used more often to set as a default. It might be nice to at least note it in the README as people using this might not know about torch and how to use it. And it might be nice to have an optional boolean input to toggle if the cache gets cleared at the end.

drohack avatar Jan 08 '24 16:01 drohack

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Apr 08 '24 02:04 github-actions[bot]