Skip to content

Commit

Permalink
Replaced deprecated pkg_resources.packaging with packaging module (py…
Browse files Browse the repository at this point in the history
…torch#113023)

Usage of `from pkg_resources import packaging` leads to a deprecation warning:
```
DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
```
and in strict tests where warnings are errors, this leads to CI breaks, e.g.: pytorch/vision#8092

Replacing `pkg_resources.package` with `package` as it is now a pytorch dependency:
https://github.com/pytorch/pytorch/blob/fa9045a8725214c05ae4dcec5a855820b861155e/requirements.txt#L19
Pull Request resolved: pytorch#113023
Approved by: https://github.com/Skylion007
  • Loading branch information
vfdev-5 authored and Skylion007 committed Nov 14, 2023
1 parent 20177c5 commit 02a891c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tools/dynamo/verify_dynamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import traceback
import warnings

from pkg_resources import packaging
import packaging.version

MIN_CUDA_VERSION = packaging.version.parse("11.6")
MIN_ROCM_VERSION = packaging.version.parse("5.4")
Expand Down
8 changes: 5 additions & 3 deletions torch/utils/cpp_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from torch.torch_version import TorchVersion

from setuptools.command.build_ext import build_ext
from pkg_resources import packaging # type: ignore[attr-defined]
import packaging.version

IS_WINDOWS = sys.platform == 'win32'
IS_MACOS = sys.platform.startswith('darwin')
Expand Down Expand Up @@ -404,6 +404,9 @@ def _check_cuda_version(compiler_name: str, compiler_version: TorchVersion) -> N

cuda_str_version = cuda_version.group(1)
cuda_ver = packaging.version.parse(cuda_str_version)
if torch.version.cuda is None:
return

torch_cuda_version = packaging.version.parse(torch.version.cuda)
if cuda_ver != torch_cuda_version:
# major/minor attributes are only available in setuptools>=49.4.0
Expand Down Expand Up @@ -2345,8 +2348,7 @@ def sanitize_flags(flags):
# Compilation will work on earlier CUDA versions but header file
# dependencies are not correctly computed.
required_cuda_version = packaging.version.parse('11.0')
has_cuda_version = torch.version.cuda is not None
if has_cuda_version and packaging.version.parse(torch.version.cuda) >= required_cuda_version:
if torch.version.cuda is not None and packaging.version.parse(torch.version.cuda) >= required_cuda_version:
cuda_compile_rule.append(' depfile = $out.d')
cuda_compile_rule.append(' deps = gcc')
# Note: non-system deps with nvcc are only supported
Expand Down

0 comments on commit 02a891c

Please sign in to comment.