Unverified Commit 25ceee71 authored by moto's avatar moto Committed by GitHub
Browse files

Simplify extension initialization (#1649)

parent ac1c9d5c
import warnings import warnings
import importlib
import torch import torch
from torchaudio._internal import module_utils as _mod_utils from torchaudio._internal import module_utils as _mod_utils
def _init_extension(): def _init_extension():
ext = 'torchaudio._torchaudio' if _mod_utils.is_module_available('torchaudio._torchaudio'):
if _mod_utils.is_module_available(ext): # Note this import has two purposes
_init_script_module(ext) # 1. to extract the path of the extension module so that
import torchaudio._torchaudio # noqa # we can initialize the script module with the path.
# 2. so that torchaudio._torchaudio is accessible in other modules.
# Look at sox_io_backend which uses `torchaudio._torchaudio.XXX`,
# assuming that the module `_torchaudio` is accessible.
import torchaudio._torchaudio
_init_script_module(torchaudio._torchaudio.__file__)
else: else:
warnings.warn('torchaudio C++ extension is not available.') warnings.warn('torchaudio C++ extension is not available.')
def _init_script_module(module): def _init_script_module(path):
path = importlib.util.find_spec(module).origin
torch.classes.load_library(path) torch.classes.load_library(path)
torch.ops.load_library(path) torch.ops.load_library(path)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment