Skip to content

Commit 09f8874

Browse files
authored
Enforce mutual exclusion of exporter flags at argparse layer
1 parent 98dc4bb commit 09f8874

2 files changed

Lines changed: 22 additions & 23 deletions

File tree

olive/cli/capture_onnx.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,30 @@ def register_subcommand(parser: ArgumentParser):
6666
help="The device used to run the model to capture the ONNX graph.",
6767
)
6868

69-
# PyTorch Exporter options
70-
pte_group = sub_parser.add_argument_group("PyTorch Exporter options")
71-
pte_group.add_argument(
69+
# Mutually exclusive exporter flags
70+
exporter_group = sub_parser.add_mutually_exclusive_group()
71+
exporter_group.add_argument(
7272
"--use_dynamo_exporter",
7373
action="store_true",
7474
help="Whether to use dynamo_export API to export ONNX model.",
7575
)
76+
exporter_group.add_argument(
77+
"--use_model_builder",
78+
action="store_true",
79+
help="Whether to use Model Builder to capture ONNX model.",
80+
)
81+
exporter_group.add_argument(
82+
"--use_mobius_builder",
83+
action="store_true",
84+
help=(
85+
"Whether to use MobiusBuilder (mobius-ai) to capture ONNX model. "
86+
"Supports multi-component multimodal models (VLMs). "
87+
"Requires 'pip install mobius-ai'."
88+
),
89+
)
90+
91+
# PyTorch Exporter options
92+
pte_group = sub_parser.add_argument_group("PyTorch Exporter options")
7693
pte_group.add_argument(
7794
"--fixed_param_dict",
7895
type=parse_dim_dict,
@@ -108,21 +125,6 @@ def register_subcommand(parser: ArgumentParser):
108125

109126
# Model Builder options
110127
mb_group = sub_parser.add_argument_group("Model Builder options")
111-
mb_group.add_argument(
112-
"--use_model_builder",
113-
action="store_true",
114-
help="Whether to use Model Builder to capture ONNX model.",
115-
)
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-
)
126128
mb_group.add_argument(
127129
"--precision",
128130
type=str,
@@ -241,10 +243,6 @@ def _get_run_config(self, tempdir: str) -> dict:
241243
]
242244
)
243245
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-
)
248246
if self.args.precision not in ("fp32", "fp16", "bf16"):
249247
raise ValueError(
250248
f"MobiusBuilder supports precisions fp32/fp16/bf16; got '{self.args.precision}'. "

test/cli/test_cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,9 @@ def test_capture_onnx_command_use_mobius_builder_rejects_conflicts(_, __, confli
401401
]
402402

403403
# execute / verify
404-
with pytest.raises(ValueError, match="cannot be combined"):
404+
with pytest.raises(SystemExit) as exc_info:
405405
cli_main(command_args)
406+
assert exc_info.value.code == 2
406407

407408

408409
@patch("olive.cli.shared_cache.AzureContainerClientFactory")

0 commit comments

Comments
 (0)