I found several examples of code where torch.pow(x, 2) is used to square the components of a tensor. Would it be more performant to replace such instances with torch.square(x)?
I have not yet come up with a benchmark to test this; I was hoping someone with more knowledge of torch's internals would be able to expand on why one is faster than the other (or not).
11 Answer
In my experiments using timeit for 1M tries to compute a square of a 4096 vector, I found:
*fastest with 8.55ssquarewith 12.51spowwith 14.11s