Thanks for the response @Gilf641 . ‘d’ is in fact a gradient tensor and its calculated inside a backward function of an autograd.Function. Since this function is used many times in my network, I wanted to make sure its as fast as possible (without writing custom C++/cuda code). I guess this is as efficient as it goes.