Skip to content

Commit 1c0e5cb

Browse files
authored
Get rid of dependency on distutils (#2540)
`distutils` is deprecated and removed from Python 3.12. We don't really need it since the regex is already producing a well formatted version number already here. Using `packaging.Version` should be good enough.
1 parent 4bb417e commit 1c0e5cb

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

coremltools/optimize/torch/_utils/torch_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import operator as _operator
1111
import re as _re
1212
from contextlib import contextmanager
13-
from distutils.version import StrictVersion as _StrictVersion
13+
from packaging.version import Version as _Version
1414
from typing import Any as _Any
1515
from typing import Dict as _Dict
1616
from typing import List as _List
@@ -243,7 +243,7 @@ def get_torch_version(version):
243243
"""
244244
version_regex = r"\d+\.\d+\.\d+"
245245
version = _re.search(version_regex, str(version)).group(0)
246-
return _StrictVersion(version)
246+
return _Version(version)
247247

248248

249249
def normalize_fsdp_module_name(module_name: str) -> str:

coremltools/optimize/torch/quantization/modules/observers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Implementation for EMAMinMaxObserver has been adapted from
1010
# https://github.com/ModelTC/MQBench/blob/main/mqbench/observer.py
1111

12-
import distutils as _distutils
12+
from packaging.version import Version as _Version
1313
from typing import Any as _Any
1414
from typing import Dict as _Dict
1515
from typing import Optional as _Optional
@@ -76,7 +76,7 @@ def __init__(
7676
is_dynamic: bool = False,
7777
):
7878
kwargs = {}
79-
if _get_torch_version(_torch.__version__) >= _distutils.version.StrictVersion("2.2"):
79+
if _get_torch_version(_torch.__version__) >= _Version("2.2"):
8080
kwargs["is_dynamic"] = is_dynamic
8181

8282
super(CustomObserverBase, self).__init__(

0 commit comments

Comments
 (0)