Skip to content

Commit

Permalink
Revert D21870844: Create lazy_dyndeps to avoid caffe2 import costs.
Browse files Browse the repository at this point in the history
Test Plan: revert-hammer

Differential Revision:
D21870844 (pytorch@07fd5f8)

Original commit changeset: 3f65fedb65bb

fbshipit-source-id: 4f661072d72486a9c14711e368247b3d30e28af9
  • Loading branch information
malfet authored and facebook-github-bot committed Jul 9, 2020
1 parent 22f940b commit 1f13514
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 205 deletions.
20 changes: 1 addition & 19 deletions caffe2/python/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@ def _InitDataType():

_InitDataType()

_import_lazy_calls = []

def RegisterLazyImport(lazy):
global _import_lazy_calls
_import_lazy_calls += [lazy]


def _import_lazy():
global _import_lazy_calls
for lazy in _import_lazy_calls:
lazy()


def _GetRegisteredOperators():
return set(workspace.RegisteredOperators())
Expand All @@ -69,9 +57,7 @@ def _GetRegisteredOperators():
_REGISTERED_OPERATORS = _GetRegisteredOperators()


def RefreshRegisteredOperators(trigger_lazy=True):
if trigger_lazy:
_import_lazy()
def RefreshRegisteredOperators():
global _REGISTERED_OPERATORS
_REGISTERED_OPERATORS = _GetRegisteredOperators()

Expand All @@ -80,7 +66,6 @@ def RefreshRegisteredOperators(trigger_lazy=True):


def GlobalInit(args):
_import_lazy()
_GLOBAL_INIT_ARGS.extend(args[1:])
C.global_init(args)

Expand All @@ -94,7 +79,6 @@ def IsOperator(op_type):


def IsOperatorWithEngine(op_type, engine):
_import_lazy()
return C.op_registry_key(op_type, engine) in _REGISTERED_OPERATORS


Expand Down Expand Up @@ -294,7 +278,6 @@ def __getattr__(self, op_type):
op_type, *args, **kwargs)

def __dir__(self):
_import_lazy()
additional_methods = [
op
for op in _REGISTERED_OPERATORS
Expand Down Expand Up @@ -2228,7 +2211,6 @@ def __getattr__(self, op_type):
op_type, *args, **kwargs)

def __dir__(self):
_import_lazy()
additional_methods = [
op
for op in _REGISTERED_OPERATORS
Expand Down
8 changes: 4 additions & 4 deletions caffe2/python/dyndep.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from caffe2.python import core, extension_loader


def InitOpsLibrary(name, trigger_lazy=True):
def InitOpsLibrary(name):
"""Loads a dynamic library that contains custom operators into Caffe2.
Since Caffe2 uses static variable registration, you can optionally load a
Expand All @@ -32,7 +32,7 @@ def InitOpsLibrary(name, trigger_lazy=True):
# time when an actual call is made.
print('Ignoring {} as it is not a valid file.'.format(name))
return
_init_impl(name, trigger_lazy=trigger_lazy)
_init_impl(name)


_IMPORTED_DYNDEPS = set()
Expand All @@ -43,10 +43,10 @@ def GetImportedOpsLibraries():
return _IMPORTED_DYNDEPS


def _init_impl(path, trigger_lazy=True):
def _init_impl(path):
with dll_lock:
_IMPORTED_DYNDEPS.add(path)
with extension_loader.DlopenGuard():
ctypes.CDLL(path)
# reinitialize available ops
core.RefreshRegisteredOperators(trigger_lazy)
core.RefreshRegisteredOperators()
84 changes: 0 additions & 84 deletions caffe2/python/lazy_dyndep.py

This file was deleted.

98 changes: 0 additions & 98 deletions caffe2/python/lazy_dyndep_test.py

This file was deleted.

0 comments on commit 1f13514

Please sign in to comment.