Rikorose / DeepFilterNet

Noise supression using deep filtering
https://huggingface.co/spaces/hshr/DeepFilterNet2
Other
2.15k stars 198 forks source link

DeepFilterNet not clearing GPU cache #486

Closed drohack closed 2 months ago

drohack commented 6 months ago

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")
lnicola commented 6 months ago

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

Rikorose commented 6 months ago

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.

drohack commented 5 months ago

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.

github-actions[bot] commented 2 months ago

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.