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

Adding support for pytorch tensors in CPU/GPU #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

latorrefabian
Copy link

Dear maintainers,

the current code is based on numpy, which makes it difficult and slow to use with pytorch tensors. I have implemented the algorithms in pure pytorch (code actually requires less lines) which has the advantage of supporting tensors in GPU, potentially increasing the speed of execution. I have also added a short benchmark script that returns the following:

Num real: 10000 Num fake: 10000
total time (numpy/CPU): 12.029611152000001
{'precision': 0.4626, 'recall': 0.4821, 'density': 0.93344, 'coverage': 0.963}
Num real: 10000 Num fake: 10000
total time (torch/CPU): 25.861853684
{'precision': 0.4626, 'recall': 0.4821, 'density': 0.93344, 'coverage': 0.963}
profiling in GPU
Num real: 10000 Num fake: 10000
total time (torch/GPU): 0.6094362700000033
{'precision': 0.4626, 'recall': 0.48210000000000003, 'density': 0.93344, 'coverage': 0.9630000000000001}

as can be seen in this example the torch code computes the exact same values, and the computation on GPU (Nvidia V100) is 20x faster. The CPU in this example is Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz

On my macbook pro laptop (2.9 GHz Quad-Core Intel Core i7) I get the following

Num real: 10000 Num fake: 10000
total time (numpy/CPU): 86.23858
{'precision': 0.4735, 'recall': 0.4853, 'density': 0.9622400000000001, 'coverage': 0.9637}
Num real: 10000 Num fake: 10000
total time (torch/CPU): 20.718494000000007
{'precision': 0.4735, 'recall': 0.4853, 'density': 0.9622400000000001, 'coverage': 0.9637}
cuda GPU not available

which shows that the pytorch CPU code can be faster than numpy, in some cases.

Hopefully this addition will be helpful to you and the community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant