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

feat(wandb): offset logging step when resuming #5050

Merged
merged 23 commits into from
Dec 19, 2020

Conversation

borisdayma
Copy link
Contributor

What does this PR do?

When resuming a run, the step was not being offset to account for previous logged data.
It will now be correctly offset.

In addition, I took advantage to give users a hint when they have related issues trying to log "back in time". It is usually due to them logging manually other data (images, etc) and causing the wandb step to automatically increase. This will close wandb/wandb#1507

I added the same details in the documentation.

Before submitting

  • Was this discussed/approved via a Github issue? discussed in wandb issue
  • 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? Since the other modification is just a warning
  • 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

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; Bugfixes should be including in bug-fix release milestones (m.f.X) and features should be included in (m.X.b) releases.

Did you have fun?

Make sure you had fun coding 🙃

@pep8speaks
Copy link

pep8speaks commented Dec 10, 2020

Hello @borisdayma! Thanks for updating this PR.

Line 165:121: E501 line too long (122 > 120 characters)

Comment last updated at 2020-12-19 12:33:15 UTC

@awaelchli awaelchli added 3rd party Related to a 3rd-party feature Is an improvement or enhancement logger Related to the Loggers labels Dec 10, 2020
pytorch_lightning/loggers/wandb.py Outdated Show resolved Hide resolved
@awaelchli awaelchli added this to the 1.1.x milestone Dec 10, 2020
@codecov
Copy link

codecov bot commented Dec 10, 2020

Codecov Report

Merging #5050 (78e0d19) into master (4c34855) will increase coverage by 0%.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           master   #5050   +/-   ##
======================================
  Coverage      93%     93%           
======================================
  Files         134     134           
  Lines        9928    9933    +5     
======================================
+ Hits         9242    9247    +5     
  Misses        686     686           

Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
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.

can we add a test for the multiple call?

pytorch_lightning/loggers/wandb.py Outdated Show resolved Hide resolved
@Borda Borda added the ready PRs ready to be merged label Dec 10, 2020
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
@borisdayma
Copy link
Contributor Author

borisdayma commented Dec 10, 2020

can we add a test for the multiple call?

@Borda Sure, you're talking about the warning?

@borisdayma
Copy link
Contributor Author

@Borda I added a test for warnings displayed.

@mergify mergify bot requested a review from a team December 12, 2020 14:56
@@ -154,6 +161,9 @@ def log_metrics(self, metrics: Dict[str, float], step: Optional[int] = None) ->
assert rank_zero_only.rank == 0, 'experiment tried to log from global_rank != 0'

metrics = self._add_prefix(metrics)
if not self.WARNING_DISPLAYED and (step is not None and step + self._step_offset < self.experiment.step):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we have a better way to handle only once displayed Warning. Could be WarningCache. Need to check.

Copy link
Member

Choose a reason for hiding this comment

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

@borisdayma
Copy link
Contributor Author

borisdayma commented Dec 14, 2020

I'm now using WarningCache as suggested by @tchaton but it breaks my tests.
In particular I'm having trouble capturing the warnings. I tried with caplog, capsys and capfd but no output/err seems to be captured, even if I just do a direct call within the test to warnings.warn or logging.log.

Edit: looks like I can use recwarn in this case

@borisdayma
Copy link
Contributor Author

I was able to make the tests work with WarningCache.
I had to rely on recwarn instead of caplog (not sure why) and made a little helper function.

@Borda Borda modified the milestones: 1.1.x, 1.2 Dec 16, 2020
@Borda Borda added bug Something isn't working and removed feature Is an improvement or enhancement labels Dec 16, 2020
@Borda Borda requested a review from tchaton December 19, 2020 12:51
@Borda Borda merged commit e89764e into Lightning-AI:master Dec 19, 2020
Borda added a commit that referenced this pull request Dec 23, 2020
* feat(wandb): offset logging step when resuming

* feat(wandb): output warnings

* fix(wandb): allow step to be None

* test(wandb): update tests

* feat(wandb): display warning only once

* style: fix PEP issues

* tests(wandb): fix tests

* tests(wandb): improve test

* style: fix whitespace

* feat: improve warning

Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>

* feat(wandb): use variable from class instance

Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>

* tests(wandb): check warnings

* feat(wandb): use WarningCache

* tests(wandb): fix tests

* style: fix formatting

Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Borda added a commit that referenced this pull request Dec 29, 2020
* feat(wandb): offset logging step when resuming

* feat(wandb): output warnings

* fix(wandb): allow step to be None

* test(wandb): update tests

* feat(wandb): display warning only once

* style: fix PEP issues

* tests(wandb): fix tests

* tests(wandb): improve test

* style: fix whitespace

* feat: improve warning

Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>

* feat(wandb): use variable from class instance

Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>

* tests(wandb): check warnings

* feat(wandb): use WarningCache

* tests(wandb): fix tests

* style: fix formatting

Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Borda added a commit that referenced this pull request Jan 4, 2021
* feat(wandb): offset logging step when resuming

* feat(wandb): output warnings

* fix(wandb): allow step to be None

* test(wandb): update tests

* feat(wandb): display warning only once

* style: fix PEP issues

* tests(wandb): fix tests

* tests(wandb): improve test

* style: fix whitespace

* feat: improve warning

Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>

* feat(wandb): use variable from class instance

Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>

* tests(wandb): check warnings

* feat(wandb): use WarningCache

* tests(wandb): fix tests

* style: fix formatting

Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Borda added a commit that referenced this pull request Jan 4, 2021
* feat(wandb): offset logging step when resuming

* feat(wandb): output warnings

* fix(wandb): allow step to be None

* test(wandb): update tests

* feat(wandb): display warning only once

* style: fix PEP issues

* tests(wandb): fix tests

* tests(wandb): improve test

* style: fix whitespace

* feat: improve warning

Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>

* feat(wandb): use variable from class instance

Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>

* tests(wandb): check warnings

* feat(wandb): use WarningCache

* tests(wandb): fix tests

* style: fix formatting

Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Borda added a commit that referenced this pull request Jan 5, 2021
* feat(wandb): offset logging step when resuming

* feat(wandb): output warnings

* fix(wandb): allow step to be None

* test(wandb): update tests

* feat(wandb): display warning only once

* style: fix PEP issues

* tests(wandb): fix tests

* tests(wandb): improve test

* style: fix whitespace

* feat: improve warning

Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>

* feat(wandb): use variable from class instance

Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>

* tests(wandb): check warnings

* feat(wandb): use WarningCache

* tests(wandb): fix tests

* style: fix formatting

Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd party Related to a 3rd-party bug Something isn't working logger Related to the Loggers ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WandB-Logger drops all the logged values in training step for PyTorch Lightning
7 participants