2626 quantize_weight ,
2727)
2828from llmcompressor .modifiers .quantization .quantization import QuantizationMixin
29+ from llmcompressor .sentinel import Sentinel
2930from llmcompressor .utils .metric_logging import CompressionLogger
3031
3132__all__ = ["GPTQModifier" ]
@@ -109,7 +110,7 @@ class GPTQModifier(Modifier, QuantizationMixin):
109110 sequential_targets : Union [str , List [str ], None ] = None
110111 block_size : int = 128
111112 dampening_frac : Optional [float ] = 0.01
112- actorder : Optional [ActivationOrdering ] = None
113+ actorder : Optional [Union [ ActivationOrdering , Sentinel ] ] = None
113114 offload_hessians : bool = False
114115
115116 # private variables
@@ -131,23 +132,29 @@ def validate_sequential_update(cls, value: bool) -> bool:
131132 def resolve_quantization_config (self ) -> QuantizationConfig :
132133 config = super ().resolve_quantization_config ()
133134
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+
135154 for scheme in config .config_groups .values ():
136- assert isinstance (scheme , QuantizationScheme ) # (1)
155+ assert isinstance (scheme , QuantizationScheme )
137156 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 )
151158
152159 return config
153160
0 commit comments