What is the purpose of the following PyTorch function (doc):
torch.addmm(beta=1, mat, alpha=1, mat1, mat2, out=None) More specifically, is there any reason to prefer this function instead of just using
beta * mat + alpha * (mat1 @ mat2) 1 Answer
The addmm function is an optimized version of the equation beta*mat + alpha*(mat1 @ mat2). I ran some tests and timed their execution.
If
beta=1, alpha=1, then the execution of both the statements (addmmand manual) is approximately the same (addmmis just a little faster), regardless of the matrices size.If
betaandalphaare not 1, thenaddmmis two times faster than the manual execution for smaller matrices (with total elements in order of 105). But, if matrices are large (in order of 106), the speedup seems negligible (39msv/s41ms)