Solved by soulitzer in post #4 
              
              
                Yep, the inefficiency in p.data=x isn’t the setting part. Its that you allocated a new tensor x first, as opposed to just operating on p in place, which avoids allocating any new tensors. 
p.copy_(x) is a safer alternative to p.data=x, so I’d recommend that over it, but since you’re still allocating…