Skip to content
Merged
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: 6 additions & 0 deletions onnxruntime/python/tools/quantization/shape_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ def quant_pre_process(
external_names, external_values = extract_raw_data_from_model(input_model)
sess_option.add_external_initializers(list(external_names), list(external_values))
input_model = input_model.SerializeToString()
# the saved optimized model otherwise points to the original external data file name
# which is not available relative to the optimized model file
elif skip_symbolic_shape and save_as_external_data:
sess_option.add_session_config_entry(
"session.optimized_model_external_initializers_file_name", "optimized.onnx.data"
)

sess = onnxruntime.InferenceSession(input_model, sess_option, providers=["CPUExecutionProvider"])
# Close the session to avoid the cleanup error on Windows for temp folders
Expand Down
6 changes: 6 additions & 0 deletions onnxruntime/python/tools/symbolic_shape_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def __init__(self, int_max, auto_merge, guess_output_rank, verbose, prefix=""):
"Range": self._infer_Range,
"Reciprocal": self._pass_on_shape_and_type,
"ReduceSum": self._infer_ReduceSum,
"ReduceMean": self._infer_ReduceMean,
"ReduceProd": self._infer_ReduceProd,
"Reshape": self._infer_Reshape,
"Resize": self._infer_Resize,
Expand Down Expand Up @@ -1603,6 +1604,11 @@ def _infer_ReduceSum(self, node): # noqa: N802
)
)

def _infer_ReduceMean(self, node): # noqa: N802
if get_opset(self.out_mp_) >= 18:
# reduce mean spec 18+ is same as reduce sum spec 13+
self._infer_ReduceSum(node)

def _infer_ReduceProd(self, node): # noqa: N802
axes = get_attribute(node, "axes")
keep_dims = get_attribute(node, "keepdims", 1)
Expand Down