skirdey / voicerestore

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

audio_restoration_model.py fails on longer files #1

Open eschmidbauer opened 1 day ago

eschmidbauer commented 1 day 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 1 day 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 1 day ago

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