From 8827363fd2badf21fe84ef326ef033f27cbdda97 Mon Sep 17 00:00:00 2001 From: Chen Fu <1316708+chenfucn@users.noreply.github.com> Date: Tue, 29 Aug 2023 12:50:15 -0700 Subject: [PATCH] Bugfixes: dangling pointers and python property typo (#17285) ### Description Bug fixes ### Motivation and Context Fixing one dangling pointer, and one python property name typo --- onnxruntime/core/mlas/lib/q4_dq_cli.cpp | 7 ++++--- .../python/tools/quantization/matmul_weight4_quantizer.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/onnxruntime/core/mlas/lib/q4_dq_cli.cpp b/onnxruntime/core/mlas/lib/q4_dq_cli.cpp index b994f171c6..5cc66da357 100644 --- a/onnxruntime/core/mlas/lib/q4_dq_cli.cpp +++ b/onnxruntime/core/mlas/lib/q4_dq_cli.cpp @@ -254,13 +254,14 @@ dequantize(const Cli& cli) out.write((const char*)dstbuf.data(), std::streamsize(dstbuf.size()) * sizeof(float)); } else { std::streambuf* buf; + std::ofstream file_output_stream; if (cli.output_file) { - std::ofstream out(cli.output_file, std::ios::out); - if (!out) { + file_output_stream.open(cli.output_file, std::ios::out); + if (file_output_stream.fail()) { std::cerr << "Cannot open output file " << cli.output_file << std::endl; return -1; } - buf = out.rdbuf(); + buf = file_output_stream.rdbuf(); } else { buf = std::cout.rdbuf(); } diff --git a/onnxruntime/python/tools/quantization/matmul_weight4_quantizer.py b/onnxruntime/python/tools/quantization/matmul_weight4_quantizer.py index 44d870bb22..921e02fb69 100644 --- a/onnxruntime/python/tools/quantization/matmul_weight4_quantizer.py +++ b/onnxruntime/python/tools/quantization/matmul_weight4_quantizer.py @@ -189,7 +189,7 @@ class MatMulWeight4Quantizer: # recursive call to take care of sub-graph graph_stack.append(attr.g) kv = {attr.name: self._process_subgraph(graph_stack)} - elif attr.type == onnx.AttributeProto.GRAPH: + elif attr.type == onnx.AttributeProto.GRAPHS: value = [] for subgraph in attr.graphs: # recursive call to take care of sub-graph