Skip to content

Commit

Permalink
Add precision validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Only-bottle committed Nov 14, 2024
1 parent 0fea4ad commit fda58e2
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ class QuantizationOptions:
weight_precision: QuantizationPrecision = QuantizationPrecision.INT8 # Weight precision
activation_precision: QuantizationPrecision = QuantizationPrecision.INT8 # Activation precision

def __post_init__(self):
# weight_precision validation
if self.weight_precision not in [QuantizationPrecision.INT8, QuantizationPrecision.FLOAT32]:
if self.weight_precision == QuantizationPrecision.FLOAT16:
raise ValueError("weight_precision FLOAT16 is only available for custom precision quantization.")
raise ValueError(f"weight_precision must be either INT8 or FLOAT32, got {self.weight_precision}")

# activation_precision validation
if self.activation_precision not in [QuantizationPrecision.INT8, QuantizationPrecision.FLOAT32]:
if self.activation_precision == QuantizationPrecision.FLOAT16:
raise ValueError("activation_precision FLOAT16 is only available for custom precision quantization.")
raise ValueError(f"activation_precision must be either INT8 or FLOAT32, got {self.activation_precision}")


@dataclass
class PlainQuantizationOption(QuantizationOptions):
Expand Down

0 comments on commit fda58e2

Please sign in to comment.