Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
Signed-off-by: Mengni Wang <[email protected]>
  • Loading branch information
mengniwang95 committed Jul 4, 2023
1 parent fec595c commit 381f1bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions neural_compressor/adaptor/onnxrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ def quantize(self, tune_cfg, model, data_loader, q_func=None):
return model
if model.model.opset_import[0].version < 11: # pragma: no cover
logger.warning("Quantize input needs model opset 11 or newer.")
if self.backend == 'DnnlExecutionProvider' and \
any([i.domain in ['', 'ai.onnx'] and i.version < 15 for i in model.model.opset_import]):
from onnx import version_converter
try:
model.model = version_converter.convert_version(model.model, 15)
except:
logging.warning("Fail to upgrade model opset_import to >= 15, "\
"please upgrate it manually to run with bf16 data type")
exit(0)

from neural_compressor.adaptor.ox_utils.util import QuantizationMode
if self.format == "qlinearops":
format = QuantizationMode.QLinearOps
Expand Down
2 changes: 1 addition & 1 deletion neural_compressor/adaptor/ox_utils/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def calculate_quantization_params(self, q_config, quantization_thresholds):
if tensor_name in output_name_to_nodes:
parent = output_name_to_nodes[tensor_name]
if parent and parent.name in q_config and \
q_config[parent.name] not in ['fp32', 'fp16']:
q_config[parent.name] not in ['fp32', 'fp16', 'bf16']:
scheme = q_config[parent.name]['activation']['scheme']
qType = q_config[parent.name]['activation']['dtype']
elif self.backend in ['TensorrtExecutionProvider']:
Expand Down

0 comments on commit 381f1bd

Please sign in to comment.