Skip to content

Commit

Permalink
[converter] fix converter sym_zp check
Browse files Browse the repository at this point in the history
  • Loading branch information
zk1998 authored Oct 8, 2024
1 parent 7a4aee5 commit 5cf1194
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tinynn/converter/operators/tflite/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import torch

from ...schemas.tflite import schema_generated as tflite
from tinynn.util.util import get_logger

log = get_logger(__name__)

Offset = int

Expand Down Expand Up @@ -201,12 +204,13 @@ def __init__(
else:
if not asymmetric:
sym_u8_offset = 128
assert tensor.q_zero_point() == sym_u8_offset, (
"As for symmetric quantization, the zero point of the u8 tensors should be"
f" {sym_u8_offset}, but got {tensor.q_zero_point()}. This could happen if you didn't train"
" the model after QAT preparation, or the OP is not supported in symmetric quantization"
" (e.g. sigmoid)"
)
if tensor.q_zero_point() != sym_u8_offset:
log.warning(
"As for symmetric quantization, the zero point of the u8 tensors should be"
f" {sym_u8_offset}, but got {tensor.q_zero_point()}. This could happen if you didn't"
" train the model after QAT preparation, or the OP is not supported in symmetric"
" quantization (e.g. sigmoid)"
)
else:
sym_u8_offset = tensor.q_zero_point()
scale = tensor.q_scale()
Expand Down

0 comments on commit 5cf1194

Please sign in to comment.