Skip to content

Commit

Permalink
Quantization Scheme Validation (#209)
Browse files Browse the repository at this point in the history
* add model validator to quantization scheme

Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>

* allow dynamic weights

Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>

---------

Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
  • Loading branch information
kylesayrs authored Nov 25, 2024
1 parent a26c03a commit c6197ce
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/compressed_tensors/quantization/quant_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = [
Expand 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
Expand Down

0 comments on commit c6197ce

Please sign in to comment.