Skip to content
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

gradient verification callback #465

Merged
merged 40 commits into from Jan 18, 2021
Merged

gradient verification callback #465

merged 40 commits into from Jan 18, 2021

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented Dec 20, 2020

What does this PR do?

Fixes #194
Adds the requested callbacks for model verification.
It's copied from my personal repository.

cc @TylerYep

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • 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? Otherwise, we ask you to create a separate PR for every change.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

PR review

  • Is this pull request ready for review? (if not, please submit in draft mode)

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@pep8speaks
Copy link

pep8speaks commented Dec 20, 2020

Hello @awaelchli! Thanks for updating this PR.

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-01-18 08:36:55 UTC

@codecov
Copy link

codecov bot commented Dec 20, 2020

Codecov Report

Merging #465 (224de45) into master (99232c3) will decrease coverage by 52.84%.
The diff coverage is 51.92%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #465       +/-   ##
===========================================
- Coverage   78.95%   26.10%   -52.85%     
===========================================
  Files         105      107        +2     
  Lines        6121     6201       +80     
===========================================
- Hits         4833     1619     -3214     
- Misses       1288     4582     +3294     
Flag Coverage Δ
cpu 26.10% <51.92%> (+0.44%) ⬆️
pytest 26.10% <51.92%> (+0.44%) ⬆️
unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pl_bolts/callbacks/data_monitor.py 40.70% <0.00%> (-46.91%) ⬇️
pl_bolts/callbacks/verification/base.py 46.34% <46.34%> (ø)
pl_bolts/callbacks/verification/batch_gradient.py 54.23% <54.23%> (ø)
pl_bolts/callbacks/__init__.py 100.00% <100.00%> (ø)
pl_bolts/utils/__init__.py 100.00% <100.00%> (ø)
pl_bolts/models/rl/common/agents.py 0.00% <0.00%> (-100.00%) ⬇️
pl_bolts/models/rl/dueling_dqn_model.py 0.00% <0.00%> (-100.00%) ⬇️
...l_bolts/models/rl/vanilla_policy_gradient_model.py 0.00% <0.00%> (-96.37%) ⬇️
pl_bolts/models/rl/double_dqn_model.py 0.00% <0.00%> (-95.66%) ⬇️
pl_bolts/models/rl/common/gym_wrappers.py 0.00% <0.00%> (-91.60%) ⬇️
... and 64 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 99232c3...ae63dad. Read the comment docs.

Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

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

LGTM, just would be nice to have tests for uncovered lines...

docs/source/info_callbacks.rst Outdated Show resolved Hide resolved
@Borda Borda force-pushed the feature/gradient-verification branch from c0d4f19 to 9f2adcd Compare December 20, 2020 23:05
@awaelchli
Copy link
Contributor Author

@Borda ok, I will try to make it higher

@TylerYep
Copy link

Thank you so much for implementing this!

Copy link
Contributor

@akihironitta akihironitta left a comment

Choose a reason for hiding this comment

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

@awaelchli I love this feature! I left some minor suggestions on typing and docs, so would you mind having a look at them? They should be resolved by clicking some buttons in your browser :]

docs/source/info_callbacks.rst Outdated Show resolved Hide resolved
docs/source/info_callbacks.rst Outdated Show resolved Hide resolved
pl_bolts/callbacks/verification/base.py Outdated Show resolved Hide resolved
pl_bolts/callbacks/verification/base.py Outdated Show resolved Hide resolved
pl_bolts/callbacks/verification/base.py Outdated Show resolved Hide resolved
pl_bolts/callbacks/verification/batch_gradient.py Outdated Show resolved Hide resolved
pl_bolts/callbacks/verification/batch_gradient.py Outdated Show resolved Hide resolved
pl_bolts/callbacks/verification/batch_gradient.py Outdated Show resolved Hide resolved
pl_bolts/callbacks/verification/batch_gradient.py Outdated Show resolved Hide resolved
@tchaton
Copy link

tchaton commented Jan 9, 2021

Hey @awaelchli, why not push it directly to PL ?

@awaelchli
Copy link
Contributor Author

Because @williamFalcon wants only essential callbacks in core PL library, and all non-essential, specialized callbacks here in bolts. Or at least this the information I have back from when pl_bolts was created, maybe it changed. I do not want to force this into any library unless team/community wants it.

@tchaton
Copy link

tchaton commented Jan 9, 2021

Because @williamFalcon wants only essential callbacks in core PL library, and all non-essential, specialized callbacks here in bolts. Or at least this the information I have back from when pl_bolts was created, maybe it changed. I do not want to force this into any library unless team/community wants it.

This looks like a great feature and we need to provide more callback examples to people.

It is up to you, but I see its value for PL.

@awaelchli
Copy link
Contributor Author

This looks like a great feature and we need to provide more callback examples to people.
It is up to you, but I see its value for PL.

Thank you for the kind feedback. Ok, let me adress the remaining review comments here on the PR and I will double check with William.

self.model = model

@abstractmethod
def check(self, *args: Any, **kwargs: Any) -> bool:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@akihironitta this mypy tool is not very smart :( It is not liking that the subclass has different args than here. I want this abstract method to be as general as possible and not specify concrete arguments and types. It should only act as an interface. Any suggestions how to proceed? I believe I have to add # type: ignore

Copy link
Contributor

Choose a reason for hiding this comment

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

I found a related issue in mypy repo, and it basically says that an easy workaround would be to add # type: ignore[override], so shall we just ignore it then?
python/mypy#1237 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no chance, it won't work. I tried to put it everywhere: at the top of method, on the same line as signature, below it, on top of the class, on top of the file, both in subclass and superclass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to spam #type: ignore everywhere to make it work.
This mypy tool, I don't understand it. I spent hours now studying the docs of this tool trying to figure out what the error messages mean. I tried everything, but the type: ignore are unavoidable, yet they pollute the code unnecessarily. It's unbelievably frustrating, and I can no longer work on this, sorry.

Copy link
Contributor

Choose a reason for hiding this comment

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

I completely understand your frustration. Let's ignore them all for now.

@akihironitta akihironitta self-requested a review January 16, 2021 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
callback enhancement New feature or request ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some callbacks for debugging and visualization
6 participants