Skip to content

Commit 4d3f4fa

Browse files
committed
Debug load_lib
1 parent bceedf3 commit 4d3f4fa

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

src/torchaudio/_extension/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
]
2222

2323

24-
if os.name == "nt" and (3, 8) <= sys.version_info < (3, 9):
24+
if os.name == "nt": # and (3, 8) <= sys.version_info < (3, 9):
2525
_init_dll_path()
2626

2727
# When the extension module is built, we initialize it.
2828
# In case of an error, we do not catch the failure as it suggests there is something
2929
# wrong with the installation.
3030
_IS_TORCHAUDIO_EXT_AVAILABLE = _load_lib("_torchaudio")
31+
assert _IS_TORCHAUDIO_EXT_AVAILABLE
3132
_IS_ALIGN_AVAILABLE = False
3233
if _IS_TORCHAUDIO_EXT_AVAILABLE:
3334
if not _load_lib("libtorchaudio"):

src/torchaudio/_extension/utils.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import logging
88
import os
99
import types
10+
import warnings
1011
from pathlib import Path
1112

1213
import torch
@@ -16,7 +17,8 @@
1617

1718

1819
def _get_lib_path(lib: str):
19-
suffix = "pyd" if os.name == "nt" else "so"
20+
suffix = ".pyd" if os.name == "nt" else ".so"
21+
paths = _LIB_DIR.glob(f"{lib}*{suffix}")
2022
path = _LIB_DIR / f"{lib}.{suffix}"
2123
return path
2224

@@ -52,10 +54,14 @@ def _load_lib(lib: str) -> bool:
5254
This behavior was chosen because the expected failure case is not recoverable.
5355
If a dependency is missing, then users have to install it.
5456
"""
55-
path = _get_lib_path(lib)
56-
if not path.exists():
57+
suffix = ".pyd" if os.name == "nt" else ".so"
58+
paths = list(_LIB_DIR.glob(f"{lib}*{suffix}"))
59+
print(f"_load_lib: {lib=} {paths=}")
60+
if not paths:
5761
return False
58-
torch.ops.load_library(path)
62+
if len(paths) > 1:
63+
warnings.warn(f"Expected a single file path to {lib}, got {paths=}")
64+
torch.ops.load_library(paths[0])
5965
return True
6066

6167

0 commit comments

Comments
 (0)