Thanks for your response. quad is integration methods from scipy . I changed np  to torch,but when I run this part of program:
# Instantiate the PyTorch model
model = torch.jit.script(LuminDist())

# It's useful to select the parameters directly instead of using model.parameters()
# so that we make sure that the order is as expected
params = [model.H0, model.Om,model.M, model.logs]

# The "forward" method of the torch op takes the data as well
args = [torch.tensor(x, dtype=torch.double), torch.tensor(y_obs, dtype=torch.double)]


I get this error:
UnsupportedNodeError                      Traceback (most recent call last)

<ipython-input-42-0a5cf026ea8a> in <module>()
      1 # Instantiate the PyTorch model
----> 2 model = torch.jit.script(LuminDist())
      3 
      4 # It's useful to select the parameters directly instead of using model.parameters()
      5 # so that we make sure that the order is as expected

12 frames

/usr/local/lib/python3.7/dist-packages/torch/jit/frontend.py in __call__(self, ctx, node)
    276         method = getattr(self, 'build_' + node.__class__.__name__, None)
    277         if method is None:
--> 278             raise UnsupportedNodeError(ctx, node)
    279         return method(ctx, node)
    280 

UnsupportedNodeError: try blocks aren't supported:
  File "/usr/local/lib/python3.7/dist-packages/scipy/integrate/quadpack.py", line 378
                   5: "The integral over this cycle is probably divergent or slowly convergent."}

    try:
    ~~~ <--- HERE
        msg = msgs[ier]
    except KeyError:
'integral' is being compiled since it was called from 'LuminDist.forward'
  File "<ipython-input-40-efadf1247617>", line 16
    def forward(self, x, y):
        mean = integral(z,H0,Om,M)
        ~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
        loglike = -0.5 * torch.sum((y - mean) ** 2 * torch.exp(-2 * self.logs) + 2 * self.logs)
        return loglike