From 3cdf42548fcccaee05ce5a5e0f9ee563105c8665 Mon Sep 17 00:00:00 2001 From: shaahji <96227573+shaahji@users.noreply.github.com> Date: Tue, 15 Aug 2023 18:38:14 -0700 Subject: [PATCH] Issue #17098: Shape inferencing fails during quantization for large models (#17100) --- .../python/tools/quantization/shape_inference.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/onnxruntime/python/tools/quantization/shape_inference.py b/onnxruntime/python/tools/quantization/shape_inference.py index 4b5cb9b242..eff3dc0bcd 100644 --- a/onnxruntime/python/tools/quantization/shape_inference.py +++ b/onnxruntime/python/tools/quantization/shape_inference.py @@ -81,7 +81,17 @@ def quant_pre_process( if not skip_symbolic_shape: # Need to save the inferenced model to file so as to run the optimizer input_model_path = str(temp_path / "symbolic_shape_inferred.onnx") - onnx.save(model, input_model_path) + if save_as_external_data: + onnx.save_model( + model, + input_model_path, + save_as_external_data=True, + all_tensors_to_one_file=all_tensors_to_one_file, + size_threshold=external_data_size_threshold, + convert_attribute=False, + ) + else: + onnx.save(model, input_model_path) model = None opt_model_path = str(temp_path / "optimized.onnx")