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

OSError libtorchaudio.so: undefined symbol: _ZN3c104cuda20CUDACachingAllocator9allocatorE when importing MSE, MAE, or MAPE #2188

Closed
R-N opened this issue Oct 22, 2023 · 5 comments
Labels
bug / fix Something isn't working help wanted Extra attention is needed

Comments

@R-N
Copy link

R-N commented Oct 22, 2023

🐛 Bug

I was just trying to import MSE, MAE, and MAPE but it errors. Weird that it has to import torchaudio when I'm not importing audio metrics?

OSError: /usr/local/lib/python3.10/dist-packages/torchaudio/lib/libtorchaudio.so: undefined symbol: _ZN3c104cuda20CUDACachingAllocator9allocatorE

/content/ml-utility-loss/ml_utility_loss/loss_learning/estimator/process.py in
4 from ...util import stack_samples, stack_sample_dicts
5 from torch.nn.utils import clip_grad_norm_
----> 6 from torchmetrics import MeanSquaredError as MSE, MeanAbsoluteError as MAE, MeanAbsolutePercentageError as MAPE
7
8 RMSE = MSE(squared=False)

/usr/local/lib/python3.10/dist-packages/torchmetrics/init.py in
12 _PROJECT_ROOT = os.path.dirname(_PACKAGE_ROOT)
13
---> 14 from torchmetrics import functional # noqa: E402
15 from torchmetrics.aggregation import ( # noqa: E402
16 CatMetric,

/usr/local/lib/python3.10/dist-packages/torchmetrics/functional/init.py in
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
---> 14 from torchmetrics.functional.audio._deprecated import _permutation_invariant_training as permutation_invariant_training
15 from torchmetrics.functional.audio._deprecated import _pit_permutate as pit_permutate
16 from torchmetrics.functional.audio._deprecated import (

/usr/local/lib/python3.10/dist-packages/torchmetrics/functional/audio/init.py in
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
---> 14 from torchmetrics.functional.audio.pit import permutation_invariant_training, pit_permutate
15 from torchmetrics.functional.audio.sdr import (
16 scale_invariant_signal_distortion_ratio,

/usr/local/lib/python3.10/dist-packages/torchmetrics/functional/audio/pit.py in
20 from typing_extensions import Literal
21
---> 22 from torchmetrics.utilities import rank_zero_warn
23 from torchmetrics.utilities.imports import _SCIPY_AVAILABLE
24

/usr/local/lib/python3.10/dist-packages/torchmetrics/utilities/init.py in
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
---> 14 from torchmetrics.utilities.checks import check_forward_full_state_property
15 from torchmetrics.utilities.data import (
16 dim_zero_cat,

/usr/local/lib/python3.10/dist-packages/torchmetrics/utilities/checks.py in
23 from torch import Tensor
24
---> 25 from torchmetrics.metric import Metric
26 from torchmetrics.utilities.data import select_topk, to_onehot
27 from torchmetrics.utilities.enums import DataType

/usr/local/lib/python3.10/dist-packages/torchmetrics/metric.py in
28 from torch.nn import Module
29
---> 30 from torchmetrics.utilities.data import (
31 _flatten,
32 _squeeze_if_scalar,

/usr/local/lib/python3.10/dist-packages/torchmetrics/utilities/data.py in
20
21 from torchmetrics.utilities.exceptions import TorchMetricsUserWarning
---> 22 from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_12, _XLA_AVAILABLE
23 from torchmetrics.utilities.prints import rank_zero_warn
24

/usr/local/lib/python3.10/dist-packages/torchmetrics/utilities/imports.py in
48 _GAMMATONE_AVAILABEL: bool = package_available("gammatone")
49 _TORCHAUDIO_AVAILABEL: bool = package_available("torchaudio")
---> 50 _TORCHAUDIO_GREATER_EQUAL_0_10: Optional[bool] = compare_version("torchaudio", operator.ge, "0.10.0")
51 _SACREBLEU_AVAILABLE: bool = package_available("sacrebleu")
52 _REGEX_AVAILABLE: bool = package_available("regex")

/usr/local/lib/python3.10/dist-packages/lightning_utilities/core/imports.py in compare_version(package, op, version, use_base_version)
71 """
72 try:
---> 73 pkg = importlib.import_module(package)
74 except (ImportError, pkg_resources.DistributionNotFound):
75 return False

/usr/lib/python3.10/importlib/init.py in import_module(name, package)
124 break
125 level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)
127
128

/usr/local/lib/python3.10/dist-packages/torchaudio/init.py in
----> 1 from . import ( # noqa: F401
2 _extension,
3 compliance,
4 datasets,
5 functional,

/usr/local/lib/python3.10/dist-packages/torchaudio/_extension/init.py in
43 _IS_ALIGN_AVAILABLE = False
44 if _IS_TORCHAUDIO_EXT_AVAILABLE:
---> 45 _load_lib("libtorchaudio")
46
47 import torchaudio.lib._torchaudio # noqa

/usr/local/lib/python3.10/dist-packages/torchaudio/_extension/utils.py in _load_lib(lib)
62 if not path.exists():
63 return False
---> 64 torch.ops.load_library(path)
65 torch.classes.load_library(path)
66 return True

/usr/local/lib/python3.10/dist-packages/torch/_ops.py in load_library(self, path)
571 # static (global) initialization code in order to register custom
572 # operators with the JIT.
--> 573 ctypes.CDLL(path)
574 self.loaded_libraries.add(path)
575

/usr/lib/python3.10/ctypes/init.py in init(self, name, mode, handle, use_errno, use_last_error, winmode)
372
373 if handle is None:
--> 374 self._handle = _dlopen(self._name, mode)
375 else:
376 self._handle = handle

OSError: /usr/local/lib/python3.10/dist-packages/torchaudio/lib/libtorchaudio.so: undefined symbol: _ZN3c104cuda20CUDACachingAllocator9allocatorE

To Reproduce

I was just trying to import MSE, MAE, and MAPE from torchmetrics import MeanSquaredError as MSE, MeanAbsoluteError as MAE, MeanAbsolutePercentageError as MAPE

Expected behavior

It imported MSE, MAE, and MAPE, preferably without requiring torchaudio.

Environment

Google Colab
Python 3.10.12
torch==1.13.1
torchmetrics==1.2.0
torchaudio==2.1.0+cu118

Additional context

I can't upgrade torch to latest version due to a package I need requires torch 1.x

@R-N R-N added bug / fix Something isn't working help wanted Extra attention is needed labels Oct 22, 2023
@R-N R-N changed the title OSError: /usr/local/lib/python3.10/dist-packages/torchaudio/lib/libtorchaudio.so: undefined symbol: _ZN3c104cuda20CUDACachingAllocator9allocatorE OSError libtorchaudio.so: undefined symbol: _ZN3c104cuda20CUDACachingAllocator9allocatorE Oct 22, 2023
@github-actions
Copy link

Hi! thanks for your contribution!, great first issue!

@R-N R-N changed the title OSError libtorchaudio.so: undefined symbol: _ZN3c104cuda20CUDACachingAllocator9allocatorE OSError libtorchaudio.so: undefined symbol: _ZN3c104cuda20CUDACachingAllocator9allocatorE when importing MSE, MAE, or MAPE Oct 22, 2023
@R-N
Copy link
Author

R-N commented Oct 22, 2023

Ok it actually errors when importing any of them.

@SkafteNicki
Copy link
Member

@R-N, thanks for raising this issue.
The stacktrace indicates to me that the problem is with your torchaudio installation, and that simply trying

import torchaudio

will lead to the same problem.

@Borda
Copy link
Member

Borda commented Oct 23, 2023

yes, this is unrelated to TM, and the misalignment of torch and torchaudion versions
you can see the compatibility matrix in:
https://github.com/Lightning-AI/utilities/blob/42097f7d9fcf9634efd3f215833357e837262e62/scripts/adjust-torch-versions.py#L12-L29

@Borda Borda closed this as completed Oct 27, 2023
@AI-General
Copy link

pip install -U torch torchaudio

Above command will fix problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug / fix Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants