If I understand you correctly is it something like this:
class dWdx(Function):
    @staticmethod
    def forward(ctx, input):
        numpy_input = input.detach().numpy()
        eval  =  derivative of inside function
        result = scipy_integrate(lambda y: eval))
        return input.new(result)

    @staticmethod
    def backward(ctx, grad_output):
        numpy_go = grad_output.numpy()
        result = scipy_integrate again?
        return grad_output.new(result)