55requirements
66++++++++++++
77
8- git+https://github.com/sdpython/experimental-experiment.git
9- huggingface_hub>=1.2.1
10- onnx-diagnostic>=0.8.4
11- onnxruntime>=1.23
12- torch>=2.9 # weekly is better
13- transformers>=4.57
8+ ::
9+
10+ git+https://github.com/sdpython/experimental-experiment.git # optional
11+ huggingface_hub>=1.2.1
12+ onnx-diagnostic>=0.8.4
13+ onnxruntime>=1.23
14+ torch>=2.9 # weekly is better
15+ transformers>=4.57
1416
1517Examples
1618++++++++
1719
1820.. code-block:: bash
1921
20- python export_qwen25_vl_visual.py -m Qwen/Qwen2.5-VL-7B-Instruct --device cpu --dtype float32 --exporter onnx-dynamo --pretrained --second-input
21-
22- Merge model and data into one file:
22+ python export_qwen25_vl_visual.py -m Qwen/Qwen2.5-VL-7B-Instruct --device cpu --dtype float32 --exporter onnx-dynamo --pretrained --second-input --zip
2323
24- .. code-block:: bash
25-
26- tar -czvf model.tar.gz model.onnx model.data
24+ Cheat sheet for tar commands. To make a tar:
25+ ``tar -czvf model.tar.gz model.onnx model.data``
26+ And to untar:
27+ ``tar -xzvf model.tar.gz``.
2728
2829Attention
2930+++++++++
3839"""
3940
4041import os
42+ import subprocess
4143import sys
4244import time
4345from argparse import ArgumentParser , BooleanOptionalAction
@@ -66,6 +68,7 @@ def main(
6668 exporter : str = "onnx-dynamo" ,
6769 pretrained : bool = True ,
6870 second_input : bool = True ,
71+ zip : bool = False ,
6972):
7073 print ("-- import torch" )
7174 import torch
@@ -164,9 +167,10 @@ def _config_reduction(config, task):
164167 prefix = simplify_model_id_for_a_filename (model_id )
165168 if "QWEN25ATTENTION" in os .environ :
166169 prefix = f"{ prefix } .{ os .environ ['QWEN25ATTENTION' ]} "
167- filename = f"model.{ prefix } .visual.{ device } .{ dtype } .{ exporter } .onnx"
170+ basename = f"model.{ prefix } .visual.{ device } .{ dtype } .{ exporter } "
171+ filename = f"{ basename } .onnx"
168172 print (f"-- export in { filename !r} " )
169- stat_file = filename . replace ( ".onnx" , ". stats")
173+ stat_file = f" { basename } . stats"
170174 begin = time .perf_counter ()
171175
172176 if exporter == "onnx-dynamo" and device == "cuda" and "QWEN25ATTENTION" not in os .environ :
@@ -235,6 +239,18 @@ def fprint(s):
235239 diff = max_diff (expected_big , big [0 ], hist = [0.1 ])
236240 fprint (f"-- discrepancies={ diff } " )
237241
242+ if zip :
243+ tar_file_name = f"{ basename } .zip"
244+ print ()
245+ print (f"-- make file { tar_file_name !r} " )
246+ cmd = ["zip" , "-v" , "-1" , tar_file_name ]
247+ for name in [filename , f"{ filename } .data" ]:
248+ print (f"-- add { name !r} " )
249+ cmd .append (name )
250+ print (f"-- cmd: { ' ' .join (cmd )} " )
251+ subprocess .run (cmd , check = True )
252+ print ("-- done." )
253+
238254
239255def get_parser () -> ArgumentParser :
240256 parser = ArgumentParser (
@@ -266,6 +282,12 @@ def get_parser() -> ArgumentParser:
266282 help = "check discrepancies with other inputs" ,
267283 action = BooleanOptionalAction ,
268284 )
285+ parser .add_argument (
286+ "--zip" ,
287+ default = False ,
288+ help = "Creates a file .zip with onnx file and data file." ,
289+ action = BooleanOptionalAction ,
290+ )
269291 return parser
270292
271293
@@ -279,4 +301,5 @@ def get_parser() -> ArgumentParser:
279301 exporter = args .exporter ,
280302 pretrained = args .pretrained ,
281303 second_input = args .second_input ,
304+ zip = args .zip ,
282305 )
0 commit comments