Skip to content

Commit e8c4d09

Browse files
authored
Remove old TORCH_VERSION variables (#3146)
* Remove config functions like `int4_weight_only` **Summary:** As a follow-up to #2994, this commit removes all quantization functions that were used as configs. These functions were deprecated in 0.14.0 and will be removed in the next release, 0.15.0. **Test Plan:** CI [ghstack-poisoned] * 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-poisoned] * Update base for Update on "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-poisoned] * Update base for Update on "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-poisoned]
1 parent cfbe695 commit e8c4d09

File tree

2 files changed

+0
-116
lines changed

2 files changed

+0
-116
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 & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@
3535
"is_sm_at_least_100",
3636
"is_package_at_least",
3737
"DummyModule",
38-
# Deprecated
39-
"TORCH_VERSION_AT_LEAST_2_2",
40-
"TORCH_VERSION_AT_LEAST_2_3",
41-
"TORCH_VERSION_AT_LEAST_2_4",
42-
"TORCH_VERSION_AT_LEAST_2_5",
43-
"TORCH_VERSION_AT_LEAST_2_6",
44-
"TORCH_VERSION_AT_LEAST_2_7",
45-
"TORCH_VERSION_AFTER_2_2",
46-
"TORCH_VERSION_AFTER_2_3",
47-
"TORCH_VERSION_AFTER_2_4",
48-
"TORCH_VERSION_AFTER_2_5",
4938
]
5039

5140

@@ -379,61 +368,6 @@ def torch_version_at_least(min_version):
379368
return parse_version(torch.__version__) >= parse_version(min_version)
380369

381370

382-
def _deprecated_torch_version_at_least(version_str: str) -> str:
383-
"""
384-
Wrapper for existing TORCH_VERSION_AT_LEAST* variables that will log
385-
a deprecation warning if the variable is used.
386-
"""
387-
version_str_var_name = "_".join(version_str.split(".")[:2])
388-
deprecation_msg = f"TORCH_VERSION_AT_LEAST_{version_str_var_name} is deprecated and will be removed in torchao 0.14.0"
389-
return _BoolDeprecationWrapper(
390-
torch_version_at_least(version_str),
391-
deprecation_msg,
392-
)
393-
394-
395-
def _deprecated_torch_version_after(version_str: str) -> str:
396-
"""
397-
Wrapper for existing TORCH_VERSION_AFTER* variables that will log
398-
a deprecation warning if the variable is used.
399-
"""
400-
bool_value = is_fbcode() or version("torch") >= version_str
401-
version_str_var_name = "_".join(version_str.split(".")[:2])
402-
deprecation_msg = f"TORCH_VERSION_AFTER_{version_str_var_name} is deprecated and will be removed in torchao 0.14.0"
403-
return _BoolDeprecationWrapper(bool_value, deprecation_msg)
404-
405-
406-
class _BoolDeprecationWrapper:
407-
"""
408-
A deprecation wrapper that logs a warning when the given bool value is accessed.
409-
"""
410-
411-
def __init__(self, bool_value: bool, msg: str):
412-
self.bool_value = bool_value
413-
self.msg = msg
414-
415-
def __bool__(self):
416-
warnings.warn(self.msg)
417-
return self.bool_value
418-
419-
def __eq__(self, other):
420-
return bool(self) == bool(other)
421-
422-
423-
# Deprecated, use `torch_version_at_least` directly instead
424-
TORCH_VERSION_AT_LEAST_2_8 = _deprecated_torch_version_at_least("2.8.0")
425-
TORCH_VERSION_AT_LEAST_2_7 = _deprecated_torch_version_at_least("2.7.0")
426-
TORCH_VERSION_AT_LEAST_2_6 = _deprecated_torch_version_at_least("2.6.0")
427-
TORCH_VERSION_AT_LEAST_2_5 = _deprecated_torch_version_at_least("2.5.0")
428-
TORCH_VERSION_AT_LEAST_2_4 = _deprecated_torch_version_at_least("2.4.0")
429-
TORCH_VERSION_AT_LEAST_2_3 = _deprecated_torch_version_at_least("2.3.0")
430-
TORCH_VERSION_AT_LEAST_2_2 = _deprecated_torch_version_at_least("2.2.0")
431-
TORCH_VERSION_AFTER_2_5 = _deprecated_torch_version_after("2.5.0.dev")
432-
TORCH_VERSION_AFTER_2_4 = _deprecated_torch_version_after("2.4.0.dev")
433-
TORCH_VERSION_AFTER_2_3 = _deprecated_torch_version_after("2.3.0.dev")
434-
TORCH_VERSION_AFTER_2_2 = _deprecated_torch_version_after("2.2.0.dev")
435-
436-
437371
class _ConfigDeprecationWrapper:
438372
"""
439373
A deprecation wrapper that directs users from a deprecated "config function"

0 commit comments

Comments
 (0)