pytorch-lightning icon indicating copy to clipboard operation
pytorch-lightning copied to clipboard

Lightning Module throws error when save_parameters() is not called from init

Open cemde opened this issue 3 years ago • 6 comments

What does this PR do?

The LightningModule will now raise an exception if the save_hyperparameter method is called from outside the __init__ method.

Fixes #12624

Does your PR introduce any breaking changes? If yes, please list them.

No.

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 list all the breaking changes introduced by this pull request?
  • [ ] Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR. Before you start reviewing, make sure you have read the 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?

Make sure you had fun coding 🙃

cemde avatar Jun 07 '22 00:06 cemde

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you need further help see our docs: https://pytorch-lightning.readthedocs.io/en/latest/generated/CONTRIBUTING.html#pull-request or ask the assistance of a core contributor here or on Slack. Thank you for your contributions.

stale[bot] avatar Jun 23 '22 04:06 stale[bot]

Hi @cemde thank you for working on this. Could you address the above review comment? Let me know if you have any questions!

akihironitta avatar Jul 05 '22 03:07 akihironitta

@akihironitta

Sorry been busy. Will add tests asap.

cemde avatar Jul 05 '22 18:07 cemde

@akihironitta I added the changes.

My implementation breaks two tests:

  • tests/tests_pytorch/models/test_hparams.py::test_collect_init_arguments[UnconventionalArgsBoringModel]
  • tests/tests_pytorch/models/test_hparams.py::test_dataclass_lightning_module

Do these tests still reflect a wanted functionality? If so, the fix for the dataclass is easy. The UnconventionalArgsBoringModel does break the assumption of checkpointing that the init args are collected for this exact class to reconstruct it, doesnt it?

cemde avatar Jul 09 '22 15:07 cemde

@akihironitta any opinion on this? :)

cemde avatar Jul 28 '22 19:07 cemde

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id Secret Commit Filename
- Generic High Entropy Secret 78fa3afdfbf964c19b4b2d36b91560698aa83178 tests/tests_app/utilities/test_login.py View secret
- Base64 Basic Authentication 78fa3afdfbf964c19b4b2d36b91560698aa83178 tests/tests_app/utilities/test_login.py View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

gitguardian[bot] avatar Jan 16 '24 09:01 gitguardian[bot]