Skip to content

Commit a926116

Browse files
authored
Merge pull request #656 from robertknight/timm-export-optimize
Apply model optimization when exporting timm models using TorchDynamo
2 parents 3269bd6 + f0229d2 commit a926116

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: tools/export-timm-model.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,13 @@ def export_timm_model(config: str, onnx_path: str, dynamo: bool = False):
8989
print_predictions(output)
9090

9191
print(f"Exporting model to {onnx_path}")
92-
torch.onnx.export(model, input_img, onnx_path, dynamo=dynamo)
92+
if dynamo:
93+
onnx_prog = torch.onnx.export(model, input_img, dynamo=True)
94+
# Optimize model to inline functions. See https://github.com/robertknight/rten/issues/655.
95+
onnx_prog.optimize()
96+
onnx_prog.save(onnx_path)
97+
else:
98+
torch.onnx.export(model, input_img, onnx_path)
9399

94100
# Test exported model with ONNX Runtime as a reference implementation.
95101
#

0 commit comments

Comments
 (0)