Skip to content

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented Feb 9, 2023

What does this PR do?

The argparse utilities, namely Trainer.add_argparse_args and Trainer.parse_argparse_args, were introduced early on in Lighting at a time when the Trainer had a relatively simple argument structure. Over time, the variety of types and combinations thereof has grown, leading to a more complex and fragile parsing logic of default values and types, e.g.,

https://github.com/Lightning-AI/lightning/blob/5340d960b9427dcfe5fb953cac0e86763d423546/src/lightning/pytorch/utilities/argparse.py#L143-L155

https://github.com/Lightning-AI/lightning/blob/5340d960b9427dcfe5fb953cac0e86763d423546/src/lightning/pytorch/utilities/argparse.py#L240-L265

We are removing this logic now in a breaking change for Lightning 2.0. The reasons being:

  • Lots of hacky, fragile logic, hard to maintain
  • There are better 3rd party solutions out there: jsonargparse/click/hydra/fire …
  • For the simple scripts, a hand-written argparse does the job as well
  • For several releases, we had the the argparse utils already marked as "legacy" in our docs
  • We practically get no questions or feedback about this feature, indicating that its popularity has decreased
  • It has always been cumbersome to both capture and parse the arguments of both Trainer and LightningModule into one single parser.

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

I made sure I had fun coding 🙃

cc @Borda @justusschock

@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Feb 9, 2023
@awaelchli awaelchli added the fun Staff contributions outside working hours - to differentiate from the "community" label label Feb 10, 2023
@awaelchli awaelchli added this to the 2.0 milestone Feb 10, 2023
@awaelchli awaelchli changed the title WIP: Remove argparse utils Remove argparse utils Feb 11, 2023
@awaelchli awaelchli marked this pull request as ready for review February 11, 2023 04:16
@awaelchli awaelchli added argparse (removed) Related to argument parsing (argparse, Hydra, ...) breaking change Includes a breaking change labels Feb 11, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Feb 11, 2023

⚡ Required checks status: All passing 🟢

Groups summary

🟢 pytorch_lightning: Tests workflow
Check ID Status
pl-cpu (macOS-11, lightning, 3.8, 1.11) success
pl-cpu (macOS-11, lightning, 3.9, 1.12) success
pl-cpu (macOS-11, lightning, 3.10, 1.13) success
pl-cpu (macOS-11, lightning, 3.8, 1.11, oldest) success
pl-cpu (ubuntu-20.04, lightning, 3.9, 1.11) success
pl-cpu (ubuntu-20.04, lightning, 3.10, 1.12) success
pl-cpu (ubuntu-20.04, lightning, 3.10, 1.13) success
pl-cpu (ubuntu-20.04, lightning, 3.8, 1.11, oldest) success
pl-cpu (windows-2022, lightning, 3.9, 1.11) success
pl-cpu (windows-2022, lightning, 3.10, 1.12) success
pl-cpu (windows-2022, lightning, 3.10, 1.13) success
pl-cpu (windows-2022, lightning, 3.8, 1.11, oldest) success
pl-cpu (macOS-11, pytorch, 3.8, 1.13) success
pl-cpu (ubuntu-20.04, pytorch, 3.8, 1.13) success
pl-cpu (windows-2022, pytorch, 3.8, 1.13) success

These checks are required after the changes to src/lightning/pytorch/core/datamodule.py, src/lightning/pytorch/trainer/trainer.py, src/lightning/pytorch/utilities/argparse.py, src/lightning/pytorch/utilities/parsing.py, src/lightning/pytorch/utilities/types.py, tests/tests_pytorch/core/test_datamodules.py, tests/tests_pytorch/models/test_tpu.py, tests/tests_pytorch/trainer/test_trainer_cli.py, tests/tests_pytorch/utilities/test_argparse.py, tests/tests_pytorch/utilities/test_parsing.py.

🟢 pytorch_lightning: Azure GPU
Check ID Status
pytorch-lightning (GPUs) success

These checks are required after the changes to src/lightning/pytorch/core/datamodule.py, src/lightning/pytorch/trainer/trainer.py, src/lightning/pytorch/utilities/argparse.py, src/lightning/pytorch/utilities/parsing.py, src/lightning/pytorch/utilities/types.py, tests/tests_pytorch/core/test_datamodules.py, tests/tests_pytorch/models/test_tpu.py, tests/tests_pytorch/trainer/test_trainer_cli.py, tests/tests_pytorch/utilities/test_argparse.py, tests/tests_pytorch/utilities/test_parsing.py.

🟢 pytorch_lightning: Azure HPU
Check ID Status
pytorch-lightning (HPUs) success

These checks are required after the changes to src/lightning/pytorch/core/datamodule.py, src/lightning/pytorch/trainer/trainer.py, src/lightning/pytorch/utilities/argparse.py, src/lightning/pytorch/utilities/parsing.py, src/lightning/pytorch/utilities/types.py, tests/tests_pytorch/core/test_datamodules.py, tests/tests_pytorch/models/test_tpu.py, tests/tests_pytorch/trainer/test_trainer_cli.py, tests/tests_pytorch/utilities/test_argparse.py, tests/tests_pytorch/utilities/test_parsing.py.

🟢 pytorch_lightning: Azure IPU
Check ID Status
pytorch-lightning (IPUs) success

These checks are required after the changes to src/lightning/pytorch/core/datamodule.py, src/lightning/pytorch/trainer/trainer.py, src/lightning/pytorch/utilities/argparse.py, src/lightning/pytorch/utilities/parsing.py, src/lightning/pytorch/utilities/types.py, tests/tests_pytorch/core/test_datamodules.py, tests/tests_pytorch/models/test_tpu.py, tests/tests_pytorch/trainer/test_trainer_cli.py, tests/tests_pytorch/utilities/test_argparse.py, tests/tests_pytorch/utilities/test_parsing.py.

🟢 pytorch_lightning: Docs
Check ID Status
make-doctest (pytorch) success
make-html (pytorch) success

These checks are required after the changes to src/lightning/pytorch/core/datamodule.py, src/lightning/pytorch/trainer/trainer.py, src/lightning/pytorch/utilities/argparse.py, src/lightning/pytorch/utilities/parsing.py, src/lightning/pytorch/utilities/types.py, docs/source-pytorch/api_references.rst, docs/source-pytorch/cli/lightning_cli.rst, docs/source-pytorch/common/checkpointing_basic.rst, docs/source-pytorch/common/hyperparameters.rst, docs/source-pytorch/common/trainer.rst.

🟢 mypy
Check ID Status
mypy success

These checks are required after the changes to src/lightning/pytorch/core/datamodule.py, src/lightning/pytorch/trainer/trainer.py, src/lightning/pytorch/utilities/argparse.py, src/lightning/pytorch/utilities/parsing.py, src/lightning/pytorch/utilities/types.py.

🟢 install
Check ID Status
install-pkg (ubuntu-22.04, app, 3.8) success
install-pkg (ubuntu-22.04, app, 3.10) success
install-pkg (ubuntu-22.04, fabric, 3.8) success
install-pkg (ubuntu-22.04, fabric, 3.10) success
install-pkg (ubuntu-22.04, pytorch, 3.8) success
install-pkg (ubuntu-22.04, pytorch, 3.10) success
install-pkg (ubuntu-22.04, lightning, 3.8) success
install-pkg (ubuntu-22.04, lightning, 3.10) success
install-pkg (ubuntu-22.04, notset, 3.8) success
install-pkg (ubuntu-22.04, notset, 3.10) success
install-pkg (macOS-12, app, 3.8) success
install-pkg (macOS-12, app, 3.10) success
install-pkg (macOS-12, fabric, 3.8) success
install-pkg (macOS-12, fabric, 3.10) success
install-pkg (macOS-12, pytorch, 3.8) success
install-pkg (macOS-12, pytorch, 3.10) success
install-pkg (macOS-12, lightning, 3.8) success
install-pkg (macOS-12, lightning, 3.10) success
install-pkg (macOS-12, notset, 3.8) success
install-pkg (macOS-12, notset, 3.10) success
install-pkg (windows-2022, app, 3.8) success
install-pkg (windows-2022, app, 3.10) success
install-pkg (windows-2022, fabric, 3.8) success
install-pkg (windows-2022, fabric, 3.10) success
install-pkg (windows-2022, pytorch, 3.8) success
install-pkg (windows-2022, pytorch, 3.10) success
install-pkg (windows-2022, lightning, 3.8) success
install-pkg (windows-2022, lightning, 3.10) success
install-pkg (windows-2022, notset, 3.8) success
install-pkg (windows-2022, notset, 3.10) success

These checks are required after the changes to src/lightning/pytorch/core/datamodule.py, src/lightning/pytorch/trainer/trainer.py, src/lightning/pytorch/utilities/argparse.py, src/lightning/pytorch/utilities/parsing.py, src/lightning/pytorch/utilities/types.py.

🟢 link-check
Check ID Status
markdown-link-check success

These checks are required after the changes to src/lightning/pytorch/CHANGELOG.md.


Thank you for your contribution! 💜

Note
This comment is automatically generated and updates for 60 minutes every 180 seconds. If you have any other questions, contact carmocca for help.

Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Borda Borda enabled auto-merge (squash) February 13, 2023 17:55
@mergify mergify bot added the ready PRs ready to be merged label Feb 13, 2023
@awaelchli awaelchli disabled auto-merge February 13, 2023 19:49
@mergify mergify bot added has conflicts and removed ready PRs ready to be merged labels Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
argparse (removed) Related to argument parsing (argparse, Hydra, ...) breaking change Includes a breaking change fun Staff contributions outside working hours - to differentiate from the "community" label pl Generic label for PyTorch Lightning package ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants