dvector icon indicating copy to clipboard operation
dvector copied to clipboard

model loading issue

Open 008karan opened this issue 4 years ago • 21 comments

I am using pre-trained model to get the embedding but getting below error:

RuntimeError                              Traceback (most recent call last)
<ipython-input-5-4bcf886e7e7f> in <module>
      2 import torchaudio
      3 
----> 4 wav2mel = torch.jit.load("wav2mel.pt")
      5 dvector = torch.jit.load("dvector.pt").eval()
      6 

~/anaconda3/lib/python3.8/site-packages/torch/jit/_serialization.py in load(f, map_location, _extra_files)
    159     cu = torch._C.CompilationUnit()
    160     if isinstance(f, str) or isinstance(f, pathlib.Path):
--> 161         cpp_module = torch._C.import_ir_module(cu, str(f), map_location, _extra_files)
    162     else:
    163         cpp_module = torch._C.import_ir_module_from_buffer(

RuntimeError: 
Class Namespace cannot be used as a value:
Serialized   File "code/__torch__/torchaudio/sox_effects/sox_effects.py", line 5
    effects: List[List[str]],
    channels_first: bool=True) -> Tuple[Tensor, int]:
  in_signal = __torch__.torch.classes.torchaudio.TensorSignal.__new__(__torch__.torch.classes.torchaudio.TensorSignal)
                                                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
  _0 = (in_signal).__init__(tensor, sample_rate, channels_first, )
  out_signal = ops.torchaudio.sox_effects_apply_effects_tensor(in_signal, effects)
'apply_effects_tensor' is being compiled since it was called from 'SoxEffects.forward'
Serialized   File "code/__torch__/data/wav2mel.py", line 29
    wav_tensor: Tensor,
    sample_rate: int) -> Tensor:
    _0 = __torch__.torchaudio.sox_effects.sox_effects.apply_effects_tensor
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
    _1 = _0(wav_tensor, sample_rate, self.effects, True, )
    wav_tensor1, _2, = _1

008karan avatar Mar 14 '21 17:03 008karan

I myself also encountered this after upgrading torch to 1.8.0 and torchaudio to 0.8.0. I will try my best to fix this ASAP!

yistLin avatar Mar 15 '21 16:03 yistLin

Looking forward for this to be fixed, since I find myself in the same situation. Thanks for your great work, by the way!

ADD-eNavarro avatar Mar 16 '21 09:03 ADD-eNavarro

I just realized that the default backend has been changed from sox to sox_io in torchaudio 0.8.0. I'm not very sure whether this causes the problem, but ever since I recompiled the Wav2Mel module, it works just fine. Plan to upload the new module tomorrow.

yistLin avatar Mar 21 '21 11:03 yistLin

The newly compiled modules have been uploaded with the new release.

yistLin avatar Mar 22 '21 07:03 yistLin

Great, thank you! Eager to try them!

ADD-eNavarro avatar Mar 22 '21 07:03 ADD-eNavarro

Still didn't work for me:

Message= Unknown builtin op: torchaudio::sox_effects_apply_effects_tensor. Could not find any similar ops to torchaudio::sox_effects_apply_effects_tensor. This op may not exist or may not be currently supported in TorchScript. : File "/home/yist/.pyenv/versions/3.8.5/lib/python3.8/site-packages/torchaudio/sox_effects/sox_effects.py", line 151 >>> assert sample_rate == 8000 """ return torch.ops.torchaudio.sox_effects_apply_effects_tensor( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE tensor, sample_rate, effects, channels_first) Serialized File "code/torch/torchaudio/sox_effects/sox_effects.py", line 5 effects: List[List[str]], channels_first: bool=True) -> Tuple[Tensor, int]: _0, _1 = ops.torchaudio.sox_effects_apply_effects_tensor(tensor, sample_rate, effects, channels_first) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE return (_0, _1) 'apply_effects_tensor' is being compiled since it was called from 'SoxEffects.forward' Serialized File "code/torch/data/wav2mel.py", line 31 wav_tensor: Tensor, sample_rate: int) -> Tensor: _0 = torch.torchaudio.sox_effects.sox_effects.apply_effects_tensor ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE _1 = _0(wav_tensor, sample_rate, self.effects, True, ) wav_tensor1, _2, = _1

Source=*** StackTrace: File "***", line 11, in (Current frame) wav2mel = torch.jit.load(r"yistLin dvector\wav2mel.pt") # Error: https://github.com/yistLin/dvector/issues/5

ADD-eNavarro avatar Mar 22 '21 07:03 ADD-eNavarro

Did you import torchaudio before loading the wav2mel.pt module?

yistLin avatar Mar 22 '21 07:03 yistLin

Yes, my code is as in the example:

import torch # This is 1.8.0 import torchaudio # This is 0.8.0

wav2mel = torch.jit.load(r"yistLin dvector\wav2mel.pt") # Error

ADD-eNavarro avatar Mar 22 '21 07:03 ADD-eNavarro

Exactly those (sorry, updated the comment a bit too late)

ADD-eNavarro avatar Mar 22 '21 07:03 ADD-eNavarro

@ADD-eNavarro Can you try to compile the modules? You can simply run the preprocessing script and those modules will be generated and saved with the preprocessed data. Or you can do it manually like this:

# in the root directory of the repo
import torch
import torchaudio

from data.wav2mel import Wav2Mel

wav2mel = Wav2Mel()
wav2mel = torch.jit.script(wav2mel)
wav2mel.save("wav2mel.pt")

yistLin avatar Mar 22 '21 07:03 yistLin

I get an error in: wav2mel = torch.jit.script(wav2mel)

Message= undefined value torch: File "\AppData\Roaming\Python\Python37\site-packages\torchaudio_internal\module_utils.py", line 151 >>> assert sample_rate == 8000 """ return torch.ops.torchaudio.sox_effects_apply_effects_tensor( ~~~~~ <--- HERE tensor, sample_rate, effects, channels_first) 'apply_effects_tensor' is being compiled since it was called from 'SoxEffects.forward' File "\yistLin_dVector\data\wav2mel.py", line 72 def forward(self, wav_tensor: torch.Tensor, sample_rate: int) -> torch.Tensor: wav_tensor, _ = apply_effects_tensor(wav_tensor, sample_rate, self.effects) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE return wav_tensor

Source=\yistLin_dVector\Test.py StackTrace: File "\yistLin_dVector\Test.py", line 7, in (Current frame) wav2mel = torch.jit.script(wav2mel)

ADD-eNavarro avatar Mar 22 '21 07:03 ADD-eNavarro

Got it, now I see some problems:

  1. Do you have sox installed on your machine?
  2. From those logs you posted, I guess you're using Windows. But I'm not 100% sure whether torchaudio's SoxEffects works on Windows as on Linux/Mac OS.

Reading torchaudio's docs, it says that the sox_io backend works on Linux/Mac OS only, but I didn't see any warnings like: SoxEffects does not work on Windows...

yistLin avatar Mar 22 '21 07:03 yistLin

You're right, I'm working on Windows. Sox is installed, sox_io won't install on Windows. That might be the cause indeed. I will look into it too, but it would be a pity to discard Windows users like that...

ADD-eNavarro avatar Mar 22 '21 08:03 ADD-eNavarro

@ADD-eNavarro Can you try to compile the modules? You can simply run the preprocessing script and those modules will be generated and saved with the preprocessed data. Or you can do it manually like this:

# in the root directory of the repo
import torch
import torchaudio

from data.wav2mel import Wav2Mel

wav2mel = Wav2Mel()
wav2mel = torch.jit.script(wav2mel)
wav2mel.save("wav2mel.pt")

hi, i follow your solution in linux,but still not solve?

by the way, can you share you source model? TorchScript should be consistent with your version

liyuanyaun avatar Jul 28 '21 06:07 liyuanyaun

@liyuanyaun Can you show me the error messages or describe more about which step went wrong?

I just tested the TorchScript modules on Google Colab, and nothing went wrong. Here's the link: https://colab.research.google.com/drive/1yNMPOCxyUYVr03pYm6kix8Vm0ICThGAe?usp=sharing

yistLin avatar Jul 28 '21 07:07 yistLin

@liyuanyaun Can you show me the error messages or describe more about which step went wrong?

I just tested the TorchScript modules on Google Colab, and nothing went wrong. Here's the link: https://colab.research.google.com/drive/1yNMPOCxyUYVr03pYm6kix8Vm0ICThGAe?usp=sharing

my error is same as ADD-eNavarro Unknown builtin op: torchaudio::sox_effects_apply_effects_tensor. Could not find any similar ops to torchaudio::sox_effects_apply_effects_tensor. This op may not exist or may not be currently supported in TorchScript.

and i follow your sulution:

in the root directory of the repo

import torch import torchaudio

from data.wav2mel import Wav2Mel

wav2mel = Wav2Mel() wav2mel = torch.jit.script(wav2mel) wav2mel.save("wav2mel.pt")

but it did not work

liyuanyaun avatar Jul 28 '21 08:07 liyuanyaun

@liyuanyaun Can you show me the error messages or describe more about which step went wrong?

I just tested the TorchScript modules on Google Colab, and nothing went wrong. Here's the link: https://colab.research.google.com/drive/1yNMPOCxyUYVr03pYm6kix8Vm0ICThGAe?usp=sharing

my error is same as ADD-eNavarro Unknown builtin op: torchaudio::sox_effects_apply_effects_tensor. Could not find any similar ops to torchaudio::sox_effects_apply_effects_tensor. This op may not exist or may not be currently supported in TorchScript.

and i follow your sulution:

in the root directory of the repo

import torch import torchaudio

from data.wav2mel import Wav2Mel

wav2mel = Wav2Mel() wav2mel = torch.jit.script(wav2mel) wav2mel.save("wav2mel.pt")

but it did not work

liyuanyaun avatar Jul 28 '21 08:07 liyuanyaun

It works on Linux well. The reported problem appears just in Windows :\

Omarnabk avatar Feb 11 '22 17:02 Omarnabk

Hello does this solved? I have the same problem in windows.

Kenny0820 avatar Sep 10 '22 08:09 Kenny0820