Skip to content

Properly import LooseVersion #996

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
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions test/test_spectral_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
skipIf)
from torch.testing._internal.common_methods_invocations import spectral_funcs

from setuptools import distutils
from distutils.version import LooseVersion
from typing import Optional, List


Expand Down Expand Up @@ -101,7 +101,7 @@ class TestFFT(TestCase):
@ops([op for op in spectral_funcs if not op.ndimensional])
def test_reference_1d(self, device, dtype, op):
norm_modes = ((None, "forward", "backward", "ortho")
if distutils.version.LooseVersion(np.__version__) >= '1.20.0'
if LooseVersion(np.__version__) >= '1.20.0'
else (None, "ortho"))
test_args = [
*product(
Expand Down Expand Up @@ -252,7 +252,7 @@ def test_fft_half_and_bfloat16_errors(self, device, dtype, op):
@ops([op for op in spectral_funcs if op.ndimensional])
def test_reference_nd(self, device, dtype, op):
norm_modes = ((None, "forward", "backward", "ortho")
if distutils.version.LooseVersion(np.__version__) >= '1.20.0'
if LooseVersion(np.__version__) >= '1.20.0'
else (None, "ortho"))

# input_ndim, s, dim
Expand Down Expand Up @@ -349,7 +349,7 @@ def test_fftn_invalid(self, device, dtype, op):
@dtypes(torch.double, torch.complex128)
def test_fft2_numpy(self, device, dtype):
norm_modes = ((None, "forward", "backward", "ortho")
if distutils.version.LooseVersion(np.__version__) >= '1.20.0'
if LooseVersion(np.__version__) >= '1.20.0'
else (None, "ortho"))

# input_ndim, s
Expand Down
8 changes: 4 additions & 4 deletions tools/setup_helpers/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from subprocess import check_call, check_output, CalledProcessError
import sys
import sysconfig
from setuptools import distutils
from distutils.version import LooseVersion

from . import which
from .env import (BUILD_DIR, IS_64BIT, IS_DARWIN, IS_WINDOWS, check_negative_env_flag)
Expand Down Expand Up @@ -115,10 +115,10 @@ def _get_cmake_command():
return cmake_command
cmake3 = which('cmake3')
cmake = which('cmake')
if cmake3 is not None and CMake._get_version(cmake3) >= distutils.version.LooseVersion("3.5.0"):
if cmake3 is not None and CMake._get_version(cmake3) >= LooseVersion("3.5.0"):
cmake_command = 'cmake3'
return cmake_command
elif cmake is not None and CMake._get_version(cmake) >= distutils.version.LooseVersion("3.5.0"):
elif cmake is not None and CMake._get_version(cmake) >= LooseVersion("3.5.0"):
return cmake_command
else:
raise RuntimeError('no cmake or cmake3 with version >= 3.5.0 found')
Expand All @@ -129,7 +129,7 @@ def _get_version(cmd):

for line in check_output([cmd, '--version']).decode('utf-8').split('\n'):
if 'version' in line:
return distutils.version.LooseVersion(line.strip().split(' ')[2])
return LooseVersion(line.strip().split(' ')[2])
raise RuntimeError('no version found')

def run(self, args, env):
Expand Down
4 changes: 2 additions & 2 deletions torch/testing/_internal/common_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from torch.testing._internal.common_utils import TEST_NUMBA
import inspect
import contextlib
from setuptools import distutils
from distutils.version import LooseVersion


TEST_CUDA = torch.cuda.is_available()
Expand All @@ -16,7 +16,7 @@
TEST_CUDNN = TEST_CUDA and torch.backends.cudnn.is_acceptable(torch.tensor(1., device=CUDA_DEVICE))
TEST_CUDNN_VERSION = torch.backends.cudnn.version() if TEST_CUDNN else 0

CUDA11OrLater = torch.version.cuda and distutils.version.LooseVersion(torch.version.cuda) >= "11.0.0"
CUDA11OrLater = torch.version.cuda and LooseVersion(torch.version.cuda) >= "11.0.0"
CUDA9 = torch.version.cuda and torch.version.cuda.startswith('9.')
SM53OrLater = torch.cuda.is_available() and torch.cuda.get_device_capability() >= (5, 3)

Expand Down
8 changes: 4 additions & 4 deletions torch/testing/_internal/common_methods_invocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
torch_to_numpy_dtype_dict, slowTest, TEST_WITH_ASAN, _wrap_warn_once,
GRADCHECK_NONDET_TOL,)

from setuptools import distutils
from distutils.version import LooseVersion

if TEST_SCIPY:
import scipy.special
Expand Down Expand Up @@ -6172,11 +6172,11 @@ def gradcheck_wrapper_triangular_input(op, input, *args, upper=False, **kwargs):
skips=(
# Reference: https://github.com/pytorch/pytorch/pull/49155#issuecomment-742664611
SkipInfo('TestUnaryUfuncs', 'test_reference_numerics_extremal',
active_if=TEST_SCIPY and distutils.version.LooseVersion(scipy.__version__) < "1.4.0"),
active_if=TEST_SCIPY and LooseVersion(scipy.__version__) < "1.4.0"),
SkipInfo('TestUnaryUfuncs', 'test_reference_numerics_hard',
active_if=TEST_SCIPY and distutils.version.LooseVersion(scipy.__version__) < "1.4.0"),
active_if=TEST_SCIPY and LooseVersion(scipy.__version__) < "1.4.0"),
SkipInfo('TestUnaryUfuncs', 'test_reference_numerics_normal',
active_if=TEST_SCIPY and distutils.version.LooseVersion(scipy.__version__) < "1.4.0"),
active_if=TEST_SCIPY and LooseVersion(scipy.__version__) < "1.4.0"),
)),
UnaryUfuncInfo('lgamma',
ref=reference_lgamma if TEST_SCIPY else _NOTHING,
Expand Down