Repository: pytorch
Issue: [JIT] Wrong type inference leads to misleading error message
Labels: oncall: jit

### 🐛 Describe the bug

```python
import torch

def fn(x: torch.Tensor):
    mul = torch.mul(x, 1)  # This is a integer tensor not a bool tensor
    return torch.sub(mul, mul)

o = fn(True) # Pass eager mode.
print("Output dtype:", o.dtype, "which is not bool")

# jit trace
traced = torch.jit.trace(fn, (torch.ones((), dtype=torch.bool),))
```

It throws a runtime error:

```
torch.jit._trace.TracingCheckError: Tracing failed sanity checks!
encountered an exception while running the trace with test inputs.
Exception:
        The following operation failed in the TorchScript interpreter.
        Traceback of TorchScript (most recent call last):
        /dev/nnsmith-ganler/test.py(6): fn
        /miniconda3/lib/python3.9/site-packages/torch/jit/_trace.py(856): trace
        /dev/nnsmith-ganler/test.py(12): <module>
        RuntimeError: Subtraction, the `-` operator, with two bool tensors is not supported. Use the `^` or `logical_xor()` operator instead.
```

saying that `torch.sub` is applied boolean tensors which are not supported. However, the `mul` tensor is not boolean but integer. So this is a false postive due to a wrong type inference.

Note: this bug is detected by a fuzzer learnt from existing PyTorch CI tests.

### Versions

<details><summary><b>Env </b> <i>[click to expand]</i></summary>
<div>

```python
"""
Collecting environment information...
PyTorch version: 1.14.0.dev20221202+cu117
Is debug build: False
CUDA used to build PyTorch: 11.7
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.1 LTS (x86_64)
GCC version: (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Clang version: Could not collect
CMake version: version 3.25.0
Libc version: glibc-2.35

Python version: 3.9.12 (main, Apr  5 2022, 06:56:58)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.15.0-56-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.6.124
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA GeForce RTX 3090
GPU 1: NVIDIA GeForce RTX 3090
GPU 2: NVIDIA GeForce RTX 3090

Nvidia driver version: 515.86.01
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.4.1
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.4.1
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.4.1
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.4.1
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.4.1
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.4.1
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.4.1
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.23.3
[pip3] onnx2torch==1.5.3
[pip3] torch==1.14.0.dev20221202+cu117
[pip3] torchaudio==0.14.0.dev20221203+cu117
[pip3] torchtriton==2.0.0+0d7e753227
[pip3] torchvision==0.15.0.dev20221203+cpu
[conda] numpy                     1.23.3                   pypi_0    pypi
[conda] onnx2torch                1.5.3                    pypi_0    pypi
[conda] torch                     1.14.0.dev20221202+cu117          pypi_0    pypi
[conda] torchaudio                0.14.0.dev20221203+cu117          pypi_0    pypi
[conda] torchtriton               2.0.0+0d7e753227          pypi_0    pypi
[conda] torchvision               0.15.0.dev20221203+cpu          pypi_0    pypi
"""
```

</div>
</details>

cc @EikanWang @jgong5 @wenzhe-nrv @sanchitintel