Skip to content

Commit 73760a3

Browse files
committed
Remove old TORCH_VERSION variables
**Summary:** As a follow-up to #2719, which deprecated these variables in 0.13.0, we remove them now in the next release 0.15.0. **Test Plan:** CI ghstack-source-id: 7c81628 Pull Request resolved: #3146
1 parent 69d38c0 commit 73760a3

File tree

2 files changed

+0
-117
lines changed

2 files changed

+0
-117
lines changed

test/test_utils.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# This source code is licensed under the BSD 3-Clause license found in the
55
# LICENSE file in the root directory of this source tree.
66
import unittest
7-
import warnings
87
from unittest.mock import patch
98

109
import torch
@@ -37,55 +36,6 @@ def test_torch_version_at_least(self):
3736
f"Failed for torch.__version__={torch_version}, comparing with {compare_version}",
3837
)
3938

40-
def test_torch_version_deprecation(self):
41-
"""
42-
Test that TORCH_VERSION_AT_LEAST* and TORCH_VERSION_AFTER*
43-
trigger deprecation warnings on use, not on import.
44-
"""
45-
# Reset deprecation warning state, otherwise we won't log warnings here
46-
warnings.resetwarnings()
47-
48-
# Importing and referencing should not trigger deprecation warning
49-
with warnings.catch_warnings(record=True) as _warnings:
50-
from torchao.utils import (
51-
TORCH_VERSION_AFTER_2_2,
52-
TORCH_VERSION_AFTER_2_3,
53-
TORCH_VERSION_AFTER_2_4,
54-
TORCH_VERSION_AFTER_2_5,
55-
TORCH_VERSION_AT_LEAST_2_2,
56-
TORCH_VERSION_AT_LEAST_2_3,
57-
TORCH_VERSION_AT_LEAST_2_4,
58-
TORCH_VERSION_AT_LEAST_2_5,
59-
TORCH_VERSION_AT_LEAST_2_6,
60-
TORCH_VERSION_AT_LEAST_2_7,
61-
TORCH_VERSION_AT_LEAST_2_8,
62-
)
63-
64-
deprecated_api_to_name = [
65-
(TORCH_VERSION_AT_LEAST_2_8, "TORCH_VERSION_AT_LEAST_2_8"),
66-
(TORCH_VERSION_AT_LEAST_2_7, "TORCH_VERSION_AT_LEAST_2_7"),
67-
(TORCH_VERSION_AT_LEAST_2_6, "TORCH_VERSION_AT_LEAST_2_6"),
68-
(TORCH_VERSION_AT_LEAST_2_5, "TORCH_VERSION_AT_LEAST_2_5"),
69-
(TORCH_VERSION_AT_LEAST_2_4, "TORCH_VERSION_AT_LEAST_2_4"),
70-
(TORCH_VERSION_AT_LEAST_2_3, "TORCH_VERSION_AT_LEAST_2_3"),
71-
(TORCH_VERSION_AT_LEAST_2_2, "TORCH_VERSION_AT_LEAST_2_2"),
72-
(TORCH_VERSION_AFTER_2_5, "TORCH_VERSION_AFTER_2_5"),
73-
(TORCH_VERSION_AFTER_2_4, "TORCH_VERSION_AFTER_2_4"),
74-
(TORCH_VERSION_AFTER_2_3, "TORCH_VERSION_AFTER_2_3"),
75-
(TORCH_VERSION_AFTER_2_2, "TORCH_VERSION_AFTER_2_2"),
76-
]
77-
self.assertEqual(len(_warnings), 0)
78-
79-
# Accessing the boolean value should trigger deprecation warning
80-
with warnings.catch_warnings(record=True) as _warnings:
81-
for api, name in deprecated_api_to_name:
82-
num_warnings_before = len(_warnings)
83-
if api:
84-
pass
85-
regex = f"{name} is deprecated and will be removed"
86-
self.assertEqual(len(_warnings), num_warnings_before + 1)
87-
self.assertIn(regex, str(_warnings[-1].message))
88-
8939

9040
class TestTorchAOBaseTensor(unittest.TestCase):
9141
def test_print_arg_types(self):

torchao/utils.py

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import itertools
99
import re
1010
import time
11-
import warnings
1211
from functools import reduce
1312
from importlib.metadata import version
1413
from math import gcd
@@ -34,17 +33,6 @@
3433
"is_sm_at_least_90",
3534
"is_package_at_least",
3635
"DummyModule",
37-
# Deprecated
38-
"TORCH_VERSION_AT_LEAST_2_2",
39-
"TORCH_VERSION_AT_LEAST_2_3",
40-
"TORCH_VERSION_AT_LEAST_2_4",
41-
"TORCH_VERSION_AT_LEAST_2_5",
42-
"TORCH_VERSION_AT_LEAST_2_6",
43-
"TORCH_VERSION_AT_LEAST_2_7",
44-
"TORCH_VERSION_AFTER_2_2",
45-
"TORCH_VERSION_AFTER_2_3",
46-
"TORCH_VERSION_AFTER_2_4",
47-
"TORCH_VERSION_AFTER_2_5",
4836
]
4937

5038

@@ -378,61 +366,6 @@ def torch_version_at_least(min_version):
378366
return parse_version(torch.__version__) >= parse_version(min_version)
379367

380368

381-
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-
"""
386-
version_str_var_name = "_".join(version_str.split(".")[:2])
387-
deprecation_msg = f"TORCH_VERSION_AT_LEAST_{version_str_var_name} is deprecated and will be removed in torchao 0.14.0"
388-
return _BoolDeprecationWrapper(
389-
torch_version_at_least(version_str),
390-
deprecation_msg,
391-
)
392-
393-
394-
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-
"""
399-
bool_value = is_fbcode() or version("torch") >= version_str
400-
version_str_var_name = "_".join(version_str.split(".")[:2])
401-
deprecation_msg = f"TORCH_VERSION_AFTER_{version_str_var_name} is deprecated and will be removed in torchao 0.14.0"
402-
return _BoolDeprecationWrapper(bool_value, deprecation_msg)
403-
404-
405-
class _BoolDeprecationWrapper:
406-
"""
407-
A deprecation wrapper that logs a warning when the given bool value is accessed.
408-
"""
409-
410-
def __init__(self, bool_value: bool, msg: str):
411-
self.bool_value = bool_value
412-
self.msg = msg
413-
414-
def __bool__(self):
415-
warnings.warn(self.msg)
416-
return self.bool_value
417-
418-
def __eq__(self, other):
419-
return bool(self) == bool(other)
420-
421-
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")
425-
TORCH_VERSION_AT_LEAST_2_6 = _deprecated_torch_version_at_least("2.6.0")
426-
TORCH_VERSION_AT_LEAST_2_5 = _deprecated_torch_version_at_least("2.5.0")
427-
TORCH_VERSION_AT_LEAST_2_4 = _deprecated_torch_version_at_least("2.4.0")
428-
TORCH_VERSION_AT_LEAST_2_3 = _deprecated_torch_version_at_least("2.3.0")
429-
TORCH_VERSION_AT_LEAST_2_2 = _deprecated_torch_version_at_least("2.2.0")
430-
TORCH_VERSION_AFTER_2_5 = _deprecated_torch_version_after("2.5.0.dev")
431-
TORCH_VERSION_AFTER_2_4 = _deprecated_torch_version_after("2.4.0.dev")
432-
TORCH_VERSION_AFTER_2_3 = _deprecated_torch_version_after("2.3.0.dev")
433-
TORCH_VERSION_AFTER_2_2 = _deprecated_torch_version_after("2.2.0.dev")
434-
435-
436369
"""
437370
Helper function for implementing aten op or torch function dispatch
438371
and dispatching to these implementations.

0 commit comments

Comments
 (0)