Skip to content

Commit 2b74165

Browse files
committed
Update on "Deprecate old TORCH_VERSION variables"
**Summary:** This commit deprecates the following variables: ``` # Always True TORCH_VERSION_AT_LEAST_2_6 TORCH_VERSION_AT_LEAST_2_5 TORCH_VERSION_AT_LEAST_2_4 TORCH_VERSION_AT_LEAST_2_3 TORCH_VERSION_AT_LEAST_2_2 # TORCH_VERSION_AFTER* was confusing to users TORCH_VERSION_AFTER_2_5 TORCH_VERSION_AFTER_2_4 TORCH_VERSION_AFTER_2_3 TORCH_VERSION_AFTER_2_2 ``` As of this commit, the latest released version of PyTorch is 2.8, which means the oldest pytorch version we support is now 2.6 since we only support 3 of the latest releases. The next commit will remove usages of all of these variables from within torchao. **Test Plan:** ``` python test/test_utils.py -k torch_version_deprecation ``` [ghstack-poisoned]
1 parent ccb28b4 commit 2b74165

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

test/test_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def test_torch_version_at_least(self):
3838

3939
def test_torch_version_deprecation(self):
4040
"""
41-
Test that TORCH_VERSION_AT_LEAST_2_6 and before and TORCH_VERSION_AFTER*
42-
trigger a deprecation warning.
41+
Test that TORCH_VERSION_AT_LEAST* and TORCH_VERSION_AFTER*
42+
trigger deprecation warnings on use, not on import.
4343
"""
4444
# Reset deprecation warning state, otherwise we won't log warnings here
4545
warnings.resetwarnings()
@@ -56,9 +56,13 @@ def test_torch_version_deprecation(self):
5656
TORCH_VERSION_AT_LEAST_2_4,
5757
TORCH_VERSION_AT_LEAST_2_5,
5858
TORCH_VERSION_AT_LEAST_2_6,
59+
TORCH_VERSION_AT_LEAST_2_7,
60+
TORCH_VERSION_AT_LEAST_2_8,
5961
)
6062

6163
deprecated_api_to_name = [
64+
(TORCH_VERSION_AT_LEAST_2_8, "TORCH_VERSION_AT_LEAST_2_8"),
65+
(TORCH_VERSION_AT_LEAST_2_7, "TORCH_VERSION_AT_LEAST_2_7"),
6266
(TORCH_VERSION_AT_LEAST_2_6, "TORCH_VERSION_AT_LEAST_2_6"),
6367
(TORCH_VERSION_AT_LEAST_2_5, "TORCH_VERSION_AT_LEAST_2_5"),
6468
(TORCH_VERSION_AT_LEAST_2_4, "TORCH_VERSION_AT_LEAST_2_4"),

torchao/utils.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ def torch_version_at_least(min_version):
379379

380380

381381
def _deprecated_torch_version_at_least(version_str: str) -> str:
382+
"""
383+
Wrapper for existing TORCH_VERSION_AT_LEAST* variables that will log
384+
a deprecation warning if the variable is used.
385+
"""
382386
version_str_var_name = "_".join(version_str.split(".")[:2])
383387
deprecation_msg = f"TORCH_VERSION_AT_LEAST_{version_str_var_name} is deprecated and will be removed in torchao 0.14.0"
384388
return _BoolDeprecationWrapper(
@@ -388,6 +392,10 @@ def _deprecated_torch_version_at_least(version_str: str) -> str:
388392

389393

390394
def _deprecated_torch_version_after(version_str: str) -> str:
395+
"""
396+
Wrapper for existing TORCH_VERSION_AFTER* variables that will log
397+
a deprecation warning if the variable is used.
398+
"""
391399
bool_value = is_fbcode() or version("torch") >= version_str
392400
version_str_var_name = "_".join(version_str.split(".")[:2])
393401
deprecation_msg = f"TORCH_VERSION_AFTER_{version_str_var_name} is deprecated and will be removed in torchao 0.14.0"
@@ -411,10 +419,9 @@ def __eq__(self, other):
411419
return bool(self) == bool(other)
412420

413421

414-
TORCH_VERSION_AT_LEAST_2_8 = torch_version_at_least("2.8.0")
415-
TORCH_VERSION_AT_LEAST_2_7 = torch_version_at_least("2.7.0")
416-
417-
# Deprecated
422+
# Deprecated, use `torch_version_at_least` directly instead
423+
TORCH_VERSION_AT_LEAST_2_8 = _deprecated_torch_version_at_least("2.8.0")
424+
TORCH_VERSION_AT_LEAST_2_7 = _deprecated_torch_version_at_least("2.7.0")
418425
TORCH_VERSION_AT_LEAST_2_6 = _deprecated_torch_version_at_least("2.6.0")
419426
TORCH_VERSION_AT_LEAST_2_5 = _deprecated_torch_version_at_least("2.5.0")
420427
TORCH_VERSION_AT_LEAST_2_4 = _deprecated_torch_version_at_least("2.4.0")

0 commit comments

Comments
 (0)