-
Notifications
You must be signed in to change notification settings - Fork 693
[WIP] 'tune cat' command for pretty printing configuration files #2298
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/2298
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Still a work in progress, but I’d love to gather as much feedback as possible while it's still in the oven! |
|
Thanks so much for the awesome RFC and for putting this up @Ankur-singh! Would you be able to attach some example output(s) from using the command to the PR description? |
|
@SalmanMohammadi Thank you for the comment. I have added the command outs for different scenarios. This should make it easy for other as well. Again, thank you very much. |
joecummings
left a comment
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.
Command looks good, just a few comments on docstrings and impl
torchtune/_cli/cat.py
Outdated
| $ tune cat non_existent_config | ||
| Config 'non_existent_config' not found. | ||
|
|
||
| $ tune cat some_recipe |
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 don't think we need an example for recipe
torchtune/_cli/cat.py
Outdated
| Config 'non_existent_config' not found. | ||
|
|
||
| $ tune cat some_recipe | ||
| 'some_recipe' is a recipe, not a config. Please use a config name. |
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.
Can you add an additional line down here saying that they can find all the cat-able configs via the tune ls command? You can also provide an example of launching a run overriding a key that was found via the new tune cat command.
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.
Thats a great idea. In fact, this is was the original motivation.
torchtune/_cli/cat.py
Outdated
| from torchtune._cli.subcommand import Subcommand | ||
| from torchtune._recipe_registry import Config, get_all_recipes | ||
|
|
||
| ROOT = Path(torchtune.__file__).parent.parent |
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.
Ugh, we need to find a different way to do this (laziness on my part, I apologize). I suspect the call to import torchtune significantly slows down the execution of the CLI.
The key part here is that we want to find the underlying project in which the torchtune package is installed. For a local installation AND for a PyPI installation, it should be two levels up from the init.py file. So theoretically it's three levels up from any of the CLI files.
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.
Yes, importing torchtune is slow. I will address this issue. We will need to update other CLI files that import torchtune as well, but it might be better to handle that in a separate PR to avoid scope creep.
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.
Yep, let's do this in another PR.
torchtune/_cli/cat.py
Outdated
| if config.name == config_str: | ||
| return config | ||
|
|
||
| def _print_file(self, file: str) -> None: |
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.
_print_yaml_file is a little more descriptive.
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.
Can you please elaborate it further? What do you mean by "descriptive"?
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.
It's a nit for sure, but this doesn't just print any file. It only takes in and prints a YAML file, therefore the name should be something like print_yaml_file.
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.
Yes, thats a good point. Will update the function name.
torchtune/_cli/cat.py
Outdated
| "cat", | ||
| prog="tune cat", | ||
| help="Pretty print a config", | ||
| description="Pretty print a config", |
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.
Can you add something related to WHY someone might want to do this? E.g. pretty print a config, making it easy to know which keys you can override when launching a training run (or something a little more concise)
torchtune/_cli/cat.py
Outdated
| task: full_finetune | ||
| ... | ||
|
|
||
| $ tune cat non_existent_config |
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.
No need for negative examples
| epilog=textwrap.dedent( | ||
| """\ | ||
| examples: | ||
| $ tune cat llama2/7B_full |
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.
Can you add an example of tune cat LOCALFILE.yaml
torchtune/_cli/cat.py
Outdated
| yaml.dump( | ||
| data, | ||
| default_flow_style=False, | ||
| sort_keys=False, |
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 personally find the sorted configs easier to read when printed.
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.
@SalmanMohammadi I can make it an argument. Something like --sort. Thoughts?
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.
cc @ebsmothers @joecummings thoughts?
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 like the idea of a --sort argument. I agree that sorted configs are a little easier to read; however, they wouldn't look like our configs on Github, which would be confusing so the default should be to match what we show on Github.
|
Would you be up for adding a little section for your shiny new command in the docs? : ) https://github.com/pytorch/torchtune/blob/main/docs/source/tune_cli.rst |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2298 +/- ##
==========================================
+ Coverage 9.19% 23.88% +14.68%
==========================================
Files 292 360 +68
Lines 17740 21295 +3555
==========================================
+ Hits 1631 5086 +3455
- Misses 16109 16209 +100 ☔ View full report in Codecov by Sentry. |
d703700 to
20801e3
Compare
|
@SalmanMohammadi and @joecummings Thank you so much for all the amazing feedback. I have made all the requested changes. |
torchtune/_cli/cat.py
Outdated
| # Pretty print the contents of LOCALFILE.yaml | ||
| $ tune cat LOCALFILE.yaml | ||
|
|
||
| # Example of launching a run overriding a key found via the `tune cat` command: |
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.
super nit, but take a look at how I did this for tune ls: https://github.com/pytorch/torchtune/blob/d4465c8b21629949a404f821528badb35962502f/torchtune/_cli/ls.py#L37
It should be unindented OUT of the examples section and instead be considered a followup.
e.g.
examples:
$ tune cat llama2/7B_full
...
$ tune cat LOCALFILE.yaml
...
You can now easily override a key based on your findings from `tune cat`:
$ tune run full_finetune_distributed ...
Need to find all the "cat"-able configs? Try `tune ls`!
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.
Done!
torchtune/_cli/cat.py
Outdated
| self._parser = subparsers.add_parser( | ||
| "cat", | ||
| prog="tune cat", | ||
| help="Pretty print a config, making it easy to override parameters when using `tune run`", |
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.
nit: "making it easy to know which parameters you can override with tune run.
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.
Done
joecummings
left a comment
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.
This looks awesome! Just two more nits I swear :)
joecummings
left a comment
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.
🫡🫡🫡
Context
What is the purpose of this PR? Is it to
Please link to any issues this PR addresses. #2281
Changelog
What are the changes made in this PR?
catsubcommand for the CLItune catTest plan
Please make sure to do each of the following if applicable to your PR. If you're unsure about any one of these just ask and we will happily help. We also have a contributing page for some guidance on contributing.
pre-commit install)pytest testspytest tests -m integration_testWhen file doesn't exist:
When some other file is passed:
When recipe name is passed:
When correct config is passed:
UX
If your function changed a public API, please add a dummy example of what the user experience will look like when calling it.
Here is a docstring example
and a tutorial example