Skip to content

Commit b01514c

Browse files
authored
Add serialization support for AOPerModuleConfig (#2186)
Summary: att Test Plan: python test/quantization/test_config_serialization.py Reviewers: Subscribers: Tasks: Tags:
1 parent 8369268 commit b01514c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

test/quantization/test_config_serialization.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD 3-Clause license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
17
import json
28
import os
39
import tempfile
@@ -14,6 +20,7 @@
1420
config_to_dict,
1521
)
1622
from torchao.quantization.quant_api import (
23+
AOPerModuleConfig,
1724
Float8DynamicActivationFloat8WeightConfig,
1825
Float8WeightOnlyConfig,
1926
FPXWeightOnlyConfig,
@@ -63,6 +70,14 @@
6370
# Sparsity configs
6471
SemiSparseWeightConfig(),
6572
BlockSparseWeightConfig(blocksize=128),
73+
AOPerModuleConfig({}),
74+
AOPerModuleConfig({"_default": Int4WeightOnlyConfig(), "linear1": None}),
75+
AOPerModuleConfig(
76+
{
77+
"linear1": Int4WeightOnlyConfig(),
78+
"linear2": Int8DynamicActivationInt4WeightConfig(),
79+
}
80+
),
6681
]
6782

6883

torchao/core/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@ def config_from_dict(data: Dict[str, Any]) -> AOBaseConfig:
255255
else item
256256
for item in value
257257
]
258+
elif isinstance(value, dict):
259+
# Handle dicts of possible configs
260+
processed_data[key] = {
261+
k: config_from_dict(v)
262+
if isinstance(v, dict) and "_type" in v and "_data" in v
263+
else v
264+
for k, v in value.items()
265+
}
258266
else:
259267
processed_data[key] = value
260268

0 commit comments

Comments
 (0)