Skip to content

Commit

Permalink
[tools/onnx-subgraph] Add file IO exception process (#14730)
Browse files Browse the repository at this point in the history
Add exception protecting for file open and read

ONE-DCO-1.0-Signed-off-by: Youxin Chen <[email protected]>
  • Loading branch information
chenyx113 authored Feb 25, 2025
1 parent d6bd10f commit fcf0da6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tools/onnx_subgraph/extract_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ def split_onnx_ios(instrfile, input_path, out_folder='subgraphs/'):
model.graph.value_info.append(output)
onnx.save(model, input_path)

f1 = open(instrfile, "r")
lines = f1.readlines()
try:
with open(instrfile, "r") as f1:
lines = f1.readlines()
except Exception as e:
print(e)
raise

cpu_count = 0
npu_count = 0
count = 0
Expand All @@ -61,8 +66,6 @@ def split_onnx_ios(instrfile, input_path, out_folder='subgraphs/'):
print("succeed", count)
count = count + 1

f1.close()


if __name__ == "__main__":
arg_parser = argparse.ArgumentParser()
Expand Down

0 comments on commit fcf0da6

Please sign in to comment.