Skip to content

Commit

Permalink
Update distutils.Version to packaging.version due to the deprecation … (
Browse files Browse the repository at this point in the history
#107207)

Update distutils.Version to packaging.version due to the deprecation warning.

```python
/root/Git.d/pytorch/pytorch/torch/testing/_internal/common_methods_invocations.py:17136: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  active_if=TEST_SCIPY and LooseVersion(scipy.__version__) < "1.4.0"),
/root/Git.d/pytorch/pytorch/torch/testing/_internal/common_methods_invocations.py:17138: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  active_if=TEST_SCIPY and LooseVersion(scipy.__version__) < "1.4.0"),
/root/Git.d/pytorch/pytorch/torch/testing/_internal/common_methods_invocations.py:17140: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  active_if=TEST_SCIPY and LooseVersion(scipy.__version__) < "1.4.0"),
```
Pull Request resolved: #107207
Approved by: https://github.com/soulitzer
  • Loading branch information
FFFrog authored and pytorchmergebot committed Aug 17, 2023
1 parent a98f745 commit e108f33
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
6 changes: 4 additions & 2 deletions test/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import tempfile
import time
from datetime import datetime
from distutils.version import LooseVersion
from typing import Any, cast, Dict, List, NamedTuple, Optional, Union

import pkg_resources

import torch
import torch.distributed as dist
from packaging import version
from torch.multiprocessing import current_process, get_context
from torch.testing._internal.common_utils import (
FILE_SCHEMA,
Expand Down Expand Up @@ -1366,7 +1366,9 @@ def get_selected_tests(options) -> List[ShardedTest]:
options.exclude.extend(DISTRIBUTED_TESTS)

# these tests failing in CUDA 11.6 temporary disabling. issue https://github.com/pytorch/pytorch/issues/75375
if torch.version.cuda is not None and LooseVersion(torch.version.cuda) >= "11.6":
if torch.version.cuda is not None and version.parse(
torch.version.cuda
) >= version.parse("11.6"):
options.exclude.extend(["distributions/test_constraints"])

selected_tests = exclude_tests(options.exclude, selected_tests)
Expand Down
4 changes: 2 additions & 2 deletions test/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from torch.testing._internal.common_cuda import TEST_CUDA
from numbers import Number
from typing import Dict, Any
from distutils.version import LooseVersion
from packaging import version
from torch.testing._internal.common_cuda import \
(SM53OrLater, SM80OrLater)
from torch.testing._internal.common_device_type import \
Expand Down Expand Up @@ -55,7 +55,7 @@ def _op_supports_any_sparse(op):
gradcheck = functools.partial(gradcheck, check_batched_grad=False)

CUSPARSE_SPMM_COMPLEX128_SUPPORTED = (
IS_WINDOWS and torch.version.cuda and LooseVersion(torch.version.cuda) > "11.2"
IS_WINDOWS and torch.version.cuda and version.parse(torch.version.cuda) > version.parse("11.2")
) or (not IS_WINDOWS and not TEST_WITH_ROCM)

def all_sparse_layouts(test_name='layout', include_strided=False):
Expand Down
7 changes: 3 additions & 4 deletions test/test_spectral_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from torch.testing._internal.common_cuda import SM53OrLater
from torch._prims_common import corresponding_complex_dtype

from setuptools import distutils
from typing import Optional, List
from packaging import version


if TEST_NUMPY:
Expand All @@ -38,11 +38,10 @@
except ModuleNotFoundError:
pass

LooseVersion = distutils.version.LooseVersion
REFERENCE_NORM_MODES = (
(None, "forward", "backward", "ortho")
if LooseVersion(np.__version__) >= '1.20.0' and (
not has_scipy_fft or LooseVersion(scipy.__version__) >= '1.6.0')
if version.parse(np.__version__) >= version.parse('1.20.0') and (
not has_scipy_fft or version.parse(scipy.__version__) >= version.parse('1.6.0'))
else (None, "ortho"))


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 @@ -44,7 +44,7 @@

from torch.utils._pytree import tree_flatten

from distutils.version import LooseVersion
from packaging import version

from torch.testing._internal.opinfo.core import ( # noqa: F401
L,
Expand Down Expand Up @@ -17134,11 +17134,11 @@ def reference_flatten(input, start_dim=0, end_dim=-1):
skips=(
# Reference: https://github.com/pytorch/pytorch/pull/49155#issuecomment-742664611
DecorateInfo(unittest.skip("Skipped!"), 'TestUnaryUfuncs', 'test_reference_numerics_extremal',
active_if=TEST_SCIPY and LooseVersion(scipy.__version__) < "1.4.0"),
active_if=TEST_SCIPY and version.parse(scipy.__version__) < version.parse("1.4.0")),
DecorateInfo(unittest.skip("Skipped!"), 'TestUnaryUfuncs', 'test_reference_numerics_large',
active_if=TEST_SCIPY and LooseVersion(scipy.__version__) < "1.4.0"),
active_if=TEST_SCIPY and version.parse(scipy.__version__) < version.parse("1.4.0")),
DecorateInfo(unittest.skip("Skipped!"), 'TestUnaryUfuncs', 'test_reference_numerics_small',
active_if=TEST_SCIPY and LooseVersion(scipy.__version__) < "1.4.0"),
active_if=TEST_SCIPY and version.parse(scipy.__version__) < version.parse("1.4.0")),
)),
OpInfo("nn.functional.smooth_l1_loss",
ref=reference_smooth_l1_loss,
Expand Down

0 comments on commit e108f33

Please sign in to comment.