Repository: pytorch
Issue: JIT model returns different value on cpu with uniform-initialized input
Labels: oncall: jit

### 🐛 Describe the bug

JIT model returns different value on cpu with uniform-initialized input

```py
import torch
class M(torch.nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, inp):
        inp1 = torch.div(inp, torch.tensor(-16, dtype=torch.float32, device='cpu'))
        inp = torch.nn.functional.tanhshrink(inp1)
        fn_res = inp.abs()
        fn_res_1 = fn_res / torch.nn.functional.tanhshrink(fn_res)
        return fn_res_1

fn = M().to('cpu')

torch.random.manual_seed(31195)
inp = torch.empty([10], dtype=torch.float32, memory_format=torch.contiguous_format)
inp.uniform_(-4, 7)

print(inp)

print(fn(inp.clone()))

jit_fn = torch.jit.trace(fn, (inp.clone(),))
print(jit_fn(inp.clone()))
```

```
inp:
tensor([ 2.6257,  6.6212, -0.4189, -0.8199,  2.5157,  6.4133,  5.3943,  6.7126,
        -1.9639, -3.2350])

normal model output:
tensor([1.3910e+06, 6.1375e+03,        inf,        inf, 1.8369e+06, 7.3721e+03,
        2.0092e+04, 5.6738e+03, **1.0527e+07**, 4.0147e+05])

JIT model output:
tensor([1391032.8750,    6137.4810,          inf,          inf, 1836885.3750,
           7372.0679,   20091.6387,    5673.8164, **5263488.0000**,  415805.7188])
```

However, when I use the `inp` with the same value to call (without uniform-initialization), the value will be the same

```py
inp = torch.tensor([ 2.6257,  6.6212, -0.4189, -0.8199,  2.5157,  6.4133,  5.3943,  6.7126,
        -1.9639, -3.2350], dtype=torch.float32,)
print(fn(inp.clone()))

jit_fn = torch.jit.trace(fn, (inp.clone(),))
print(jit_fn(inp.clone()))
```

```
tensor([1.3911e+06, 6.1375e+03,        inf,        inf, 1.8368e+06, 7.3719e+03,
        2.0091e+04, 5.6739e+03, 1.0527e+07, 4.0148e+05])
tensor([1.3911e+06, 6.1375e+03,        inf,        inf, 1.8368e+06, 7.3719e+03,
        2.0091e+04, 5.6739e+03, 1.0527e+07, 4.1581e+05])
```

Besides, this issue only happens on cpu

```py
import torch
class M(torch.nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, inp):
        inp1 = torch.div(inp, torch.tensor(-16, dtype=torch.float32, device='cuda'))
        inp = torch.nn.functional.tanhshrink(inp1)
        fn_res = inp.abs()
        fn_res_1 = fn_res / torch.nn.functional.tanhshrink(fn_res)
        return fn_res_1

fn = M().to('cuda')

torch.random.manual_seed(31195)
inp = torch.empty([10], dtype=torch.float32, memory_format=torch.contiguous_format)
inp.uniform_(-4, 7)
inp = inp.to('cuda')

print(fn(inp.clone()))

jit_fn = torch.jit.trace(fn, (inp.clone(),))
print(jit_fn(inp.clone()))
```

On cuda, the results are the same

```
tensor([1.3910e+06, 6.1375e+03,        inf,        inf, 1.8369e+06, 7.3721e+03,
        2.0092e+04, 5.6738e+03, 1.0527e+07, 4.0147e+05], device='cuda:0')

tensor([1.3910e+06, 6.1375e+03,        inf,        inf, 1.8369e+06, 7.3721e+03,
        2.0092e+04, 5.6738e+03, 1.0527e+07, 4.0147e+05], device='cuda:0')
```

### Versions

```
Collecting environment information...
PyTorch version: 1.14.0.dev20221012
Is debug build: False
CUDA used to build PyTorch: 11.6
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.6.124
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.14.0.dev20221012
[pip3] torchaudio==0.13.0.dev20221012
[pip3] torchvision==0.15.0.dev20221012
[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.14.0.dev20221012 py3.9_cuda11.6_cudnn8.3.2_0    pytorch-nightly
[conda] pytorch-cuda              11.6                 h867d48c_0    pytorch-nightly
[conda] pytorch-mutex             1.0                        cuda    pytorch-nightly
[conda] tensorflow-base           2.9.1           mkl_py39h353358b_0  
[conda] torchaudio                0.13.0.dev20220923+cu116          pypi_0    pypi
[conda] torchvision               0.14.0.dev20220923+cu116          pypi_0    pypi

```