Replying to @martin_gornerYuanzhi's idea for this line of prompt is that given a scalar hyper parameter d_dim, and each gradient, which is a tensor of any order, has an axis whose dimension is exactly d_dim. Find that axis ('by looping') and then reshape the gradient to 2d by collapsing all the other axes