Skip to content

Commit c6197ce

Browse files
authored
Quantization Scheme Validation (#209)
* add model validator to quantization scheme Signed-off-by: Kyle Sayers <[email protected]> * allow dynamic weights Signed-off-by: Kyle Sayers <[email protected]> --------- Signed-off-by: Kyle Sayers <[email protected]>
1 parent a26c03a commit c6197ce

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/compressed_tensors/quantization/quant_scheme.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
# limitations under the License.
1414

1515
from copy import deepcopy
16-
from typing import List, Optional
16+
from typing import Any, Dict, List, Optional
1717

1818
from compressed_tensors.quantization.quant_args import (
1919
QuantizationArgs,
2020
QuantizationStrategy,
2121
QuantizationType,
2222
)
23-
from pydantic import BaseModel
23+
from pydantic import BaseModel, model_validator
2424

2525

2626
__all__ = [
@@ -47,6 +47,20 @@ class QuantizationScheme(BaseModel):
4747
input_activations: Optional[QuantizationArgs] = None
4848
output_activations: Optional[QuantizationArgs] = None
4949

50+
@model_validator(mode="after")
51+
def validate_model_after(model: "QuantizationArgs") -> Dict[str, Any]:
52+
inputs = model.input_activations
53+
outputs = model.output_activations
54+
55+
if inputs is not None:
56+
if inputs.actorder is not None:
57+
raise ValueError("Cannot apply actorder to input activations")
58+
59+
if outputs is not None:
60+
if outputs.actorder is not None:
61+
raise ValueError("Cannot apply actorder to output activations")
62+
63+
return model
5064

5165
"""
5266
Pre-Set Quantization Scheme Args

0 commit comments

Comments
 (0)