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 subgraph quantization regression in onnxruntime 1.17 #19421

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Changes from 1 commit
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
Next Next commit
fix subgraph quantization bug
  • Loading branch information
fxmarty committed Feb 5, 2024
commit a3cec5218b8092efb37ddcc4f0c1a985fcf14e75
11 changes: 9 additions & 2 deletions onnxruntime/python/tools/quantization/onnx_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,9 +1336,16 @@ def _dequantize_value(self, value_name):
if (value_name in self.quantized_value_map) and (value_name not in self.generated_value_names):
quantized_value = self.quantized_value_map[value_name]
# Add DequantizeLinear Node for this input

scale_init = find_by_name(quantized_value.scale_name, self.model.initializer())
# axis is not specified so scale_init must be a scalar.
assert onnx.numpy_helper.to_array(scale_init).size == 1

# In case we are working with subgraphs, the graph `producer_name` is set to `"onnx-quantizer"` in the `quantize_subgraph` method. In this case, the scale initializer may be on the top level graph, so this check can not be done.
if (
self.model.model.producer_name != "onnx-quantizer"
or (self.model.model.producer_name == "onnx-quantizer" and scale_init is not None)
):
# axis is not specified so scale_init must be a scalar.
assert onnx.numpy_helper.to_array(scale_init).size == 1

dqlinear_name = value_name + "_DequantizeLinear"
dqlinear_node = self.model.find_node_by_name(dqlinear_name, self.new_nodes, self.model.graph())
Expand Down