Skip to content

Fix extension import path for buck #764

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

Merged
merged 1 commit into from
May 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions torchtext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,23 @@


def _init_extension():
import os
import importlib
import torch
torch.ops.load_library('torchtext/_torchtext.so')
torch.classes.load_library('torchtext/_torchtext.so')

# load the custom_op_library and register the custom ops
lib_dir = os.path.dirname(__file__)
loader_details = (
importlib.machinery.ExtensionFileLoader,
importlib.machinery.EXTENSION_SUFFIXES
)

extfinder = importlib.machinery.FileFinder(lib_dir, loader_details)
ext_specs = extfinder.find_spec("_torchtext")
if ext_specs is None:
raise ImportError
torch.ops.load_library(ext_specs.origin)
torch.classes.load_library(ext_specs.origin)


_init_extension()
Expand Down