From bcc6205161969b292c66601ef9b080dd418d21a2 Mon Sep 17 00:00:00 2001 From: trajep Date: Wed, 27 Sep 2023 06:32:04 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Bugfix=20win=20del=20file=20err?= =?UTF-8?q?=20(#17697)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Description Fix for this issue which raise the error of FileNotAccessd in windows when the context of TemporaryDirectory finished. https://github.com/microsoft/onnxruntime/issues/17627 ### Motivation and Context https://github.com/microsoft/onnxruntime/issues/17627 --- onnxruntime/python/tools/quantization/shape_inference.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/onnxruntime/python/tools/quantization/shape_inference.py b/onnxruntime/python/tools/quantization/shape_inference.py index eff3dc0bcd..b7d4726610 100644 --- a/onnxruntime/python/tools/quantization/shape_inference.py +++ b/onnxruntime/python/tools/quantization/shape_inference.py @@ -99,7 +99,10 @@ def quant_pre_process( sess_option = onnxruntime.SessionOptions() sess_option.optimized_model_filepath = opt_model_path sess_option.graph_optimization_level = onnxruntime.GraphOptimizationLevel.ORT_ENABLE_BASIC - _ = onnxruntime.InferenceSession(input_model_path, sess_option, providers=["CPUExecutionProvider"]) + sess = onnxruntime.InferenceSession(input_model_path, sess_option, providers=["CPUExecutionProvider"]) + # Close the session to avoid the cleanup error on Windows for temp folders + # https://github.com/microsoft/onnxruntime/issues/17627 + del sess except Exception: logger.error( "ONNX Runtime Model Optimization Failed! Consider rerun with option `--skip_optimization'."