I changed that to this:
denom = torch.sqrt(torch.mean(targ**2))
but I am still getting the error. Seems like that any transformation without torch. works fine (for example squared), but when I use torch. (i tried log, exp, cos and sin) I get the error.