Convergence with custom layers

im trying to implement a three layer network with a custom layer (which is essentially a curve fitted function using scipy). my network converges when i use a standard torch class but when i replace it with my custom layer, the network doesnt converge. my function is mathematically the same, as in im replacing a sigmoid with a fitted sigmoid. what could be going wrong?

Can you display both the pytorch code and the modified version?