diff --git a/onnxruntime/python/tools/quantization/shape_inference.py b/onnxruntime/python/tools/quantization/shape_inference.py index 63d34e1167de4..0f5a9c376e00c 100644 --- a/onnxruntime/python/tools/quantization/shape_inference.py +++ b/onnxruntime/python/tools/quantization/shape_inference.py @@ -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 diff --git a/onnxruntime/python/tools/symbolic_shape_infer.py b/onnxruntime/python/tools/symbolic_shape_infer.py index b9675d4280e59..c25e5dc087614 100755 --- a/onnxruntime/python/tools/symbolic_shape_infer.py +++ b/onnxruntime/python/tools/symbolic_shape_infer.py @@ -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, @@ -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)