Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model loading issue #5

Open
008karan opened this issue Mar 14, 2021 · 21 comments
Open

model loading issue #5

008karan opened this issue Mar 14, 2021 · 21 comments

Comments

@008karan
Copy link

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

@yistLin
Copy link
Owner

yistLin commented Mar 15, 2021

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!

@ADD-eNavarro
Copy link

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

@yistLin
Copy link
Owner

yistLin commented Mar 21, 2021

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 yistLin closed this as completed Mar 22, 2021
@yistLin
Copy link
Owner

yistLin commented Mar 22, 2021

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

@ADD-eNavarro
Copy link

Great, thank you! Eager to try them!

@ADD-eNavarro
Copy link

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: #5

@yistLin
Copy link
Owner

yistLin commented Mar 22, 2021

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

@ADD-eNavarro
Copy link

ADD-eNavarro commented Mar 22, 2021

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
Copy link

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

@yistLin
Copy link
Owner

yistLin commented Mar 22, 2021

@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 yistLin reopened this Mar 22, 2021
@ADD-eNavarro
Copy link

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)

@yistLin
Copy link
Owner

yistLin commented Mar 22, 2021

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...

@ADD-eNavarro
Copy link

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...

@liyuanyaun
Copy link

@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

@yistLin
Copy link
Owner

yistLin commented Jul 28, 2021

@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

@liyuanyaun
Copy link

@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

1 similar comment
@liyuanyaun
Copy link

@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

@Omarnabk
Copy link

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

@Kenny0820
Copy link

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

@MohamedAbdullah55
Copy link

@yistLin
I used a Linux OS but I still have this problem.

torch 2.3.1
torchaudio 2.3.1
sox 1.5.0

@Sivakgpian
Copy link

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 "code/torch/torchaudio/sox_effects/sox_effects.py", line 5
effects: List[List[str]],
channels_first: bool=True) -> Tuple[Tensor, int]:
...
_0 = torch.torchaudio.sox_effects.sox_effects.apply_effects_tensor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
_1 = _0(wav_tensor, sample_rate, self.effects, True, )
wav_tensor1, _2, = _1

torch==2.4.0
torchaudio==2.4.0

i got error in linux can anyone solve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants