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 is_sync logic to Metric #339

Merged
merged 31 commits into from
Jul 1, 2021
Merged

Add is_sync logic to Metric #339

merged 31 commits into from
Jul 1, 2021

Conversation

tchaton
Copy link
Contributor

@tchaton tchaton commented Jul 1, 2021

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 to update the docs?
  • Did you write any new necessary tests?

What does this PR do?

This PR makes synchornization, state_dict and load_dict generation fully manual for the users, so they have full control on their metric states.

for i in range(steps):

    metric(i)

    metric.sync()
    state_dict = metric.state_dict() # synced states
    assert metric.is_synced 

    metric.unsync()
    state_dict = metric.state_dict() # local states
    assert not metric.is_synced 

Fixes # (issue).

PR review

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 Jul 1, 2021

Hello @tchaton! Thanks for updating this PR.

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

Comment last updated at 2021-07-01 17:43:39 UTC

@codecov
Copy link

codecov bot commented Jul 1, 2021

Codecov Report

Merging #339 (5d33441) into master (18056a5) will decrease coverage by 20.40%.
The diff coverage is 45.23%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #339       +/-   ##
===========================================
- Coverage   96.37%   75.97%   -20.41%     
===========================================
  Files         111      112        +1     
  Lines        3586     3600       +14     
===========================================
- Hits         3456     2735      -721     
- Misses        130      865      +735     
Flag Coverage Δ
Linux 75.97% <45.23%> (-0.02%) ⬇️
Windows 75.97% <45.23%> (-0.02%) ⬇️
cpu 75.97% <45.23%> (-20.35%) ⬇️
gpu ?
macOS 75.97% <45.23%> (-20.35%) ⬇️
pytest 75.97% <45.23%> (-20.41%) ⬇️
python3.6 ?
python3.8 ?
torch1.3.1 ?
torch1.4.0 ?
torch1.9.0 ?

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

Impacted Files Coverage Δ
torchmetrics/metric.py 57.18% <43.90%> (-38.36%) ⬇️
torchmetrics/utilities/exceptions.py 100.00% <100.00%> (ø)
torchmetrics/utilities/distributed.py 17.24% <0.00%> (-81.04%) ⬇️
torchmetrics/image/kid.py 18.39% <0.00%> (-78.17%) ⬇️
torchmetrics/image/inception.py 30.00% <0.00%> (-65.00%) ⬇️
torchmetrics/image/fid.py 32.55% <0.00%> (-51.17%) ⬇️
torchmetrics/classification/auc.py 50.00% <0.00%> (-50.00%) ⬇️
torchmetrics/classification/kldivergence.py 37.50% <0.00%> (-50.00%) ⬇️
torchmetrics/functional/classification/auroc.py 44.92% <0.00%> (-40.58%) ⬇️
torchmetrics/functional/classification/accuracy.py 55.71% <0.00%> (-38.58%) ⬇️
... and 70 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 18056a5...5d33441. Read the comment docs.

@tchaton tchaton self-assigned this Jul 1, 2021
@tchaton tchaton added this to the v0.4 milestone Jul 1, 2021
@tchaton tchaton added the bug / fix Something isn't working label Jul 1, 2021
Copy link
Member

@justusschock justusschock left a comment

Choose a reason for hiding this comment

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

Looks good so far, some comments :)

torchmetrics/metric.py Outdated Show resolved Hide resolved
torchmetrics/utilities/device_dtype_mixin.py Outdated Show resolved Hide resolved
torchmetrics/utilities/device_dtype_mixin.py Outdated Show resolved Hide resolved
tests/bases/test_ddp.py Outdated Show resolved Hide resolved
torchmetrics/utilities/exceptions.py Outdated Show resolved Hide resolved
torchmetrics/metric.py Show resolved Hide resolved
Co-authored-by: Nicki Skafte <skaftenicki@gmail.com>
@Borda Borda changed the title [bugfix] Add is_sync logic to Metric Add is_sync logic to Metric Jul 1, 2021
@Borda Borda added API / design enhancement New feature or request Important milestonish and removed bug / fix Something isn't working labels Jul 1, 2021
torchmetrics/utilities/exceptions.py Outdated Show resolved Hide resolved
@Borda Borda added the ready label Jul 1, 2021
torchmetrics/metric.py Outdated Show resolved Hide resolved
torchmetrics/metric.py Outdated Show resolved Hide resolved
torchmetrics/metric.py Show resolved Hide resolved
torchmetrics/metric.py Outdated Show resolved Hide resolved
torchmetrics/metric.py Outdated Show resolved Hide resolved
torchmetrics/metric.py Outdated Show resolved Hide resolved
torchmetrics/utilities/exceptions.py Outdated Show resolved Hide resolved
@chauhang
Copy link

chauhang commented Jul 1, 2021

@tchaton Model saving after DDP training is working fine with this fix. Tested for single and multi-gpus.

@tchaton tchaton enabled auto-merge (squash) July 1, 2021 17:51
@tchaton tchaton merged commit 299de5b into master Jul 1, 2021
@tchaton tchaton deleted the fix_ddp branch July 1, 2021 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API / design enhancement New feature or request Important milestonish ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants