26
26
quantize_weight ,
27
27
)
28
28
from llmcompressor .modifiers .quantization .quantization import QuantizationMixin
29
+ from llmcompressor .sentinel import Sentinel
29
30
from llmcompressor .utils .metric_logging import CompressionLogger
30
31
31
32
__all__ = ["GPTQModifier" ]
@@ -109,7 +110,7 @@ class GPTQModifier(Modifier, QuantizationMixin):
109
110
sequential_targets : Union [str , List [str ], None ] = None
110
111
block_size : int = 128
111
112
dampening_frac : Optional [float ] = 0.01
112
- actorder : Optional [ActivationOrdering ] = None
113
+ actorder : Optional [Union [ ActivationOrdering , Sentinel ] ] = None
113
114
offload_hessians : bool = False
114
115
115
116
# private variables
@@ -131,23 +132,29 @@ def validate_sequential_update(cls, value: bool) -> bool:
131
132
def resolve_quantization_config (self ) -> QuantizationConfig :
132
133
config = super ().resolve_quantization_config ()
133
134
134
- # Resolve config with `self.actorder`
135
+ def resolve_actorder (existing ):
136
+ # sentinel default only overrides if existing is None
137
+ if self .actorder == Sentinel ("static" ):
138
+ return ActivationOrdering .STATIC if existing is None else existing
139
+
140
+ # user-provided value always attempts to override
141
+ if self .actorder is not None :
142
+ if existing is None or self .actorder == existing :
143
+ return self .actorder
144
+ raise ValueError (
145
+ "Cannot resolve activation ordering when both "
146
+ "`GPTQModifier.actorder` and `QuantizationScheme.actorder` "
147
+ "are provided and differ. Either set `GPTQModifier.actorder = "
148
+ "None` or remove `actorder` from config groups."
149
+ )
150
+
151
+ # setting `GPTQModifier.actorder = None` does nothing
152
+ return existing
153
+
135
154
for scheme in config .config_groups .values ():
136
- assert isinstance (scheme , QuantizationScheme ) # (1)
155
+ assert isinstance (scheme , QuantizationScheme )
137
156
if scheme .weights is not None :
138
- existing = scheme .weights .actorder
139
- assert isinstance (existing , (ActivationOrdering , type (None ))) # (2)
140
- if existing is not None and existing != self .actorder :
141
- raise ValueError (
142
- "Cannot resolve activation ordering when both "
143
- "`GPTQModifier.actorder` and `QuantizationScheme.actorder` "
144
- "both are provided. Either set `GPTQModifier.actorder = None` "
145
- "or remove `actorder` from config groups"
146
- )
147
- scheme .weights .actorder = self .actorder
148
-
149
- # (1) QuantizationConfig.model_post_init
150
- # (2) QuantizationScheme.validate_actorder
157
+ scheme .weights .actorder = resolve_actorder (scheme .weights .actorder )
151
158
152
159
return config
153
160
0 commit comments