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

Remove numpy dependency from the core library #212

Merged
merged 7 commits into from
Apr 30, 2021

Conversation

maximsch2
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?

Remove numpy dependency that seemed to have been added mostly for one test to make it cleaner. Instead moved the function that needs to support both Tensor and ndarray to test utils and removed the dependency from the core library.

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 Apr 29, 2021

Hello @maximsch2! 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 12:16:53 UTC

@codecov
Copy link

codecov bot commented Apr 29, 2021

Codecov Report

Merging #212 (781300e) into master (263a4c7) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #212      +/-   ##
==========================================
- Coverage   96.66%   96.65%   -0.01%     
==========================================
  Files         180      180              
  Lines        5750     5744       -6     
==========================================
- Hits         5558     5552       -6     
  Misses        192      192              
Flag Coverage Δ
Linux 79.73% <66.66%> (-0.03%) ⬇️
Windows 79.73% <66.66%> (-0.03%) ⬇️
cpu 96.65% <100.00%> (-0.01%) ⬇️
gpu 96.65% <ø> (-0.01%) ⬇️
macOS 96.65% <100.00%> (-0.01%) ⬇️
pytest 96.65% <100.00%> (-0.01%) ⬇️
python3.6 95.56% <100.00%> (-0.01%) ⬇️
python3.8 96.62% <100.00%> (-0.01%) ⬇️
python3.9 96.51% <100.00%> (-0.01%) ⬇️
torch1.3.1 95.56% <100.00%> (-0.01%) ⬇️
torch1.4.0 95.68% <100.00%> (-0.01%) ⬇️
torch1.8.1 96.51% <100.00%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
torchmetrics/setup_tools.py 93.54% <ø> (ø)
torchmetrics/classification/stat_scores.py 100.00% <100.00%> (ø)
torchmetrics/utilities/data.py 96.29% <100.00%> (-0.14%) ⬇️
__w/2/s/torchmetrics/utilities/data.py 96.29% <0.00%> (-0.14%) ⬇️
__w/2/s/torchmetrics/classification/stat_scores.py 100.00% <0.00%> (ø)

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 263a4c7...781300e. Read the comment docs.

@Borda
Copy link
Member

Borda commented Apr 29, 2021

numpy is installed with PyTorch anyway and numpy is everywhere so what is the motivation?

@SkafteNicki
Copy link
Member

agree with @Borda on this one, no need to remove numpy as requirement as it is already installed with torch

@maximsch2
Copy link
Contributor Author

I don't think pytorch requires numpy to run, it's likely for tests as well. In fact, we are running pytorch in builds without numpy so it's for sure not required.

In this particular case, the core library doesn't really require numpy, so I'm thinking we should keep it lean especially given it's a no-cost thing for us. The two current uses for numpy in torchmetrics were:

  • np.nan (replaced by float('nan') which is same
  • helper function that was made to take np.ndarray so that the test will be used.

Both are not needed for metrics to function.

@ananthsub
Copy link
Contributor

@SkafteNicki @Borda one of the concerns is around backwards compatibility for metrics. numpy introduces a large surface area which can make this harder to manage. given how minimal the usage is in torchmetrics now, we'd prefer to keep the library lean and use torch primitives instead to better control for this

@Borda
Copy link
Member

Borda commented Apr 29, 2021

Ok, I am fine with dropping it 🐰

@SkafteNicki
Copy link
Member

@maximsch2 and @ananthsub great points, also fine with dropping it, did not really have a strong opinion on this :]

@SkafteNicki SkafteNicki added ready enhancement New feature or request labels Apr 30, 2021
@SkafteNicki SkafteNicki added this to the v0.4 milestone Apr 30, 2021
@Borda Borda enabled auto-merge (squash) April 30, 2021 12:39
@Borda Borda merged commit 8d9c592 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.

5 participants