Skip to content

Commit

Permalink
add onnxslim intergration (#811)
Browse files Browse the repository at this point in the history
* add onnxslim intergration

* fix onnxslim version
  • Loading branch information
inisis authored Jun 22, 2024
1 parent 4d92c7f commit e8cfaf6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions scripts/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)

import onnx
import onnxslim
from optimum.exporters.onnx import main_export, export_models
from optimum.onnx.graph_transformations import check_and_save_model
from optimum.exporters.tasks import TasksManager
Expand Down Expand Up @@ -224,6 +225,12 @@ class ConversionArguments:
"that desire a finer-grained control on the export."
}
)
skip_onnxslim: bool = field(
default=False,
metadata={
"help": "Whether or not to skip onnxslim."
}
)


def get_operators(model: onnx.ModelProto) -> Set[str]:
Expand Down Expand Up @@ -623,6 +630,13 @@ def main():

os.makedirs(os.path.join(output_model_folder, 'onnx'), exist_ok=True)

if not conv_args.skip_onnxslim:
onnx_models = [os.path.join(output_model_folder, x)
for x in os.listdir(output_model_folder) if x.endswith('.onnx')]

for model in onnx_models:
onnxslim.slim(model, model)

# Step 2. (optional, recommended) quantize the converted model for fast inference and to reduce model size.
if conv_args.quantize:
# Update quantize config with model specific defaults
Expand Down
1 change: 1 addition & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ optimum==1.17.1
onnx==1.15.0
onnxconverter-common==1.14.0
tqdm
onnxslim==0.1.29.1

0 comments on commit e8cfaf6

Please sign in to comment.