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

add types in bolts/callbacks #444

Merged
merged 26 commits into from
Jan 4, 2021
Merged

add types in bolts/callbacks #444

merged 26 commits into from
Jan 4, 2021

Conversation

ydcjeff
Copy link
Contributor

@ydcjeff ydcjeff commented Dec 11, 2020

What does this PR do?

Part of #434

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 11, 2020

Hello @ydcjeff! Thanks for updating this PR.

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

Comment last updated at 2021-01-04 11:08:33 UTC

@ydcjeff
Copy link
Contributor Author

ydcjeff commented Dec 11, 2020

I need help with the failed mypy check.

@codecov
Copy link

codecov bot commented Dec 11, 2020

Codecov Report

Merging #444 (798f68b) into master (efac971) will decrease coverage by 0.04%.
The diff coverage is 90.27%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #444      +/-   ##
==========================================
- Coverage   79.15%   79.10%   -0.05%     
==========================================
  Files         102      102              
  Lines        5906     5921      +15     
==========================================
+ Hits         4675     4684       +9     
- Misses       1231     1237       +6     
Flag Coverage Δ
cpu 25.57% <65.27%> (+0.20%) ⬆️
pytest 25.57% <65.27%> (+0.20%) ⬆️
unittests 78.61% <90.27%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
pl_bolts/utils/shaping.py 40.00% <ø> (+3.63%) ⬆️
pl_bolts/callbacks/vision/confused_logit.py 76.92% <66.66%> (-23.08%) ⬇️
pl_bolts/callbacks/printing.py 71.18% <69.23%> (+0.49%) ⬆️
pl_bolts/callbacks/byol_updates.py 100.00% <100.00%> (ø)
pl_bolts/callbacks/data_monitor.py 87.61% <100.00%> (-1.68%) ⬇️
pl_bolts/callbacks/ssl_online.py 96.42% <100.00%> (+0.13%) ⬆️
pl_bolts/callbacks/variational.py 95.91% <100.00%> (+0.26%) ⬆️
pl_bolts/callbacks/vision/image_generation.py 91.30% <100.00%> (ø)
pl_bolts/utils/__init__.py 100.00% <100.00%> (ø)
pl_bolts/datasets/kitti_dataset.py 32.69% <0.00%> (-1.93%) ⬇️
... and 2 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 efac971...db6637d. Read the comment docs.

@ydcjeff
Copy link
Contributor Author

ydcjeff commented Dec 11, 2020

matplotlib is needed for adding types in confused logits callbacks. how shall we do it?

pl_bolts/callbacks/byol_updates.py Outdated Show resolved Hide resolved
pl_bolts/callbacks/data_monitor.py Outdated Show resolved Hide resolved
pl_bolts/callbacks/data_monitor.py Outdated Show resolved Hide resolved
setup.cfg Show resolved Hide resolved
@akihironitta
Copy link
Contributor

@ydcjeff

matplotlib is needed for adding types in confused logits callbacks. how shall we do it?

I'm adding matplotlib to the (optional) requirements in #450, so after having it merged, it should work without any issue I suppose :]

@akihironitta akihironitta self-assigned this Dec 14, 2020
@ydcjeff ydcjeff changed the title add types in bolts/callbacks blocked by #450 add types in bolts/callbacks Dec 14, 2020
@ydcjeff ydcjeff changed the title blocked by #450 add types in bolts/callbacks [blocked by #450] add types in bolts/callbacks Dec 14, 2020
@akihironitta akihironitta mentioned this pull request Dec 15, 2020
17 tasks
@Borda Borda changed the title [blocked by #450] add types in bolts/callbacks add types in bolts/callbacks Dec 16, 2020
@Borda
Copy link
Member

Borda commented Dec 16, 2020

@ydcjeff can we resolve conflits?

@ydcjeff ydcjeff requested a review from Borda December 20, 2020 17:21
.github/workflows/ci_test-base.yml Outdated Show resolved Hide resolved
pl_bolts/callbacks/data_monitor.py Outdated Show resolved Hide resolved
pl_bolts/callbacks/variational.py Outdated Show resolved Hide resolved
pl_bolts/callbacks/variational.py Outdated Show resolved Hide resolved
pl_bolts/callbacks/vision/confused_logit.py Outdated Show resolved Hide resolved
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.

LGTM other than the below comment! Thank you for your work!

pl_bolts/callbacks/data_monitor.py Outdated Show resolved Hide resolved
Co-authored-by: Akihiro Nitta <nitta@akihironitta.com>
@Borda
Copy link
Member

Borda commented Jan 3, 2021

the docs fail, probably we need to add matplotlib also to docs requirements

@ydcjeff
Copy link
Contributor Author

ydcjeff commented Jan 3, 2021

I have tested locally, the docs build still fail even if installed matplotlib.
The thing is autodoc tracks _MATPLOTLIB_AVAILABLE to the _module_available function. so when we print _MATPLOTLIB_AVAILABLE, it shows pytorch_lightning.utilities._module_available, so resulting import warning.
any other solution in mind?

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.

@ydcjeff Sorry for the delay! I looked through how other OSS projects deal with types of optional packages, and I found that, in Optuna, they assign object to the types (class names) when optional packages are unavailable. https://github.com/optuna/optuna/blob/392088c25d661b997c4143fd18ccdb7480ffa825/optuna/integration/pytorch_lightning.py#L4-L12

Do you think following this convention sound reasonable?

pl_bolts/callbacks/vision/confused_logit.py Outdated Show resolved Hide resolved
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.

@ydcjeff lgtm. Thank you!

@Borda Borda merged commit ce3187d into Lightning-Universe:master Jan 4, 2021
@ydcjeff ydcjeff deleted the types/callbacks branch January 4, 2021 11:23
self,
trainer: Trainer,
pl_module: LightningModule,
batch: Sequence,
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

self._train_batch_idx = batch_idx

def log_histograms(self, batch, group="") -> None:
def log_histograms(self, batch: Sequence, group: str = "") -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

self._trainer = trainer

def on_train_batch_start(
self, trainer, pl_module, batch, batch_idx, dataloader_idx
):
self, trainer: Trainer, pl_module: LightningModule, batch: Sequence, batch_idx: int, dataloader_idx: int
Copy link
Contributor

Choose a reason for hiding this comment

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

for batch it is too strict, this could be almost anything (Any)

@Borda
Copy link
Member

Borda commented Jan 4, 2021

@ydcjeff mind send another PR addressing @awaelchli comments?

@ydcjeff ydcjeff mentioned this pull request Jan 4, 2021
8 tasks
@akihironitta akihironitta mentioned this pull request Jan 9, 2021
8 tasks
@Borda Borda added this to the v0.3 milestone Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants