@@ -76,6 +76,7 @@ def save_onnx(
76
76
model_path : str ,
77
77
max_external_file_size : int = 16e9 ,
78
78
external_data_file : Optional [str ] = None ,
79
+ do_split_external_data : bool = True ,
79
80
) -> bool :
80
81
"""
81
82
Save model to the given path.
@@ -95,6 +96,8 @@ def save_onnx(
95
96
specified in the variable EXTERNAL_ONNX_DATA_NAME
96
97
:param max_external_file_size: The maximum file size in bytes of a single split
97
98
external data out file. Defaults to 16000000000 (16e9 = 16GB)
99
+ :param do_split_external_data: True to split external data file into chunks of max
100
+ size max_external_file_size, false otherwise
98
101
:return True if the model was saved with external data, False otherwise.
99
102
"""
100
103
if external_data_file is not None :
@@ -112,7 +115,8 @@ def save_onnx(
112
115
all_tensors_to_one_file = True ,
113
116
location = external_data_file ,
114
117
)
115
- split_external_data (model_path , max_file_size = max_external_file_size )
118
+ if do_split_external_data :
119
+ split_external_data (model_path , max_file_size = max_external_file_size )
116
120
return True
117
121
118
122
if model .ByteSize () > DUMP_EXTERNAL_DATA_THRESHOLD :
@@ -132,7 +136,8 @@ def save_onnx(
132
136
all_tensors_to_one_file = True ,
133
137
location = external_data_file ,
134
138
)
135
- split_external_data (model_path , max_file_size = max_external_file_size )
139
+ if do_split_external_data :
140
+ split_external_data (model_path , max_file_size = max_external_file_size )
136
141
return True
137
142
138
143
onnx .save (model , model_path )
@@ -247,6 +252,9 @@ def split_external_data(
247
252
f"{ external_data_file_path } not found. { model_path } must have external "
248
253
"data written to a single file in the same directory"
249
254
)
255
+ if os .path .getsize (external_data_file_path ) <= max_file_size :
256
+ # return immediately if file is small enough to not split
257
+ return
250
258
251
259
# UPDATE: external data info of graph tensors so they point to the new split out
252
260
# files with updated offsets
0 commit comments