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

Too slow on cpu. #417

Closed
hihunjin opened this issue Aug 1, 2021 · 2 comments · Fixed by #419
Closed

Too slow on cpu. #417

hihunjin opened this issue Aug 1, 2021 · 2 comments · Fixed by #419
Labels
help wanted Extra attention is needed question Further information is requested
Milestone

Comments

@hihunjin
Copy link

hihunjin commented Aug 1, 2021

🐛 Bug

Using torchmetrics with cpu is too slow, slower than with gpu. I don't think there are a lot of calculations using gpu, multiplies, divides. But I'm not sure where this bottleneck took.

To Reproduce

Steps to reproduce the behavior:

  1. Go to 'colab'
import torch
import torchmetrics

accuracy_train = torchmetrics.Accuracy(num_classes=5, average='none')
x = torch.rand((1,5,40,512,512))
y = torch.randint(0,5,(1,40,512,512))

## to gpu
x_ = x.cuda()
y_ = y.cuda()
accuracy_train.cuda()

%%timeit
accuracy_train(x_,y_)

accuracy_train.cpu()

%%timeit
accuracy_train(x,y)
  1. See the following outcomes.

image

image

Expected behavior

They should not be that much different.

Environment

  • google colab
@hihunjin hihunjin added bug / fix Something isn't working help wanted Extra attention is needed labels Aug 1, 2021
@github-actions
Copy link

github-actions bot commented Aug 1, 2021

Hi! thanks for your contribution!, great first issue!

@Borda Borda added question Further information is requested and removed bug / fix Something isn't working labels Aug 1, 2021
@SkafteNicki
Copy link
Member

After running the python cprofiler and vizualizing with snakeviz I get this:
image
it is the topk function from pytorch that is the sinner here, that seems to have much worse performance on cpu than gpu (the program spends around 92% on that single call).
We could probably work around this to only use the torch.topk function whenever the topk parameter != 1 (just use argmax which I think have better performance). @Borda any opinion here?

@SkafteNicki SkafteNicki mentioned this issue Aug 3, 2021
4 tasks
@Borda Borda closed this as completed in #419 Aug 3, 2021
@Borda Borda added this to the v0.5 milestone Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants