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

Changes for Test Differentiability [2/n] #178

Merged
merged 18 commits into from
Apr 30, 2021
Merged

Changes for Test Differentiability [2/n] #178

merged 18 commits into from
Apr 30, 2021

Conversation

bhadreshpsavani
Copy link
Contributor

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?

Fixes #26

PR review

@SkafteNicki

Note:

  • After My changes in the Test File, Test Cases that I wrote were failing for a few scenarios
  • I value of Differentiability Property might not be very accurate. I wrote it according to my understanding and few internet searches

@pep8speaks
Copy link

pep8speaks commented Apr 18, 2021

Hello @bhadreshpsavani! Thanks for updating this PR.

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

Comment last updated at 2021-04-30 13:12:29 UTC

@codecov
Copy link

codecov bot commented Apr 18, 2021

Codecov Report

Merging #178 (bb57cb5) into master (8d9c592) will increase coverage by 0.01%.
The diff coverage is 95.65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #178      +/-   ##
==========================================
+ Coverage   96.65%   96.67%   +0.01%     
==========================================
  Files         180      180              
  Lines        5744     5770      +26     
==========================================
+ Hits         5552     5578      +26     
  Misses        192      192              
Flag Coverage Δ
Linux 79.65% <63.15%> (-0.08%) ⬇️
Windows 79.65% <63.15%> (-0.08%) ⬇️
cpu 96.67% <95.65%> (+0.01%) ⬆️
gpu 96.67% <ø> (+0.01%) ⬆️
macOS 96.67% <95.65%> (+0.01%) ⬆️
pytest 96.67% <95.65%> (+0.01%) ⬆️
python3.6 95.57% <94.73%> (+0.01%) ⬆️
python3.8 96.63% <95.65%> (+0.01%) ⬆️
python3.9 96.53% <95.65%> (+0.01%) ⬆️
torch1.3.1 95.57% <94.73%> (+0.01%) ⬆️
torch1.4.0 95.70% <95.65%> (+0.01%) ⬆️
torch1.8.1 96.53% <95.65%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
torchmetrics/functional/classification/auc.py 87.50% <90.90%> (+0.54%) ⬆️
torchmetrics/classification/auc.py 100.00% <100.00%> (ø)
torchmetrics/classification/auroc.py 92.50% <100.00%> (+0.60%) ⬆️
torchmetrics/classification/average_precision.py 100.00% <100.00%> (ø)
torchmetrics/classification/cohen_kappa.py 100.00% <100.00%> (ø)
__w/2/s/torchmetrics/classification/auc.py 100.00% <0.00%> (ø)
__w/2/s/torchmetrics/classification/cohen_kappa.py 100.00% <0.00%> (ø)
...s/torchmetrics/classification/average_precision.py 100.00% <0.00%> (ø)
.../2/s/torchmetrics/functional/classification/auc.py 87.50% <0.00%> (+0.54%) ⬆️
__w/2/s/torchmetrics/classification/auroc.py 92.50% <0.00%> (+0.60%) ⬆️

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 8d9c592...bb57cb5. Read the comment docs.

@Borda Borda marked this pull request as draft April 18, 2021 21:32
@SkafteNicki
Copy link
Member

some tests are failing because this assert cannot handle metrics that returns multiple values.
https://github.com/PyTorchLightning/metrics/blob/c1ae5ace2dc03525720ab3a867ce35fe50a2d276/tests/helpers/testers.py#L465
should be changed to something like:

if isinstance(out, list):
    assert all(metric.is_differentiable == o.requires_grad for o in out)
else:
    assert metric.is_differentiable == out.requires_grad

@SkafteNicki SkafteNicki changed the title [WIP] Changes for Test Differentiability [2/n] Changes for Test Differentiability [2/n] Apr 26, 2021
@SkafteNicki SkafteNicki marked this pull request as ready for review April 26, 2021 14:36
@SkafteNicki SkafteNicki added enhancement New feature or request ready labels Apr 26, 2021
@SkafteNicki
Copy link
Member

After looking a bit on the failing tests it seems that:

@bhadreshpsavani could you add a pytest.skipif to the differentiability test of AUC such that it is skipped if the input is larger than 2048?

@Borda
Copy link
Member

Borda commented Apr 28, 2021

@bhadreshpsavani mind check the failing tests?

@maximsch2
Copy link
Contributor

For the pytorch bug - it would be great to have a small isolated repro to file as an issue for pytorch.

On AUC - is it really meaningful to treat it as differentiable? What tasks will do that?

@bhadreshpsavani
Copy link
Contributor Author

Hi @Borda,
I will make changes according to the suggestion of @SkafteNicki,
Let me know if anything I need to change.

@bhadreshpsavani
Copy link
Contributor Author

Hi @SkafteNicki,
I made changes as per your suggestions
Eventhough i add this line @pytest.mark.skipif(x.shape[1] > 2048) in metrics/tests/classification/test_auc.py it still fails.

@SkafteNicki
Copy link
Member

After searching the internet, AUC indeed is described as an non-differentiable function and it must therefore be our specific implementation in pytorch that allows gradient to be backprop.
I have inserted a torch.no_grad to secure that the function is non-differentiable which also fixes the tests.

@Borda Borda enabled auto-merge (squash) April 30, 2021 13:42
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

@Borda Borda merged commit c65af2c into Lightning-AI:master Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test for differentiability
5 participants