I actually do not want to do this while training. I just want to try some transformation during inference. I have a function Transformation which takes numpy.ndarray, and it will return the same. I just want to update the data of  previous_layer_out tensor using this Transformation function. Should I just do this :
out = Transformation(previous_layer_out.numpy())
previous_layer_out = torch.from_numpy(out)