Repository: pytorch
Issue: JIT model will have a different jacobian after the first computation
Labels: oncall: jit

### 🐛 Describe the bug

JIT model will have a different jacobian after the first computation

```py
import torch
class M(torch.nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, _input_tensor):
        _input_tensor_1 = torch.nn.functional.celu(_input_tensor)
        _input_tensor_2 = torch.mul(_input_tensor_1, torch.tensor(-2, dtype=torch.float64, device='cpu'))
        _input_tensor_2 = _input_tensor_1 / _input_tensor_2
        _input_tensor = _input_tensor_2
        fn_res = _input_tensor.logdet()
        return fn_res

fn = M().to('cpu')

torch.random.manual_seed(5160)
inp = torch.empty([5, 5], dtype=torch.float64, memory_format=torch.contiguous_format)
inp.uniform_(-64, 7)
inp = inp.to('cpu')

jit_fn = torch.jit.script(fn)

from torch.autograd.functional import jacobian

# these two are the same
print(jacobian(fn, inp.clone()))
print(jacobian(jit_fn, inp.clone()))

# this will be different
print(jacobian(jit_fn, inp.clone()))
```

```
tensor([[0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00],
        [0.0000e+00, 0.0000e+00, 6.3193e+52, 0.0000e+00, 0.0000e+00],
        [0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00],
        [0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00],
        [0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00]],
       dtype=torch.float64)

tensor([[0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00],
        [0.0000e+00, 0.0000e+00, 6.3193e+52, 0.0000e+00, 0.0000e+00],
        [0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00],
        [0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00],
        [0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00]],
       dtype=torch.float64)

tensor([[ 4.7020e-04,  0.0000e+00,  0.0000e+00,  0.0000e+00, -1.8723e+75],
        [ 0.0000e+00,  2.5916e+50,  6.3193e+52,  0.0000e+00, -5.3604e+72],
        [ 0.0000e+00, -4.3133e+53,  0.0000e+00,  0.0000e+00,  0.0000e+00],
        [-6.2500e-02,  0.0000e+00,  0.0000e+00,  0.0000e+00,  0.0000e+00],
        [ 0.0000e+00,  0.0000e+00,  0.0000e+00, -6.5622e+85,  1.6687e+94]],
       dtype=torch.float64)
```

This happens on both cpu and cuda.

Not sure whether this is related to #85877

### Versions

```
Collecting environment information...
PyTorch version: 1.12.1
Is debug build: False
CUDA used to build PyTorch: 11.3
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.1 LTS (x86_64)
GCC version: (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Clang version: 14.0.0-1ubuntu1
CMake version: Could not collect
Libc version: glibc-2.35

Python version: 3.9.13 (main, Aug 25 2022, 23:26:10)  [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.19.5-051905-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.7.99
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3060
Nvidia driver version: 515.65.01
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] functorch==0.2.1
[pip3] numpy==1.23.3
[pip3] torch==1.13.0.dev20220923+cu116
[pip3] torchaudio==0.13.0.dev20220923+cu116
[pip3] torchvision==0.14.0.dev20220923+cu116
[conda] _tflow_select             2.3.0                       mkl  
[conda] blas                      1.0                         mkl  
[conda] cudatoolkit               11.3.1               h2bc3f7f_2  
[conda] functorch                 0.2.1                    pypi_0    pypi
[conda] libblas                   3.9.0            12_linux64_mkl    conda-forge
[conda] libcblas                  3.9.0            12_linux64_mkl    conda-forge
[conda] liblapack                 3.9.0            12_linux64_mkl    conda-forge
[conda] mkl                       2021.4.0           h06a4308_640  
[conda] mkl-service               2.4.0            py39h7f8727e_0  
[conda] mkl_fft                   1.3.1            py39hd3c417c_0  
[conda] mkl_random                1.2.2            py39h51133e4_0  
[conda] numpy                     1.23.3                   pypi_0    pypi
[conda] numpy-base                1.23.1           py39ha15fc14_0  
[conda] pytorch                   1.12.1          py3.9_cuda11.3_cudnn8.3.2_0    pytorch
[conda] pytorch-cuda              11.7                 h67b0de4_0    pytorch-nightly
[conda] pytorch-mutex             1.0                        cuda    pytorch-nightly
[conda] tensorflow-base           2.9.1           mkl_py39h353358b_0  
[conda] torch                     1.12.1                   pypi_0    pypi
[conda] torchaudio                0.13.0.dev20220923+cu116          pypi_0    pypi
[conda] torchvision               0.14.0.dev20220923+cu116          pypi_0    pypi
```