Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Add not_calc_quant_min_max assertion when symmetric_range==True #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions mqbench/prepare_by_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ class BackendType(Enum):
default_weight_observer=MinMaxObserver,
default_act_observer=EMAMinMaxObserver),
BackendType.Tensorrt: dict(qtype='affine', # noqa: E241
w_qscheme=QuantizeScheme(symmetry=True, per_channel=True, pot_scale=False, bit=8, symmetric_range=True),
a_qscheme=QuantizeScheme(symmetry=True, per_channel=False, pot_scale=False, bit=8, symmetric_range=True),
w_qscheme=QuantizeScheme(symmetry=True, per_channel=True, pot_scale=False, bit=8, symmetric_range=True,
factory_kwargs={'not_calc_quant_min_max': True}),
a_qscheme=QuantizeScheme(symmetry=True, per_channel=False, pot_scale=False, bit=8, symmetric_range=True,
factory_kwargs={'not_calc_quant_min_max': True}),
default_weight_quantize=LearnableFakeQuantize,
default_act_quantize=LearnableFakeQuantize,
default_weight_observer=MinMaxObserver,
Expand Down
4 changes: 4 additions & 0 deletions mqbench/scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def __init__(self, symmetry=True, per_channel=False, pot_scale=False, bit=8, **k
if 'symmetric_range' in kwargs:
self.symmetric_range = kwargs['symmetric_range']
del kwargs['symmetric_range']
assert isinstance(kwargs.get('factory_kwargs', None), dict) \
and kwargs['factory_kwargs'].get('not_calc_quant_min_max', False), \
"QuantizeScheme with `symmetric_range=True` should provide kwargs " \
"factory_kwargs={not_calc_quant_min_max: True, ...}"
else:
self.symmetric_range = False
self.kwargs = kwargs
Expand Down