Skip to content

Commit

Permalink
Fix setup.py crash when torch is not installed. (#1866)
Browse files Browse the repository at this point in the history
Co-authored-by: Blaine Rogers <blaine.rogers@five.ai>
  • Loading branch information
PaperclipBadger and five-blaine-rogers authored Mar 29, 2022
1 parent 398f060 commit 73b5d98
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
25 changes: 14 additions & 11 deletions op_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
print(
f"{WARNING} unable to import torch, please install it if you want to pre-compile any deepspeed ops."
)

TORCH_MAJOR = int(torch.__version__.split('.')[0])
TORCH_MINOR = int(torch.__version__.split('.')[1])
else:
TORCH_MAJOR = int(torch.__version__.split('.')[0])
TORCH_MINOR = int(torch.__version__.split('.')[1])


def installed_cuda_version():
Expand Down Expand Up @@ -166,12 +166,17 @@ def is_rocm_pytorch():
return OpBuilder._is_rocm_pytorch

_is_rocm_pytorch = False
if TORCH_MAJOR > 1 or (TORCH_MAJOR == 1 and TORCH_MINOR >= 5):
_is_rocm_pytorch = hasattr(torch.version,
'hip') and torch.version.hip is not None
if _is_rocm_pytorch:
from torch.utils.cpp_extension import ROCM_HOME
_is_rocm_pytorch = ROCM_HOME is not None
try:
import torch
except ImportError:
pass
else:
if TORCH_MAJOR > 1 or (TORCH_MAJOR == 1 and TORCH_MINOR >= 5):
_is_rocm_pytorch = hasattr(torch.version,
'hip') and torch.version.hip is not None
if _is_rocm_pytorch:
from torch.utils.cpp_extension import ROCM_HOME
_is_rocm_pytorch = ROCM_HOME is not None
OpBuilder._is_rocm_pytorch = _is_rocm_pytorch
return OpBuilder._is_rocm_pytorch

Expand Down Expand Up @@ -571,8 +576,6 @@ def compute_capability_args(self, cross_compile_archs=None):

def version_dependent_macros(self):
# Fix from apex that might be relevant for us as well, related to https://github.com/NVIDIA/apex/issues/456
TORCH_MAJOR = int(torch.__version__.split('.')[0])
TORCH_MINOR = int(torch.__version__.split('.')[1])
version_ge_1_1 = []
if (TORCH_MAJOR > 1) or (TORCH_MAJOR == 1 and TORCH_MINOR > 0):
version_ge_1_1 = ['-DVERSION_GE_1_1']
Expand Down
1 change: 0 additions & 1 deletion op_builder/fused_adam.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Copyright 2020 The Microsoft DeepSpeed Team
"""
import torch
from .builder import CUDAOpBuilder


Expand Down
1 change: 0 additions & 1 deletion op_builder/fused_lamb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Copyright 2020 The Microsoft DeepSpeed Team
"""
import torch
from .builder import CUDAOpBuilder


Expand Down
1 change: 0 additions & 1 deletion op_builder/transformer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Copyright 2020 The Microsoft DeepSpeed Team
"""
import torch
from .builder import CUDAOpBuilder


Expand Down

0 comments on commit 73b5d98

Please sign in to comment.