Skip to content

Commit 81ea7a4

Browse files
vfdev-5pytorchmergebot
authored andcommitted
Replaced deprecated pkg_resources.packaging with packaging module (#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: #113023 Approved by: https://github.com/Skylion007
1 parent 67256d5 commit 81ea7a4

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

tools/dynamo/verify_dynamo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import traceback
66
import warnings
77

8-
from pkg_resources import packaging
8+
import packaging.version
99

1010
MIN_CUDA_VERSION = packaging.version.parse("11.6")
1111
MIN_ROCM_VERSION = packaging.version.parse("5.4")

torch/utils/cpp_extension.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from torch.torch_version import TorchVersion
2626

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

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

405405
cuda_str_version = cuda_version.group(1)
406406
cuda_ver = packaging.version.parse(cuda_str_version)
407+
if torch.version.cuda is None:
408+
return
409+
407410
torch_cuda_version = packaging.version.parse(torch.version.cuda)
408411
if cuda_ver != torch_cuda_version:
409412
# major/minor attributes are only available in setuptools>=49.4.0
@@ -2345,8 +2348,7 @@ def sanitize_flags(flags):
23452348
# Compilation will work on earlier CUDA versions but header file
23462349
# dependencies are not correctly computed.
23472350
required_cuda_version = packaging.version.parse('11.0')
2348-
has_cuda_version = torch.version.cuda is not None
2349-
if has_cuda_version and packaging.version.parse(torch.version.cuda) >= required_cuda_version:
2351+
if torch.version.cuda is not None and packaging.version.parse(torch.version.cuda) >= required_cuda_version:
23502352
cuda_compile_rule.append(' depfile = $out.d')
23512353
cuda_compile_rule.append(' deps = gcc')
23522354
# Note: non-system deps with nvcc are only supported

0 commit comments

Comments
 (0)