How did you define the N method?
If I’m not mistaken, this line of code would not normalize the output to [0, 1], but would clip it at 0 and add probably noise to all positive values?
If N is implemented using PyTorch operations, Autograd would probably be able to create the backward pass for you.