From 02a891c9dd6d191f71d4365304dae06e90d5d1c4 Mon Sep 17 00:00:00 2001 From: vfdev Date: Mon, 6 Nov 2023 20:26:27 +0000 Subject: [PATCH] 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.: https://github.com/pytorch/vision/pull/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: https://github.com/pytorch/pytorch/pull/113023 Approved by: https://github.com/Skylion007 --- tools/dynamo/verify_dynamo.py | 2 +- torch/utils/cpp_extension.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/dynamo/verify_dynamo.py b/tools/dynamo/verify_dynamo.py index 364773b7e1884d..016beff014530a 100644 --- a/tools/dynamo/verify_dynamo.py +++ b/tools/dynamo/verify_dynamo.py @@ -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") diff --git a/torch/utils/cpp_extension.py b/torch/utils/cpp_extension.py index ad5b494660c968..f9201e1249f400 100644 --- a/torch/utils/cpp_extension.py +++ b/torch/utils/cpp_extension.py @@ -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') @@ -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 @@ -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