Skip to content

Commit 030a5be

Browse files
kylesayrsdsikka
andauthored
[Tests] GPTQ Actorder Resolution Tests (#1468)
## Purpose ## * Clarify behavior introduced by #1453 ## Changes ## * Remove `TestQuantizationRegistered` test, which is less necessary that it was before * Add `test_actorder_resolution`, which demonstrates and regression tests behavior related to resolving the `actorder` argument --------- Signed-off-by: Kyle Sayers <[email protected]> Co-authored-by: Dipika Sikka <[email protected]>
1 parent 4888f34 commit 030a5be

File tree

1 file changed

+68
-18
lines changed

1 file changed

+68
-18
lines changed
Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,76 @@
1-
import unittest
1+
from contextlib import nullcontext
22

33
import pytest
44

5-
from llmcompressor.modifiers.factory import ModifierFactory
6-
from llmcompressor.modifiers.quantization import QuantizationModifier
7-
from tests.llmcompressor.modifiers.conf import setup_modifier_factory
5+
from llmcompressor.modifiers.quantization import GPTQModifier
86

97

10-
@pytest.mark.unit
11-
class TestQuantizationRegistered(unittest.TestCase):
12-
def setUp(self):
13-
setup_modifier_factory()
14-
self.kwargs = dict(
15-
index=0, group="quantization", start=2.0, end=-1.0, config_groups={}
8+
@pytest.fixture
9+
def q_config_kwargs(config_0, config_1):
10+
return dict(
11+
config_groups=dict(
12+
group_0=dict(
13+
targets=["Linear"],
14+
input_activations=dict(num_bits=8, symmetric=False, strategy="token"),
15+
weights=dict(
16+
num_bits=4,
17+
symmetric=True,
18+
strategy="group",
19+
group_size=128,
20+
actorder=config_0,
21+
),
22+
),
23+
group_1=dict(
24+
targets=["Linear"],
25+
input_activations=dict(num_bits=8, symmetric=False, strategy="token"),
26+
weights=dict(
27+
num_bits=4,
28+
symmetric=True,
29+
strategy="group",
30+
group_size=128,
31+
actorder=config_1,
32+
),
33+
),
1634
)
35+
)
1736

18-
def test_quantization_registered(self):
19-
quant_obj = ModifierFactory.create(
20-
type_="QuantizationModifier",
21-
allow_experimental=False,
22-
allow_registered=True,
23-
**self.kwargs,
24-
)
2537

26-
self.assertIsInstance(quant_obj, QuantizationModifier)
38+
@pytest.mark.parametrize(
39+
"has_actorder,actorder,config_0,config_1,expected_0,expected_1",
40+
[
41+
# defaults to None if nothing provided
42+
(False, None, None, None, None, None),
43+
# modifier overrides config if no config provided
44+
(True, "group", None, None, "group", "group"),
45+
# modifier overrides if config partially matches anyways
46+
(True, "group", None, "group", "group", "group"),
47+
(True, "group", "group", None, "group", "group"),
48+
# modifier errors if conflict with config
49+
(True, "group", None, "static", "error", "error"),
50+
(True, "group", "static", None, "error", "error"),
51+
# modifier does not override if not provided
52+
(False, "N/A", None, None, None, None),
53+
(False, "N/A", None, "static", None, "static"),
54+
(False, "N/A", "static", None, "static", None),
55+
(False, "N/A", "static", "static", "static", "static"),
56+
(False, "N/A", None, "group", None, "group"),
57+
(False, "N/A", "group", None, "group", None),
58+
(False, "N/A", "group", "group", "group", "group"),
59+
],
60+
)
61+
def test_actorder_resolution(
62+
has_actorder, actorder, q_config_kwargs, expected_0, expected_1
63+
):
64+
if has_actorder:
65+
modifier = GPTQModifier(**q_config_kwargs, actorder=actorder)
66+
else:
67+
modifier = GPTQModifier(**q_config_kwargs)
68+
69+
with pytest.raises(ValueError) if expected_0 == "error" else nullcontext():
70+
resolved = modifier.resolve_quantization_config()
71+
72+
if expected_0 != "error":
73+
assert resolved.config_groups["group_0"].input_activations.actorder is None
74+
assert resolved.config_groups["group_0"].weights.actorder == expected_0
75+
assert resolved.config_groups["group_1"].input_activations.actorder is None
76+
assert resolved.config_groups["group_1"].weights.actorder == expected_1

0 commit comments

Comments
 (0)