Skip to content

Commit 22f9d31

Browse files
authored
Clarifying the meaning of VERSION in AOBaseConfig (#2635)
Summary: the VERSION means default version for child configs, it should never change. Also added test to enforce this Test Plan: python test/core/test_config.py Reviewers: Subscribers: Tasks: Tags:
1 parent 7b0671c commit 22f9d31

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

test/quantization/test_config_serialization.py renamed to test/core/test_config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,19 @@ def test_version_mismatch():
187187
config_from_dict(reconstructable)
188188

189189

190+
def test_default_version():
191+
"""Making sure the default version for a new config inheriting from AOBaseConfig is always 1
192+
because it's the default VERSION that all children has when they haven't explicitly
193+
defined a VERSION class variable
194+
"""
195+
196+
@dataclass
197+
class DummyConfig(AOBaseConfig):
198+
pass
199+
200+
config = DummyConfig()
201+
assert config.VERSION == 1, "Default version must be 1"
202+
203+
190204
if __name__ == "__main__":
191205
pytest.main([__file__])

torchao/core/config.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"ALLOWED_AO_MODULES",
2121
]
2222

23+
# the default version for all configs, should never change
24+
_DEFAULT_VERSION = 1
25+
2326

2427
class AOBaseConfig(abc.ABC):
2528
"""
@@ -46,8 +49,16 @@ def _transform(
4649
4750
"""
4851

49-
# Base Version of a config
50-
VERSION: ClassVar[int] = 1
52+
"""
53+
Note: this is not the version of AOBaseConfig, but the default version for all child configs
54+
inheriting from AOBaseConfig, and it should be `_DEFAULT_VERSION` and never change
55+
this is making sure all configs has a version defined, when they need to bump the version
56+
they have to define a class variable VERSION for the child config to overwrite the default VERSION
57+
that's defined here. Different child configs will maintain their own VERSION.
58+
59+
default Version of a config, should never change
60+
"""
61+
VERSION: ClassVar[int] = _DEFAULT_VERSION
5162

5263

5364
class VersionMismatchError(Exception):

0 commit comments

Comments
 (0)