Skip to content

Commit 92b83eb

Browse files
committed
optional import pytorch rewriter
1 parent ade8e02 commit 92b83eb

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

mmdeploy/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
from mmdeploy.utils import get_root_logger
55
from .version import __version__ # noqa F401
66

7-
importlib.import_module('mmdeploy.pytorch')
7+
if importlib.util.find_spec('torch'):
8+
importlib.import_module('mmdeploy.pytorch')
9+
else:
10+
logger = get_root_logger()
11+
logger.debug('torch is not installed.')
812

913
if importlib.util.find_spec('mmcv'):
1014
importlib.import_module('mmdeploy.mmcv')

mmdeploy/backend/sdk/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020
lib_dir = os.path.dirname(lib_path)
2121
sys.path.insert(0, lib_dir)
2222

23-
if importlib.util.find_spec(module_name) is not None:
24-
from .wrapper import SDKWrapper
25-
__all__ = ['SDKWrapper']
26-
_is_available = True
23+
try:
24+
if importlib.util.find_spec(module_name) is not None:
25+
from .wrapper import SDKWrapper
26+
__all__ = ['SDKWrapper']
27+
_is_available = True
28+
except Exception:
29+
pass
2730

2831

2932
def is_available() -> bool:

requirements/runtime.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
h5py
22
matplotlib
3+
multiprocess
34
numpy
45
onnx>=1.8.0
56
six

setup.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
import logging
2-
31
from setuptools import find_packages, setup
42

53
version_file = 'mmdeploy/version.py'
64

7-
try:
8-
from torch.utils.cpp_extension import BuildExtension
9-
cmd_class = {'build_ext': BuildExtension}
10-
except ModuleNotFoundError:
11-
cmd_class = {}
12-
logging.warning('Skip building ext ops due to the absence of torch.')
13-
145

156
def readme():
167
with open('README.md', encoding='utf-8') as f:
@@ -135,5 +126,5 @@ def gen_packages_items():
135126
'optional': parse_requirements('requirements/optional.txt'),
136127
},
137128
ext_modules=[],
138-
cmdclass=cmd_class,
129+
cmdclass={},
139130
zip_safe=False)

0 commit comments

Comments
 (0)