Skip to content

Commit fdfc760

Browse files
committed
use convert_attribute=True by default for onnx.save
1 parent 8748081 commit fdfc760

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

optimum/exporters/onnx/base.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,11 @@ def fix_dynamic_axes(
342342
dims = onnx_model.graph.output[output_idx].type.tensor_type.shape.dim
343343
dims[dim_idx].dim_value = outputs[output_idx].shape[dim_idx]
344344

345-
onnx.save(onnx_model, model_path.as_posix())
345+
onnx.save(
346+
onnx_model,
347+
model_path.as_posix(),
348+
convert_attribute=True,
349+
)
346350
del onnx_model
347351
gc.collect()
348352

optimum/exporters/onnx/convert.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ def remap(value):
611611
all_tensors_to_one_file=True,
612612
location=output.name + "_data",
613613
size_threshold=1024 if not FORCE_ONNX_EXTERNAL_DATA else 0,
614+
convert_attribute=True,
614615
)
615616

616617
# delete previous external data
@@ -688,7 +689,11 @@ def export_tensorflow(
688689

689690
with config.patch_model_for_export(model):
690691
onnx_model, _ = tf2onnx.convert.from_keras(model, input_signature, opset=opset)
691-
onnx.save(onnx_model, output.as_posix())
692+
onnx.save(
693+
onnx_model,
694+
output.as_posix(),
695+
convert_attribute=True,
696+
)
692697

693698
return input_names, output_names
694699

optimum/onnx/graph_transformations.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ def check_and_save_model(model: onnx.ModelProto, save_path: Optional[Union[str,
157157
# The new model may be below the maximum protobuf size, overwritting a model that was larger. Hence this os.remove.
158158
os.remove(external_path)
159159

160-
onnx.save(model, save_path)
160+
onnx.save(
161+
model,
162+
save_path,
163+
convert_attribute=True,
164+
)
161165
elif save_path is not None:
162166
# path/to/model.onnx
163167
save_path = Path(save_path).as_posix()
@@ -177,6 +181,7 @@ def check_and_save_model(model: onnx.ModelProto, save_path: Optional[Union[str,
177181
save_as_external_data=True,
178182
all_tensors_to_one_file=True,
179183
location=external_file_name,
184+
convert_attribute=True,
180185
)
181186
try:
182187
onnx.checker.check_model(save_path)

optimum/onnxruntime/modeling_decoder.py

+1
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ def _from_pretrained(
536536
all_tensors_to_one_file=True,
537537
location=model_cache_path.name + "_data",
538538
size_threshold=0,
539+
convert_attribute=True,
539540
)
540541
del onnx_model
541542

tests/onnx/test_onnx_graph_transformations.py

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def test_to_int32(self):
117117
save_as_external_data=True,
118118
all_tensors_to_one_file=True,
119119
location=Path(save_path).name + "_data",
120+
convert_attribute=True,
120121
)
121122

122123
onnx.checker.check_model(save_path)

0 commit comments

Comments
 (0)