mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[BE] Prefer dash over underscore in command-line options (#94505)
Preferring dash over underscore in command-line options. Add `--command-arg-name` to the argument parser. The old arguments with underscores `--command_arg_name` are kept for backward compatibility.
Both dashes and underscores are used in the PyTorch codebase. Some argument parsers only have dashes or only have underscores in arguments. For example, the `torchrun` utility for distributed training only accepts underscore arguments (e.g., `--master_port`). The dashes are more common in other command-line tools. And it looks to be the default choice in the Python standard library:
`argparse.BooleanOptionalAction`: 4a9dff0e5a/Lib/argparse.py (L893-L895)
```python
class BooleanOptionalAction(Action):
def __init__(...):
if option_string.startswith('--'):
option_string = '--no-' + option_string[2:]
_option_strings.append(option_string)
```
It adds `--no-argname`, not `--no_argname`. Also typing `_` need to press the shift or the caps-lock key than `-`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/94505
Approved by: https://github.com/ezyang, https://github.com/seemethere
This commit is contained in:
committed by
PyTorch MergeBot
parent
a63524684d
commit
a229b4526f
@ -204,7 +204,11 @@ def main(args: List[str]) -> None:
|
||||
default="aten/src/ATen",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-d", "--install_dir", help="output directory", default="build/aten/src/ATen"
|
||||
"-d",
|
||||
"--install-dir",
|
||||
"--install_dir",
|
||||
help="output directory",
|
||||
default="build/aten/src/ATen",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-o",
|
||||
@ -217,6 +221,7 @@ def main(args: List[str]) -> None:
|
||||
help="run without writing any files (still updates outputs)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--op-selection-yaml-path",
|
||||
"--op_selection_yaml_path",
|
||||
help="Provide a path to the operator selection (for custom build) YAML "
|
||||
"that contains the information about the set of selected operators "
|
||||
@ -225,6 +230,7 @@ def main(args: List[str]) -> None:
|
||||
"The operator names also contain the namespace prefix (e.g. aten::)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--op-registration-allowlist",
|
||||
"--op_registration_allowlist",
|
||||
nargs="*",
|
||||
help="filter op registrations by the allowlist (if set); "
|
||||
@ -232,6 +238,7 @@ def main(args: List[str]) -> None:
|
||||
"e.g.: aten::empty aten::conv2d ...",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--TEST-ONLY-op-registration-allowlist-yaml-path",
|
||||
"--TEST_ONLY_op_registration_allowlist_yaml_path",
|
||||
help="Provide a path to the operator selection (for custom build) YAML "
|
||||
"which contains a list of operators. It is to serve testing purpose and "
|
||||
|
@ -17,7 +17,7 @@ class TestGenUnboxing(unittest.TestCase):
|
||||
mock_parse_native_yaml: NonCallableMock,
|
||||
mock_get_custom_build_selector: NonCallableMock,
|
||||
) -> None:
|
||||
args = ["--op_registration_allowlist=op1", "--op_selection_yaml_path=path2"]
|
||||
args = ["--op-registration-allowlist=op1", "--op-selection-yaml-path=path2"]
|
||||
gen_unboxing.main(args)
|
||||
mock_get_custom_build_selector.assert_called_once_with(["op1"], "path2")
|
||||
|
||||
@ -32,8 +32,8 @@ class TestGenUnboxing(unittest.TestCase):
|
||||
temp_file.write(b"- aten::add.Tensor")
|
||||
temp_file.seek(0)
|
||||
args = [
|
||||
f"--TEST_ONLY_op_registration_allowlist_yaml_path={temp_file.name}",
|
||||
"--op_selection_yaml_path=path2",
|
||||
f"--TEST-ONLY-op-registration-allowlist-yaml-path={temp_file.name}",
|
||||
"--op-selection-yaml-path=path2",
|
||||
]
|
||||
gen_unboxing.main(args)
|
||||
mock_get_custom_build_selector.assert_called_once_with(
|
||||
@ -52,9 +52,9 @@ class TestGenUnboxing(unittest.TestCase):
|
||||
temp_file.write(b"- aten::add.Tensor")
|
||||
temp_file.seek(0)
|
||||
args = [
|
||||
"--op_registration_allowlist=op1",
|
||||
"--TEST_ONLY_op_registration_allowlist_yaml_path={temp_file.name}",
|
||||
"--op_selection_yaml_path=path2",
|
||||
"--op-registration-allowlist=op1",
|
||||
"--TEST-ONLY-op-registration-allowlist-yaml-path={temp_file.name}",
|
||||
"--op-selection-yaml-path=path2",
|
||||
]
|
||||
gen_unboxing.main(args)
|
||||
mock_get_custom_build_selector.assert_called_once_with(["op1"], "path2")
|
||||
|
Reference in New Issue
Block a user