Run code in cpu

I read the demo


I don’t understand this correct += pred.eq(target.data).cpu().sum().
Why do you use .cpu() function?

I can’t see that line in the link you posted.



Can you see the link?
It is the mnist example in pytorch example!
Thanks very much

as you see in the comment of the line above the one you highlighted, pred has the index of the max log-probability. Hence, checking pred == target and summing total correct predictions in the mini-batch adds up to total correctly predicted.

But why use cpu() ?
It seems that using correct += pred.eq(target.data).sum() would be faster

hmmm, cpu() can probably be removed.