CosyVoice icon indicating copy to clipboard operation
CosyVoice copied to clipboard

fade_in_out error when stream=True

Open codingl2k1 opened this issue 1 year ago • 3 comments

Describe the bug A clear and concise description of what the bug is.

Using the latest cosyvoice in stream mode:

  File "cosyvoice/cli/cosyvoice.py", line 56, in inference_sft
    for model_output in self.model.inference(**model_input, stream=stream):
  File "cosyvoice/cli/model.py", line 131, in inference
    this_tts_speech = self.token2wav(token=this_tts_speech_token,
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cosyvoice/cli/model.py", line 95, in token2wav
    tts_mel = fade_in_out(tts_mel, self.mel_overlap_dict[uuid], self.mel_window)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cosyvoice/utils/common.py", line 138, in fade_in_out
    fade_in_mel[:, :, :mel_overlap_len] = fade_in_mel[:, :, :mel_overlap_len] * window[:mel_overlap_len] + fade_out_mel[:, :, -mel_overlap_len:] * window[mel_overlap_len:]
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Inplace update to inference tensor outside InferenceMode is not allowed.You can make a clone to get a normal tensor before doing inplace update.See https://github.com/pytorch/rfcs/pull/17 for more details.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context Add any other context about the problem here.

codingl2k1 avatar Sep 01 '24 08:09 codingl2k1

update your code and run again

aluminumbox avatar Sep 03 '24 07:09 aluminumbox

## common.py
def fade_in_out(fade_in_mel, fade_out_mel, window):
    device = fade_in_mel.device
    fade_in_mel, fade_out_mel = fade_in_mel.cpu(), fade_out_mel.cpu()
    mel_overlap_len = int(window.shape[0] / 2)
    fade_in_mel = fade_in_mel.clone() ## works for me
    fade_in_mel[..., :mel_overlap_len] = fade_in_mel[..., :mel_overlap_len] * window[:mel_overlap_len] + \
        fade_out_mel[..., -mel_overlap_len:] * window[mel_overlap_len:]
    return fade_in_mel.to(device)

xianqiliu avatar Sep 24 '24 02:09 xianqiliu

Same error on my Apple M1, @xianqiliu solution works for me, thanks. But it should be better merge to repo?

riddlegit avatar Oct 12 '24 11:10 riddlegit