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

undefined symbol when importing torchaudio with pytorch #62

Closed
ccoulombe opened this issue Oct 3, 2018 · 15 comments
Closed

undefined symbol when importing torchaudio with pytorch #62

ccoulombe opened this issue Oct 3, 2018 · 15 comments

Comments

@ccoulombe
Copy link
Contributor

ccoulombe commented Oct 3, 2018

Hi,
When importing torchaudio with pytorch 0.4.1 I get an undefined symbol. It does however work with v0.4.0. audio version: 7314b36

Successfully installed numpy-1.15.0 torch-cpu-0.4.1 torchaudio-0.1
(test_venv) [~]$ python -c "import torchaudio;"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "test_venv/lib/python3.6/site-packages/torchaudio/__init__.py", line 4, in <module>
    import _torch_sox
ImportError: test_venv/lib/python3.6/site-packages/_torch_sox.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZN2at5ErrorC1ENS_14SourceLocationESs

Thanks

@sh0416
Copy link

sh0416 commented Oct 6, 2018

I also encounter same problem.
The reason why the problem occur is virtual environment.
I use base environment and the problem doesn't occur even if the version is 0.4.1

@XilunWu
Copy link

XilunWu commented Oct 30, 2018

Same problem. When I use virtual environment in conda, it occurs while it doesn't occur in the base environment.

@ghost
Copy link

ghost commented Nov 8, 2018

How to install the package into existing virtual environment with Anaconda3?
I can not change to use the 'base' environment, because the Conda environment have installed so many packages

@ghost
Copy link

ghost commented Nov 8, 2018

To be Use the 'base' environment may cause some unkown errors,how to fix this bug?
ox.cpython-37m-x86_64-linux-gnu.so
linux-vdso.so.1 (0x00007ffefa331000)
libsox.so.3 => /usr/lib/x86_64-linux-gnu/libsox.so.3 (0x00007f15ce295000)
libstdc++.so.6 => /home//.conda/envs/PyTorch/lib/libstdc++.so.6 (0x00007f15ce5c8000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f15cdef7000)
libgcc_s.so.1 => /home/
/.conda/envs/PyTorch/lib/libgcc_s.so.1 (0x00007f15ce5b3000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f15cdcd8000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f15cd8e7000)
libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007f15cd6dd000)
libpng16.so.16 => /usr/lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f15cd4ab000)
libz.so.1 => /home//.conda/envs/PyTorch/lib/libz.so.1 (0x00007f15cd294000)
libmagic.so.1 => /usr/lib/x86_64-linux-gnu/libmagic.so.1 (0x00007f15cd072000)
libgsm.so.1 => /usr/lib/x86_64-linux-gnu/libgsm.so.1 (0x00007f15cce65000)
libgomp.so.1 => /home/
/.conda/envs/PyTorch/lib/libgomp.so.1 (0x00007f15ce58b000)
Is this problem caused by source bug ?or other reason ?
how to build the packages?
or where to download the rebuild package with pip?

@ccoulombe
Copy link
Contributor Author

ccoulombe commented Feb 11, 2019

With torch 1.0.0, I monkey patched this issue. It is caused by an issue in torch where is does not detect correctly the ABI of the wheel and forces to add -D_GLIBCXX_USE_CXX11_ABI=0 when it was compiled with -D_GLIBCXX_USE_CXX11_ABI=1. CFLAGS are not heard as the flag is forced at the end and the right most argument is the one heard by the compiler.

Make sure torchaudio is compiled with -D_GLIBCXX_USE_CXX11_ABI=1 if torch was build with CXX11_ABI.

Pytorch issue: pytorch/pytorch#16972

@ccoulombe ccoulombe changed the title undefined symbol when importing torchaudio with pytorch 0.4.1 undefined symbol when importing torchaudio with pytorch Feb 11, 2019
@prajwalkr
Copy link

@ccoulombe How do I make sure that torchaudio is compiled with that specific flag?

@dav-ell
Copy link

dav-ell commented Apr 4, 2020

Interested in the solution to this problem as well.

@jmlemercier
Copy link

jmlemercier commented Apr 16, 2020

Really intersted in this solution as well: I have the same problem with Virtual AND Base environments. I use pytorch=1.4.0 and torchaudio=0.4.0

  • Tried installing torchaudio with pip and conda but I get the same issue.

  • Also tried to downgrade pytorch and torchaudio, but does not solve the issue, just adding new conflicts.

Would be very much appreciated if we re-opened this issue

[EDIT : solved this issue by downgrading to torchaudio=0.3.0 and torch=1.3.1]

@ccoulombe
Copy link
Contributor Author

ccoulombe commented Apr 16, 2020

This issue was fixed in pytorch ~1.0.0 but I can re-trace the steps and provide more details when building from source. But maybe the wheels available on PyPI are built differently.

See : #62 (comment)

@NumesSanguis
Copy link

This issue occurred to me with pytorch=1.8.0, torchaudio=0.8.0 and cudatoolkit=11.1.1 through a conda environment.yaml install on Ubuntu 18.04:

OSError: /home/user/anaconda3/envs/some_env/lib/python3.8/site-packages/torchaudio/_torchaudio.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs
Full Traceback (CLICK ME)

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-1-b60aa7932a25> in <module>
      6 from torchvision import transforms
      7 # import torchaudio
----> 8 from torchaudio import transforms as atransforms
      9 import pytorch_lightning as pl
     10 from pytorch_lightning import Trainer

~/anaconda3/envs/some_env/lib/python3.8/site-packages/torchaudio/__init__.py in <module>
----> 1 from . import extension  # noqa: F401
      2 from torchaudio._internal import module_utils as _mod_utils  # noqa: F401
      3 from torchaudio import (
      4     compliance,
      5     datasets,

~/anaconda3/envs/some_env/lib/python3.8/site-packages/torchaudio/extension/__init__.py in <module>
      3 )
      4 
----> 5 _init_extension()
      6 
      7 del _init_extension

~/anaconda3/envs/some_env/lib/python3.8/site-packages/torchaudio/extension/extension.py in _init_extension()
      9     ext = 'torchaudio._torchaudio'
     10     if _mod_utils.is_module_available(ext):
---> 11         _init_script_module(ext)
     12     else:
     13         warnings.warn('torchaudio C++ extension is not available.')

~/anaconda3/envs/some_env/lib/python3.8/site-packages/torchaudio/extension/extension.py in _init_script_module(module)
     16 def _init_script_module(module):
     17     path = importlib.util.find_spec(module).origin
---> 18     torch.classes.load_library(path)
     19     torch.ops.load_library(path)

~/anaconda3/envs/some_env/lib/python3.8/site-packages/torch/_classes.py in load_library(self, path)
     44             path (str): A path to a shared library to load.
     45         """
---> 46         torch.ops.load_library(path)
     47 
     48 # The classes "namespace"

~/anaconda3/envs/some_env/lib/python3.8/site-packages/torch/_ops.py in load_library(self, path)
    102             # static (global) initialization code in order to register custom
    103             # operators with the JIT.
--> 104             ctypes.CDLL(path)
    105         self.loaded_libraries.add(path)
    106 

~/anaconda3/envs/some_env/lib/python3.8/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error, winmode)
    379 
    380         if handle is None:
--> 381             self._handle = _dlopen(self._name, mode)
    382         else:
    383             self._handle = handle

OSError: /home/user/anaconda3/envs/some_env/lib/python3.8/site-packages/torchaudio/_torchaudio.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs

@mthrok
Copy link
Collaborator

mthrok commented Mar 10, 2021

This issue occurred to me with pytorch=1.8.0, torchaudio=0.8.0 and cudatoolkit=11.1.1 through a conda environment.yaml install on Ubuntu 18.04:

OSError: /home/user/anaconda3/envs/some_env/lib/python3.8/site-packages/torchaudio/_torchaudio.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs

Full Traceback (CLICK ME)

@NumesSanguis The error means that your PyTorch C++ binary does not contain the function that torchaudio needs. It is likely version mismatch between torchaudio and pytorch.

@NumesSanguis
Copy link

@mthrok Thank you, this was indeed the issue. It was not the versions, but the channel of the conda package.

The release of PyTorch 1.8.0 was released together with the announcement of TorchAudio 0.8.0, so I would assume that these 2 versions would work together:

However, checking conda list:

pytorch                   1.8.0           cpu_py38he614459_0    conda-forge
torchaudio                0.8.0                      py38    pytorch

That shouldn't be the CPU version from conda-forge...

I also see an env inconsistency:

$ conda install pytorch -c pytorch
Collecting package metadata (current_repodata.json): done
Solving environment: - 
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:

  - pytorch/linux-64::torchaudio==0.8.0=py38
  - conda-forge/linux-64::cudatoolkit==11.1.1=h6406543_8
  - conda-forge/linux-64::pytorch==1.8.0=cpu_py38he614459_0
  - pytorch/linux-64::torchvision==0.9.0=py38_cu111
  - conda-forge/noarch::pytorch-lightning==1.1.8=pyhd8ed1ab_0
done

To solve it, I reversed the channel priority in my environment.yml:

channels:
  - defaults
  - pytorch
  - conda-forge

pytorch above conda-forge means that pytorch channel is prioritized (if my understanding is correct).

@mthrok
Copy link
Collaborator

mthrok commented Mar 10, 2021

@mthrok Thank you, this was indeed the issue. It was not the versions, but the channel of the conda package.

The release of PyTorch 1.8.0 was released together with the announcement of TorchAudio 0.8.0, so I would assume that these 2 versions would work together:

However, checking conda list:

pytorch                   1.8.0           cpu_py38he614459_0    conda-forge
torchaudio                0.8.0                      py38    pytorch

That shouldn't be the CPU version from conda-forge...

I also see an env inconsistency:

$ conda install pytorch -c pytorch
Collecting package metadata (current_repodata.json): done
Solving environment: - 
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:

  - pytorch/linux-64::torchaudio==0.8.0=py38
  - conda-forge/linux-64::cudatoolkit==11.1.1=h6406543_8
  - conda-forge/linux-64::pytorch==1.8.0=cpu_py38he614459_0
  - pytorch/linux-64::torchvision==0.9.0=py38_cu111
  - conda-forge/noarch::pytorch-lightning==1.1.8=pyhd8ed1ab_0
done

To solve it, I reversed the channel priority in my environment.yml:

channels:
  - defaults
  - pytorch
  - conda-forge

pytorch above conda-forge means that pytorch channel is prioritized (if my understanding is correct).

@NumesSanguis PyTorch 1.8.0 and torchaudio 0.8.0 work together. In fact PyTorch 1.8.0 is a strict requirement for torchaudio 0.8.0. For conda, pytorch channel is the official distribution channel, but conda-forge is not and we do not know how the packages in conda-forge are maintained. I guess in your case, things got mixed up. Glad to hear that now it's working.

@thinker0v0
Copy link

I've same problem and couldn't find solution how to. I just changed kernel virenv from python 3.7 to python 3.6 then magically error's gone.

@alireza-hariri
Copy link

using -U option simply solved problem for me
pip install -U torch torchaudio --no-cache-dir

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

10 participants