Commit 7e436109 authored by Mik Vyatskov's avatar Mik Vyatskov Committed by Facebook GitHub Bot
Browse files

Introduce a helper to convert args to CLI args

Summary:
Pull Request resolved: https://github.com/facebookresearch/d2go/pull/290

When running through torchx, converting from arguments to CLI arguments is necessary.

Reviewed By: wat3rBro

Differential Revision: D37086938

fbshipit-source-id: d17c4e36bece8eb02955263181789b71e3483a40
parent 73763a16
...@@ -7,6 +7,7 @@ Detection Training Script. ...@@ -7,6 +7,7 @@ Detection Training Script.
import logging import logging
import sys import sys
from typing import List, Optional, Union
import detectron2.utils.comm as comm import detectron2.utils.comm as comm
from d2go.distributed import launch from d2go.distributed import launch
...@@ -103,5 +104,43 @@ def cli(args): ...@@ -103,5 +104,43 @@ def cli(args):
run_with_cmdline_args(parser.parse_args(args)) run_with_cmdline_args(parser.parse_args(args))
def build_cli_args(
config_path: str,
output_dir: str,
runner_name: Optional[str] = None,
num_processes: Optional[Union[int, str]] = None,
num_machines: Optional[Union[int, str]] = None,
machine_rank: Optional[Union[int, str]] = None,
dist_url: Optional[str] = None,
dist_backend: Optional[str] = None,
eval_only: bool = False,
resume: bool = False,
) -> List[str]:
"""Returns parameters in the form of CLI arguments for train_net binary."""
args = [
"--config-file",
config_path,
"--output-dir",
output_dir,
]
if runner_name is not None:
args += ["--runner", runner_name]
if num_processes is not None:
args += ["--num-processes", str(num_processes)]
if num_machines is not None:
args += ["--num-machines", str(num_machines)]
if machine_rank is not None:
args += ["--machine-rank", str(machine_rank)]
if dist_url is not None:
args += ["--dist-url", str(dist_url)]
if dist_backend is not None:
args += ["--dist-backend", str(dist_backend)]
if eval_only:
args += ["--eval-only"]
if resume:
args += ["--resume"]
return args
if __name__ == "__main__": if __name__ == "__main__":
cli(sys.argv[1:]) cli(sys.argv[1:])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment