@@ -113,6 +113,16 @@ def register_subcommand(parser: ArgumentParser):
113113 action = "store_true" ,
114114 help = "Whether to use Model Builder to capture ONNX model." ,
115115 )
116+ mb_group .add_argument (
117+ "--use_mobius_builder" ,
118+ action = "store_true" ,
119+ help = (
120+ "Whether to use MobiusBuilder (mobius-ai) to capture ONNX model. "
121+ "Supports multi-component multimodal models (VLMs). "
122+ "Requires 'pip install mobius-ai'. "
123+ "Mutually exclusive with --use_model_builder and --use_dynamo_exporter."
124+ ),
125+ )
116126 mb_group .add_argument (
117127 "--precision" ,
118128 type = str ,
@@ -197,8 +207,14 @@ def _get_run_config(self, tempdir: str) -> dict:
197207 is_diffusers_model = input_model_config ["type" ].lower () == "diffusersmodel"
198208
199209 # whether model is in fp16 or bf16 (currently not supported by CPU EP)
200- is_fp16_or_bf16 = (not self .args .use_model_builder and self .args .torch_dtype == "float16" ) or (
201- self .args .use_model_builder and self .args .precision in ("fp16" , "bf16" )
210+ is_fp16_or_bf16 = (
211+ (
212+ not self .args .use_model_builder
213+ and not self .args .use_mobius_builder
214+ and self .args .torch_dtype == "float16"
215+ )
216+ or (self .args .use_model_builder and self .args .precision in ("fp16" , "bf16" ))
217+ or (self .args .use_mobius_builder and self .args .precision in ("fp16" , "bf16" ))
202218 )
203219 to_replace = [
204220 ("input_model" , input_model_config ),
@@ -213,6 +229,7 @@ def _get_run_config(self, tempdir: str) -> dict:
213229
214230 if is_diffusers_model :
215231 del config ["passes" ]["m" ]
232+ del config ["passes" ]["b" ]
216233 to_replace .extend (
217234 [
218235 (
@@ -223,8 +240,30 @@ def _get_run_config(self, tempdir: str) -> dict:
223240 (("passes" , "c" , "target_opset" ), self .args .target_opset ),
224241 ]
225242 )
243+ elif self .args .use_mobius_builder :
244+ if self .args .use_model_builder or self .args .use_dynamo_exporter :
245+ raise ValueError (
246+ "--use_mobius_builder cannot be combined with --use_model_builder or --use_dynamo_exporter."
247+ )
248+ if self .args .precision not in ("fp32" , "fp16" , "bf16" ):
249+ raise ValueError (
250+ f"MobiusBuilder supports precisions fp32/fp16/bf16; got '{ self .args .precision } '. "
251+ "For INT4, capture in fp32/fp16/bf16 first and run a quantization pass afterwards."
252+ )
253+ del config ["passes" ]["c" ]
254+ del config ["passes" ]["m" ]
255+ to_replace .extend (
256+ [
257+ (("passes" , "b" , "precision" ), self .args .precision ),
258+ (
259+ ("passes" , "b" , "runtime" ),
260+ "ort-genai" if self .args .use_ort_genai else "none" ,
261+ ),
262+ ]
263+ )
226264 elif self .args .use_model_builder :
227265 del config ["passes" ]["c" ]
266+ del config ["passes" ]["b" ]
228267 to_replace .extend (
229268 [
230269 (("passes" , "m" , "precision" ), self .args .precision ),
@@ -245,6 +284,7 @@ def _get_run_config(self, tempdir: str) -> dict:
245284 if self .args .int4_accuracy_level is not None :
246285 to_replace .append ((("passes" , "m" , "int4_accuracy_level" ), self .args .int4_accuracy_level ))
247286 else :
287+ del config ["passes" ]["b" ]
248288 to_replace .extend (
249289 [
250290 (
@@ -300,6 +340,7 @@ def _get_run_config(self, tempdir: str) -> dict:
300340 "type" : "OnnxConversion" ,
301341 },
302342 "m" : {"type" : "ModelBuilder" , "metadata_only" : False },
343+ "b" : {"type" : "MobiusBuilder" },
303344 "f" : {"type" : "DynamicToFixedShape" },
304345 },
305346 "host" : "local_system" ,
0 commit comments