Simplify the extension initialization process (#1734)
Calling `torch.[ops|classes].load_library(<PATH_TO_LIBRARY_FILE>)` is problematic in case `torchaudio` is deployed with PEX format, because the library file does not exist as a file. Our extension module, when it exists, is guaranteed to have PyBind11 binding even when no function is bound. This allows to load the library using the regular `import` statement in Python, and it works even in PEX format. When the library is loaded, the static initialization kicks in and the custom kernels bound via TorchScript also become available. This removes the need to call `torch.[ops|classe].load_library`. This works even when the implementation of custom kernel is stripped from `_torchaudio.so` so long as `_torchaudio.so` properly depend on the library that has the kernel implementations and static initialization.
Showing
Please register or sign in to comment