You can simply wrap this function like this:
with torch.no_grad():
    output_layer_n.copy_(TransformationFunction(output_layer_n))

Note that you need to copy into it.
If you replace the python variable output_layer_n, then you will get a new tensor that does not require gradients and that will be unrelated to the old output_layer_n (since you did not track ops inside the no_grad() block.