Skip to content

Commit 4249da3

Browse files
authored
[one-cmds] Show logs for one-import-onnx (#16220)
This will show progress logs of one-import-onnx with verbose option. And also show call stack for errors. ONE-DCO-1.0-Signed-off-by: SaeHie Park <saehie.park@gmail.com>
1 parent 8051236 commit 4249da3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

compiler/one-cmds/one-import-onnx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import onelib.utils as oneutils
3939
# TODO Find better way to suppress trackback on error
4040
sys.tracebacklimit = 0
4141

42+
_verbose = False
43+
4244

4345
def get_driver_cfg_section():
4446
return "one-import-onnx"
@@ -139,8 +141,12 @@ def _apply_verbosity(verbosity):
139141
# 1 : WARNING + ERROR + FATAL
140142
# 2 : ERROR + FATAL
141143
# 3 : FATAL
144+
global _verbose
142145
if verbosity:
143146
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '0'
147+
# set to default value 1000
148+
sys.tracebacklimit = 1000
149+
_verbose = True
144150
else:
145151
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
146152

@@ -184,6 +190,7 @@ def _check_onnx2circle():
184190

185191

186192
def _convert(args):
193+
global _verbose
187194
_apply_verbosity(args.verbose)
188195

189196
# get file path to log
@@ -192,6 +199,8 @@ def _convert(args):
192199

193200
# get default converter
194201
onnx2circle_path = _check_onnx2circle()
202+
if _verbose:
203+
print("import-onnx: onnx2circle_path", onnx2circle_path, flush=True)
195204

196205
# get import onnx extension path
197206
ext_path = _check_ext()
@@ -204,6 +213,8 @@ def _convert(args):
204213
# save intermediate
205214
if oneutils.is_valid_attr(args, 'save_intermediate'):
206215
tmpdir = os.path.dirname(logfile_path)
216+
if _verbose:
217+
print("import-onnx: intermediate at", tmpdir, flush=True)
207218

208219
onnx_model = onnx.load(onnx_to_convert_path)
209220
if _onnx_legalizer_enabled:
@@ -213,6 +224,8 @@ def _convert(args):
213224
if options.unroll_rnn or options.unroll_lstm:
214225
onnx_legalizer.legalize(onnx_model, options)
215226
model_updated = True
227+
if _verbose:
228+
print("import-onnx: legalize done", flush=True)
216229

217230
run_default_import = True
218231
if ext_path:
@@ -224,6 +237,9 @@ def _convert(args):
224237
onnx.save(onnx_model, fixed_path)
225238
onnx_to_convert_path = fixed_path
226239

240+
if _verbose:
241+
print("import-onnx: import", onnx_to_convert_path, flush=True)
242+
227243
res_conv = -1
228244
if run_default_import:
229245
if _force_ext(args):
@@ -239,10 +255,15 @@ def _convert(args):
239255
o2c_cmd.append('--dynamic_batch_to_single_batch')
240256
o2c_cmd.append(onnx_to_convert_path)
241257
o2c_cmd.append(getattr(args, 'output_path'))
258+
if _verbose:
259+
print("import-onnx: cmd ", o2c_cmd, flush=True)
242260
res_conv = oneutils.run_ret(o2c_cmd, logfile=f)
243261
except:
244262
res_conv = -1
245263

264+
if _verbose:
265+
print("import-onnx: default called", flush=True)
266+
246267
# if default conversion fails, try with one-import-onnx-ext if available
247268
if ext_path and not _disable_ext(args):
248269
if res_conv != 0:
@@ -266,8 +287,13 @@ def _convert(args):
266287
ext_cmd.append('--keep_io_order')
267288
ext_cmd.append(onnx_to_convert_path)
268289
ext_cmd.append(getattr(args, 'output_path'))
290+
if _verbose:
291+
print("import-onnx: ext cmd", ext_cmd, flush=True)
269292
res_conv = oneutils.run_ret(ext_cmd, logfile=f)
270293

294+
if _verbose:
295+
print("import-onnx: done", flush=True)
296+
271297
sys.exit(res_conv)
272298

273299

0 commit comments

Comments
 (0)