question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] allow for dashed overrides

See original GitHub issue

🚀 Feature Request

It would be nice if one could use dashed overrides as well as the current non-dashed version

arg1: default1
arg2: default2
python app.py arg1=override1 arg2=override2
python app.py arg1=override1 --arg2=override2
python app.py arg1=override1 --arg3=unknown_arg1  # this still fails

Some scripts assume that arguments have the preceding dashes and thus breaks if you call hydra scripts. A notable example is the pytorch distributed launch script. The pytorch example basically invokes multiple runs of the given command with --local_rank={local_rank} attached to the command. So even if you have local_rank as an expected variable in your hydra config, it fails because of the formatting of the variable.

Motivation

I want to use hydra with pytorch distributed training and specifically something like python -m torch.distributed.launch --nproc_per_node=2 app.py arg1=override1

Pitch

I haven’t done extensive testing, but I think the following diff on hydra/_internal/utils.py would enable this feature.

diff --git a/hydra/_internal/utils.py b/hydra/_internal/utils.py
index 7eb38bf0..f23ac64f 100644
--- a/hydra/_internal/utils.py
+++ b/hydra/_internal/utils.py
@@ -148,6 +148,15 @@ def create_config_search_path(search_path_dir: Optional[str]) -> ConfigSearchPat
     return search_path
 
 
+def _convert_dashed_args(unknown_args: List[str]) -> List[str]:
+    new_args = []
+    for arg in unknown_args:
+        while arg.startswith("-"):
+            arg = arg[1:]
+        new_args.append(arg)
+    return new_args
+
+
 def run_hydra(
     args_parser: argparse.ArgumentParser,
     task_function: TaskFunction,
@@ -172,7 +181,8 @@ def run_hydra(
         task_name=task_name, config_search_path=search_path, strict=strict
     )
     try:
-        args = args_parser.parse_args()
+        args, unknown_args = args_parser.parse_known_args()
+        args.overrides += _convert_dashed_args(unknown_args)
         if args.help:
             hydra.app_help(config_name=config_name, args_parser=args_parser, args=args)
             sys.exit(0)
@@ -276,7 +286,9 @@ def get_args_parser() -> argparse.ArgumentParser:
 
 
 def get_args(args: Optional[Sequence[str]] = None) -> Any:
-    return get_args_parser().parse_args(args=args)
+    known_args, unknown_args = get_args_parser().parse_known_args(args=args)
+    known_args.overrides += _convert_dashed_args(unknown_args)
+    return known_args
 
 
 def _strict_mode_strategy(strict: Optional[bool], config_name: Optional[str]) -> bool:

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
reactivetypecommented, Apr 3, 2020

Another use case where – syntax would be nice to have is for use with some editors’s launch configuration. For e.g., with MS Visual studio code, we would pass a list of args as follows:

args = [ ''--param_1=value1", "--param2=value2"]
1reaction
omrycommented, Apr 3, 2020

@reactivetype :

Another use case where – syntax would be nice to have is for use with some editors’s launch configuration. For e.g., with MS Visual studio code, we would pass a list of args as follows:

args = [ ''--param_1=value1", "--param2=value2"]

I am not using VSC myself, by traditionally IDEs does not assume getopt style and allow you to pass anything to the app.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Take advantage of Local Overrides when developing with Safari
Safari's Local Overrides allows us to simply instruct the browser about what a certain request or response to/from a given endpoint should be ......
Read more >
Maybe this is a feature request? | Dash Forum
I know how to ~/.dashcore/dash-cli getnewaddress It stands to reason that, ... Which is likely why nothing has been implemented; to allow flexibility....
Read more >
Allow component instance overrides to be inherited by all states
Allow component instance overrides to be inherited by all states ... These are no feature requests, just cries for XD to be made...
Read more >
validation-overrides.xml - Vespa Documentation
Validations which can be overridden in this way are returned with a dash-separated validation-id preceding the validation message. E.g. if the message is...
Read more >
Advanced Callbacks | Dash for Python Documentation | Plotly
inputs and states : allow you to access the callback params by ID and prop ... under which the dash-renderer front-end client can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found