Skip to content

Commit

Permalink
Add a skip_checks option to OpQuantizationConfig.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 653687329
  • Loading branch information
paulinesho authored and copybara-github committed Jul 18, 2024
1 parent 2d9afef commit c2656d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def check_op_quantization_config(
Raises:
ValueError: If the op quantization config is invalid.
"""
if op_quant_config.skip_checks:
return

if op_quant_config.weight_tensor_config.dtype != qtyping.TensorDataType.INT:
raise ValueError(
"Weights need to have integer type for min/max uniform quantization. If"
Expand Down
6 changes: 6 additions & 0 deletions ai_edge_quantizer/qtyping.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class OpQuantizationConfig:
weight_tensor_config: The quantization configuration for weight tensor in
the op.
execution_mode: How to execute the op after quantization.
skip_checks: Skip op quantization config checks.
"""

# Quant config for activation tensors in the op (i.e., runtime tensors).
Expand All @@ -262,6 +263,11 @@ class OpQuantizationConfig:
# How to execute the op after quantization.
execution_mode: OpExecutionMode = OpExecutionMode.WEIGHT_ONLY

# For advanced users only. If set, the quantizer will ignore all op
# configuration checks and forcefully quantize this op according to the user
# instructions even if it's not supported in the TFLite runtime.
skip_checks: bool = False

def __post_init__(self):
if self.activation_tensor_config is None:
return
Expand Down

0 comments on commit c2656d2

Please sign in to comment.