skirdey / voicerestore

VoiceRestore: Flow-Matching Transformers for Universal Speech Restoration
MIT License
88 stars 9 forks source link

audio_restoration_model.py fails on longer files #1

Closed eschmidbauer closed 1 month ago

eschmidbauer commented 2 months ago

thank you for sharing this project; im trying to run the audio_restoration_model.py on a 2m57s call (16k, 1 channel) and i get the following error:

audio_restoration_model.py:57: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  state_dict = torch.load(save_path)
Traceback (most recent call last):
  File "audio_restoration_model.py", line 99, in <module>
    restore_audio(optimized_model, args.input, args.output, steps=args.steps, cfg_strength=args.cfg_strength)
  File "audio_restoration_model.py", line 75, in restore_audio
    restored_wav = model(audio, steps=steps, cfg_strength=cfg_strength)
  File "venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
    return forward_call(*args, **kwargs)
  File "audio_restoration_model.py", line 39, in forward
    restored_mel = self.voice_restore.sample(processed_mel.transpose(1, 2), steps=steps, cfg_strength=cfg_strength)
  File "venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
    return func(*args, **kwargs)
  File "voice_restore.py", line 238, in sample
    trajectory = odeint(ode_fn, y0, times, **self.odeint_kwargs)
  File "venv/lib/python3.10/site-packages/torchdiffeq/_impl/odeint.py", line 79, in odeint
    solution = solver.integrate(t)
  File "venv/lib/python3.10/site-packages/torchdiffeq/_impl/solvers.py", line 114, in integrate
    dy, f0 = self._step_func(self.func, t0, dt, t1, y0)
  File "venv/lib/python3.10/site-packages/torchdiffeq/_impl/fixed_grid.py", line 19, in _step_func
    f0 = func(t0, y0, perturb=Perturb.NEXT if self.perturb else Perturb.NONE)
  File "venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
    return forward_call(*args, **kwargs)
  File "venv/lib/python3.10/site-packages/torchdiffeq/_impl/misc.py", line 197, in forward
    return self.base_func(t, y)
  File "voice_restore.py", line 235, in ode_fn
    return self.cfg_transformer_with_pred_head(x, times=t, cond=processed, cfg_strength=cfg_strength)
  File "voice_restore.py", line 216, in cfg_transformer_with_pred_head
    pred = self.transformer_with_pred_head(*args, **kwargs, cond=cond)
  File "voice_restore.py", line 205, in transformer_with_pred_head
    attended = self.transformer(x, times=times)
  File "venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
    return forward_call(*args, **kwargs)
  File "voice_restore.py", line 134, in forward
    assert seq_len <= self.max_seq_len, f'{seq_len} exceeds the set `max_seq_len` ({self.max_seq_len}) on Transformer'
AssertionError: 16681 exceeds the set `max_seq_len` (2000) on Transformer
skirdey commented 2 months ago

1) You can try removing the assert assert seq_len <= self.max_seq_len and see if the audio will fit into GPU memory.

2) I am planning to add long-form processing, which would be optimized for audio clips such yours via chunking. Give me a few days if the #1 doesn't work

eschmidbauer commented 2 months ago

separate issue was triggered- looks related to CUDA memory. Looking forward to the long form implementation

skirdey commented 1 month ago

@eschmidbauer I've added longform inference with window chunking, tested on 11m audio and it works well

https://github.com/skirdey/voicerestore/blob/main/inference_long.py

eschmidbauer commented 1 month ago

thank you ! i have noticed it takes a very long time to run long inference. the VRAM usage is very low (6% in testing), im wondering if the model/data is not fully loaded into CUDA image

skirdey commented 1 month ago

Thanks for sharing the experiment. I think you can try changing the window size (make it larger) and reduce overlap size to get a better utilization of gpu and have less chunks to process. Both are available as CLI parameters in the infer_long script.

skirdey commented 1 month ago

A few notes on future updates: 1) The model is still training, with more training it will require less CFM steps thus will dramatically speed up performance 2) The current model is raw pytorch export, I am planning to release a quantized and pruned version for inference once it trains a bit more

skirdey commented 1 month ago

@eschmidbauer I've updated inference_long script now it is 10x faster

eschmidbauer commented 1 month ago

i am testing the HF code since it has a model and It is still taking a very long time for a 3m20s file - >>> model("poor-quality-mono.wav", "test_output.wav", short=False) it doesn't appear like the model is using much resources on GPU either. image

Screenshot 2024-10-09 at 11 33 40 AM

skirdey commented 1 month ago

Hi Emmanuel! Thank you for reporting. I'll take a look into it and see what I can do for the HF code optimization.

On Wed, Oct 9, 2024 at 8:37 AM Emmanuel Schmidbauer < @.***> wrote:

i am testing the HF code https://huggingface.co/jadechoghari/VoiceRestore since it has a model and It is still taking a very long time for a 3m20s file -

model("poor-quality-mono.wav", "test_output.wav", short=False) it doesn't appear like the model is using much resources on GPU either. image.png (view on web) https://github.com/user-attachments/assets/8912dc56-6d42-4a2b-b873-451408d9dffa

Screenshot.2024-10-09.at.11.33.40.AM.png (view on web) https://github.com/user-attachments/assets/d987502c-306e-4aa2-babd-622fbe87ae74

— Reply to this email directly, view it on GitHub https://github.com/skirdey/voicerestore/issues/1#issuecomment-2402676972, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHIJQGCG4BSPXQNJAYJFYDZ2VETBAVCNFSM6AAAAABOWNEBH6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBSGY3TMOJXGI . You are receiving this because you modified the open/close state.Message ID: @.***>