Skip to content

Adding support for pytorch tensors in CPU/GPU - #10

Open
latorrefabian wants to merge 2 commits into
clovaai:masterfrom
latorrefabian:master
Open

Adding support for pytorch tensors in CPU/GPU#10
latorrefabian wants to merge 2 commits into
clovaai:masterfrom
latorrefabian:master

Conversation

@latorrefabian

Copy link
Copy Markdown

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.

1 participant