From c6197ce2a9c1b3b02980f4be48796ed16c9fbe7a Mon Sep 17 00:00:00 2001 From: Kyle Sayers Date: Mon, 25 Nov 2024 09:31:36 -0500 Subject: [PATCH] Quantization Scheme Validation (#209) * add model validator to quantization scheme Signed-off-by: Kyle Sayers * allow dynamic weights Signed-off-by: Kyle Sayers --------- Signed-off-by: Kyle Sayers --- .../quantization/quant_scheme.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/compressed_tensors/quantization/quant_scheme.py b/src/compressed_tensors/quantization/quant_scheme.py index 47ce0a9b..3a8152da 100644 --- a/src/compressed_tensors/quantization/quant_scheme.py +++ b/src/compressed_tensors/quantization/quant_scheme.py @@ -13,14 +13,14 @@ # limitations under the License. from copy import deepcopy -from typing import List, Optional +from typing import Any, Dict, List, Optional from compressed_tensors.quantization.quant_args import ( QuantizationArgs, QuantizationStrategy, QuantizationType, ) -from pydantic import BaseModel +from pydantic import BaseModel, model_validator __all__ = [ @@ -47,6 +47,20 @@ class QuantizationScheme(BaseModel): input_activations: Optional[QuantizationArgs] = None output_activations: Optional[QuantizationArgs] = None + @model_validator(mode="after") + def validate_model_after(model: "QuantizationArgs") -> Dict[str, Any]: + inputs = model.input_activations + outputs = model.output_activations + + if inputs is not None: + if inputs.actorder is not None: + raise ValueError("Cannot apply actorder to input activations") + + if outputs is not None: + if outputs.actorder is not None: + raise ValueError("Cannot apply actorder to output activations") + + return model """ Pre-Set Quantization Scheme Args