Repository navigation
Expand file tree
/
Copy pathcli.py
More file actions
41 lines (33 loc) · 1.32 KB
/
Copy pathcli.py
File metadata and controls
41 lines (33 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Shared argparse helpers for the ONNX utility scripts.
A few scripts expose identical ``--model-path`` or ``--weight-type`` CLI
arguments; the helpers here keep those definitions in one place so Pylint's
duplicate-code check (R0801) stays quiet. The module has no third-party
dependencies so it imports cleanly in any environment.
"""
from __future__ import annotations
import argparse
from collections.abc import Mapping
def add_model_path_argument(parser: argparse.ArgumentParser) -> None:
"""Add the common ``--model-path`` (required) argument to ``parser``."""
parser.add_argument(
"--model-path",
required=True,
help="Path to the ONNX model to inspect.",
)
def add_weight_type_argument(
parser: argparse.ArgumentParser,
weight_types: Mapping[str, object],
default_weight_type: str,
) -> None:
"""Add the common ``--weight-type`` argument used by the quantizers.
Args:
parser: The argument parser to extend.
weight_types: Mapping of CLI choice -> quantization weight-type value.
default_weight_type: The choice to select when none is given.
"""
parser.add_argument(
"--weight-type",
choices=sorted(weight_types),
default=default_weight_type,
help=f"Quantization weight type (default: {default_weight_type}).",
)