-
Notifications
You must be signed in to change notification settings - Fork 966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable using dash or underscore in CLI #2525
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Zach, in the OP, the 2 lines of code are identical - a copy-n-paste mistake? |
OP was posted before I did this 😅 I'll go update it! |
Actually, was weird phrasing on my end. Edited it to be more succinct :) |
I meant this:
the 2 are identical. but it has OR in between. |
oh, wait, they aren't identical ;) it's the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm +/- in this PR. I understand the goal to enable both ways of writing this, but I'm uncertain if the extra complexity is worth it.
We override two private methods, which in turn use more private methods. Are we sure that they work in all edge cases with all Python versions? Is the new code 100% covered by tests? If there is an issue there, it has the potential to break our users' scripts.
I went looking for alternatives. argparse
has the concept of custom Action
s, which could be a solution, but the documentation wasn't very helpful IMO:
https://docs.python.org/3/library/argparse.html#action-classes
Also, at a different place, it says "New in version 3.9", so not sure if this works with 3.8.
Maybe another way would be to detect if there are missing arguments with _
in the name that, if replaced by -
, would match an existing argument, and then add a useful warning, but leave the arguments untouched otherwise? This could be less disruptive.
Also note:
(option_tuple,) = option_tuples | ||
return option_tuple | ||
|
||
# If not found, but looks like a negative number, probably posisional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# If not found, but looks like a negative number, probably posisional | |
# If not found, but looks like a negative number, probably positional |
Test cases revolving around the CLI wrappers | ||
""" | ||
|
||
def test_hiphen(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_hiphen(self): | |
def test_hyphen(self): |
@@ -127,10 +128,13 @@ def __call__(self, parser, namespace, values, option_string=None): | |||
|
|||
|
|||
def launch_command_parser(subparsers=None): | |||
description = "Launch a python script in a distributed scenario. Arguments can be passed in with either hyphens (`a-b`) or underscores (`a_b`)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the doc would be clearer with a real example, for num-processes
instead of a-b
.
import argparse | ||
|
||
|
||
class ArgumentParserWithDashSupport(argparse.ArgumentParser): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be easier to just override add_argument()
add dash-y aliases for option strings that have underscores?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The aim is to not bloat --help
, these are passthrough arguments to downstream API hook-ins such as torchrun
which uses -
rather than _
.
What does this PR do?
This PR adds a pinch of magic for users that are used to doing
--a-b
with arguments that pass-through to things such astorchrun
, accelerate can process those if we have them defined ourselves already.E.g. a user can do:
accelerate launch --no_python --multi_gpu --num_processes 8 --monitor_interval=1 ./trampoline.sh python3 -c "print('hello')"
OR:
accelerate launch --no-python --multi-gpu --num-processes 8 --monitor-interval=1 ./trampoline.sh python3 -c "print('hello')"
Fixes #2241
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@BenjaminBossan, @stas00 (for your future sanity 😄 )