Skip to content

Commit a229b45

Browse files
XuehaiPanpytorchmergebot
authored andcommitted
[BE] Prefer dash over underscore in command-line options (pytorch#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`: https://github.com/python/cpython/blob/4a9dff0e5adc91cbb1ed68c495dac64ccfe608bd/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: pytorch#94505 Approved by: https://github.com/ezyang, https://github.com/seemethere
1 parent a635246 commit a229b45

File tree

91 files changed

+631
-456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+631
-456
lines changed

benchmarks/distributed/rpc/parameter_server/launcher.py

+16
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,13 @@ def main(args):
448448
if __name__ == "__main__":
449449
parser = argparse.ArgumentParser(description="RPC server Benchmark")
450450
parser.add_argument(
451+
"--master-addr",
451452
"--master_addr",
452453
type=str,
453454
help="IP address of the machine that will host the process with rank 0"
454455
)
455456
parser.add_argument(
457+
"--master-port",
456458
"--master_port",
457459
type=str,
458460
help="A free port on the machine that will host the process with rank 0"
@@ -493,6 +495,7 @@ def main(args):
493495
help="cudaserver count for benchmark run"
494496
)
495497
parser.add_argument(
498+
"--rpc-timeout",
496499
"--rpc_timeout",
497500
type=int,
498501
help="timeout in seconds to use for RPC"
@@ -508,6 +511,7 @@ def main(args):
508511
help="epoch count for training"
509512
)
510513
parser.add_argument(
514+
"--batch-size",
511515
"--batch_size",
512516
type=int,
513517
help="number of training examples used in one iteration"
@@ -523,62 +527,74 @@ def main(args):
523527
help="id for model configuration"
524528
)
525529
parser.add_argument(
530+
"--data-config-path",
526531
"--data_config_path",
527532
type=str,
528533
help="path to data configuration file"
529534
)
530535
parser.add_argument(
536+
"--model-config-path",
531537
"--model_config_path",
532538
type=str,
533539
help="path to model configuration file"
534540
)
535541
parser.add_argument(
542+
"--server-config-path",
536543
"--server_config_path",
537544
type=str,
538545
help="path to server configuration file"
539546
)
540547
parser.add_argument(
548+
"--trainer-config-path",
541549
"--trainer_config_path",
542550
type=str,
543551
help="path to trainer configuration file"
544552
)
545553
parser.add_argument(
554+
"--torch-seed",
546555
"--torch_seed",
547556
type=int,
548557
help="seed for generating random numbers to a non-deterministic random number"
549558
)
550559
parser.add_argument(
560+
"--cuda-seed",
551561
"--cuda_seed",
552562
type=int,
553563
help="seed for generating random numbers to a random number for the current GPU"
554564
)
555565
parser.add_argument(
566+
"--preprocess-data",
556567
"--preprocess_data",
557568
type=str,
558569
help="this function will be used to preprocess data before training"
559570
)
560571
parser.add_argument(
572+
"--create-criterion",
561573
"--create_criterion",
562574
type=str,
563575
help="this function will be used to create the criterion used for model loss calculation"
564576
)
565577
parser.add_argument(
578+
"--create-ddp-model",
566579
"--create_ddp_model",
567580
type=str,
568581
help="this function will be used to create the ddp model used during training"
569582
)
570583
parser.add_argument(
584+
"--hook-state",
571585
"--hook_state",
572586
type=str,
573587
help="this will be the state class used when registering the ddp communication hook"
574588
)
575589
parser.add_argument(
590+
"--ddp-hook",
576591
"--ddp_hook",
577592
type=str,
578593
default="allreduce_hook",
579594
help="ddp communication hook"
580595
)
581596
parser.add_argument(
597+
"--iteration-step",
582598
"--iteration_step",
583599
type=str,
584600
help="this will be the function called for each iteration of training"

benchmarks/distributed/rpc/rl/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This benchmark depends on PyTorch.
2020

2121
For any environments you are interested in, pass the corresponding arguments to `python launcher.py`.
2222

23-
```python launcher.py --world_size="10,20" --master_addr="127.0.0.1" --master_port="29501 --batch="True" --state_size="10-20-10" --nlayers="5" --out_features="10" --output_file_path="benchmark_report.json"```
23+
```python launcher.py --world-size="10,20" --master-addr="127.0.0.1" --master-port="29501 --batch="True" --state-size="10-20-10" --nlayers="5" --out-features="10" --output-file-path="benchmark_report.json"```
2424

2525
Example Output:
2626

benchmarks/distributed/rpc/rl/launcher.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ def str2bool(v):
2929

3030

3131
parser = argparse.ArgumentParser(description='PyTorch RPC RL Benchmark')
32-
parser.add_argument('--world_size', type=str, default='10')
33-
parser.add_argument('--master_addr', type=str, default='127.0.0.1')
34-
parser.add_argument('--master_port', type=str, default='29501')
32+
parser.add_argument('--world-size', '--world_size', type=str, default='10')
33+
parser.add_argument('--master-addr', '--master_addr', type=str, default='127.0.0.1')
34+
parser.add_argument('--master-port', '--master_port', type=str, default='29501')
3535
parser.add_argument('--batch', type=str, default='True')
3636

37-
parser.add_argument('--state_size', type=str, default='10-20-10')
37+
parser.add_argument('--state-size', '--state_size', type=str, default='10-20-10')
3838
parser.add_argument('--nlayers', type=str, default='5')
39-
parser.add_argument('--out_features', type=str, default='10')
40-
parser.add_argument('--output_file_path', type=str, default='benchmark_report.json')
39+
parser.add_argument('--out-features', '--out_features', type=str, default='10')
40+
parser.add_argument('--output-file-path', '--output_file_path', type=str, default='benchmark_report.json')
4141

4242
args = parser.parse_args()
4343
args = vars(args)

benchmarks/dynamo/common.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,9 @@ def parse_args(args=None):
15201520
default=False,
15211521
help="use channels last format",
15221522
)
1523-
parser.add_argument("--batch_size", type=int, help="batch size for benchmarking")
1523+
parser.add_argument(
1524+
"--batch-size", "--batch_size", type=int, help="batch size for benchmarking"
1525+
)
15241526
parser.add_argument(
15251527
"--iterations", type=int, default=2, help="how many iterations to run"
15261528
)
@@ -1651,7 +1653,11 @@ def get_example_inputs(self):
16511653
action="store_true",
16521654
help="exports trace of kineto profiler",
16531655
)
1654-
parser.add_argument("--profiler_trace_name", help="Overwrites exported trace name")
1656+
parser.add_argument(
1657+
"--profiler-trace-name",
1658+
"--profiler_trace_name",
1659+
help="Overwrites exported trace name",
1660+
)
16551661

16561662
parser.add_argument(
16571663
"--diff-branch",
@@ -1670,6 +1676,7 @@ def get_example_inputs(self):
16701676
)
16711677

16721678
parser.add_argument(
1679+
"--cold-start-latency",
16731680
"--cold_start_latency",
16741681
action="store_true",
16751682
help="Use a fresh triton cachedir when running each model, to force cold-start compile.",
@@ -1787,6 +1794,7 @@ def get_example_inputs(self):
17871794
help="Dump convolution input/weight/bias's shape/stride/dtype and other options to json",
17881795
)
17891796
group.add_argument(
1797+
"--recompile-profiler",
17901798
"--recompile_profiler",
17911799
action="store_true",
17921800
help="Run the dynamo recompilation profiler on each model.",

benchmarks/dynamo/distributed.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,29 @@ def print_compile(gm, ex):
121121
help="if set to a str, uses dynamo[str] backend. else, eager",
122122
)
123123
parser.add_argument("--verbose", action="store_true")
124-
parser.add_argument("--batch_size", default=None)
124+
parser.add_argument("--batch-size", "--batch_size", default=None)
125125
parser.add_argument(
126126
"--torchviz", action="store_true", help="Dump autograd graph with torchviz"
127127
)
128128
parser.add_argument("--profile", action="store_true", help="Run the profiler")
129-
parser.add_argument("--trace_file", default="profile.json", help="Run the profiler")
129+
parser.add_argument(
130+
"--trace-file", "--trace_file", default="profile.json", help="Run the profiler"
131+
)
130132
parser.add_argument("--repeat", default=10, help="Repeats for timing run")
131133
parser.add_argument(
134+
"--dynamo-no-optimize-ddp",
132135
"--dynamo_no_optimize_ddp",
133136
action="store_true",
134137
help="Disable dynamo's ddp optimizer (enabled by default)",
135138
)
136139
parser.add_argument(
140+
"--fsdp-checkpoint",
137141
"--fsdp_checkpoint",
138142
action="store_true",
139143
help="Use gradient checkpointing via model-specific policy",
140144
)
141145
parser.add_argument(
146+
"--fsdp-wrap",
142147
"--fsdp_wrap",
143148
action="store_true",
144149
help="Apply fsdp to submodules via model-specific policy",
@@ -150,10 +155,12 @@ def print_compile(gm, ex):
150155

151156
model_arg = parser.add_mutually_exclusive_group(required=True)
152157
model_arg.add_argument(
153-
"--torchbench_model", help="name of torchbench model, e.g. hf_Bert"
158+
"--torchbench-model",
159+
"--torchbench_model",
160+
help="name of torchbench model, e.g. hf_Bert",
154161
)
155162
model_arg.add_argument(
156-
"--toy_model", action="store_true", help="use toy model instead"
163+
"--toy-model", "--toy_model", action="store_true", help="use toy model instead"
157164
)
158165
args = parser.parse_args()
159166

benchmarks/dynamo/runner.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
below) for inference, run them and visualize the logs.
1414
1515
If you want to just print the commands, you could use the following command
16-
-> python benchmarks/runner.py --print_run_commands --suites=torchbench --inference
16+
-> python benchmarks/runner.py --print-run-commands --suites=torchbench --inference
1717
1818
Similarly, if you want to just visualize the already finished logs
19-
-> python benchmarks/runner.py --visualize_logs --suites=torchbench --inference
19+
-> python benchmarks/runner.py --visualize-logs --suites=torchbench --inference
2020
2121
If you want to test float16
2222
-> python benchmarks/runner.py --suites=torchbench --inference --dtypes=float16
@@ -178,11 +178,13 @@ def parse_args():
178178
# Choose either generation of commands, pretty parsing or e2e runs
179179
group = parser.add_mutually_exclusive_group(required=False)
180180
group.add_argument(
181+
"--print-run-commands",
181182
"--print_run_commands",
182183
action="store_true",
183184
help="Generate commands and saves them to run.sh",
184185
)
185186
group.add_argument(
187+
"--visualize-logs",
186188
"--visualize_logs",
187189
action="store_true",
188190
help="Pretty print the log files and draw graphs",
@@ -265,7 +267,11 @@ def parse_args():
265267
help="Github CLI path",
266268
)
267269
parser.add_argument(
268-
"--batch_size", type=int, default=None, help="batch size for benchmarking"
270+
"--batch-size",
271+
"--batch_size",
272+
type=int,
273+
default=None,
274+
help="batch size for benchmarking",
269275
)
270276
parser.add_argument(
271277
"--threads",
@@ -276,12 +282,14 @@ def parse_args():
276282
)
277283
launcher_group = parser.add_argument_group("CPU Launcher Parameters")
278284
launcher_group.add_argument(
285+
"--enable-cpu-launcher",
279286
"--enable_cpu_launcher",
280287
action="store_true",
281288
default=False,
282289
help="Use torch.backends.xeon.run_cpu to get the peak performance on Intel(R) Xeon(R) Scalable Processors.",
283290
)
284291
launcher_group.add_argument(
292+
"--cpu-launcher-args",
285293
"--cpu_launcher_args",
286294
type=str,
287295
default="",
@@ -370,10 +378,10 @@ def generate_commands(args, dtypes, suites, devices, compilers, output_dir):
370378
"inductor",
371379
"inductor_no_cudagraphs",
372380
):
373-
cmd = f"{cmd} --cold_start_latency"
381+
cmd = f"{cmd} --cold-start-latency"
374382

375383
if args.batch_size is not None:
376-
cmd = f"{cmd} --batch_size {args.batch_size}"
384+
cmd = f"{cmd} --batch-size {args.batch_size}"
377385

378386
if args.threads is not None:
379387
cmd = f"{cmd} --threads {args.threads}"

benchmarks/dynamo/test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_benchmark_infra_runs(self) -> None:
3636
"--performance",
3737
"--only=BERT_pytorch",
3838
"-n1",
39-
"--batch_size=1",
39+
"--batch-size=1",
4040
]
4141
)
4242
run(TorchBenchmarkRunner(), args, original_dir)

benchmarks/fastrnns/bench.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def bench_group(model_list, bench_name, bench_group, bench_args):
209209
parser.add_argument('--warmup', default='10', type=int)
210210
parser.add_argument('--nloops', default='100', type=int)
211211
parser.add_argument('--device', default='cuda', type=str)
212-
parser.add_argument('--variable_lstms', action='store_true',
212+
parser.add_argument('--variable-lstms', '--variable_lstms', action='store_true',
213213
help='Also benchmark variable sequence length lstms '
214214
'Note that some of these run really slowly '
215215
'and that the `seqLength` flag will be ignored.')
@@ -224,9 +224,9 @@ def bench_group(model_list, bench_name, bench_group, bench_args):
224224
help='The fuser backend to use. One of: te, old, or none')
225225
parser.add_argument('--executor', default=None, type=str,
226226
help='The executor to use. One of: legacy, simple, profiling')
227-
parser.add_argument('--cuda_pointwise_loop_level', default=None, type=int)
228-
parser.add_argument('--cuda_pointwise_block_count', default=None, type=int)
229-
parser.add_argument('--cuda_pointwise_block_size', default=None, type=int)
227+
parser.add_argument('--cuda-pointwise-loop-level', '--cuda_pointwise_loop_level', default=None, type=int)
228+
parser.add_argument('--cuda-pointwise-block-count', '--cuda_pointwise_block_count', default=None, type=int)
229+
parser.add_argument('--cuda-pointwise-block-size', '--cuda_pointwise_block_size', default=None, type=int)
230230

231231
args = parser.parse_args()
232232
set_fuser(args.fuser, args.executor)

benchmarks/fastrnns/profile.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def full_profile(rnns, **args):
9595
for k, v in args.items():
9696
profile_args.append('--{}={}'.format(k, v))
9797
profile_args.append('--rnns {}'.format(' '.join(rnns)))
98-
profile_args.append('--internal_run')
98+
profile_args.append('--internal-run')
9999

100100
outpath = nvprof_output_filename(rnns, **args)
101101

@@ -114,15 +114,15 @@ def full_profile(rnns, **args):
114114
parser.add_argument('--inputSize', default='512', type=int)
115115
parser.add_argument('--hiddenSize', default='512', type=int)
116116
parser.add_argument('--miniBatch', default='64', type=int)
117-
parser.add_argument('--sleep_between_seconds', default='1', type=int)
117+
parser.add_argument('--sleep-between-seconds', '--sleep_between_seconds', default='1', type=int)
118118
parser.add_argument('--nloops', default='5', type=int)
119119

120120
parser.add_argument('--rnns', nargs='*',
121121
help='What to run. cudnn, aten, jit, etc')
122122

123123
# if internal_run, we actually run the rnns.
124124
# if not internal_run, we shell out to nvprof with internal_run=T
125-
parser.add_argument('--internal_run', default=False, action='store_true',
125+
parser.add_argument('--internal-run', '--internal_run', default=False, action='store_true',
126126
help='Don\'t use this')
127127
args = parser.parse_args()
128128
if args.rnns is None:

benchmarks/fastrnns/test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ def test_vl_py(**test_args):
128128
parser.add_argument('--hiddenSize', default='512', type=int)
129129
parser.add_argument('--miniBatch', default='64', type=int)
130130
parser.add_argument('--device', default='cuda', type=str)
131-
parser.add_argument('--check_grad', default='True', type=bool)
132-
parser.add_argument('--variable_lstms', action='store_true')
131+
parser.add_argument('--check-grad', '--check_grad', default='True', type=bool)
132+
parser.add_argument('--variable-lstms', '--variable_lstms', action='store_true')
133133
parser.add_argument('--seed', default='17', type=int)
134134
parser.add_argument('--verbose', action='store_true')
135135
parser.add_argument('--rnns', nargs='*',

0 commit comments

Comments
 (0)