Repository: pytorch
Issue: (JIT) x:Optional[T] cannot not expect content type after `if x is None or x.shape[0]==1`
Labels: oncall: jit

### 🐛 Describe the bug

(JIT) x:Optional[T] cannot not expect content type after `if x is None or x.shape[0]==1`

```py
RuntimeError: 
'Optional[Tensor]' object has no attribute or method 'shape'.:
  File "/home/ainl/library/sharkshark-4k/upscale/model/bsvd/model.py", line 95
            self.fold = self.c//fold_div
        # Case1: In the start or end stage, the memory is empty
        if self.center is None or self.center.shape[-1] == 1:
                                  ~~~~~~~~~~~~~~~~~ <--- HERE
```

`self.center` is `Optional[Tensor]`. 

In prior statement, since we check `or`, so we can expect the self.center is not None.
However JIT type inference does not track it.

### Versions

Collecting environment information...
PyTorch version: 1.12.1+cu113
Is debug build: False
CUDA used to build PyTorch: 11.3
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.5 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: Could not collect
CMake version: version 3.16.3
Libc version: glibc-2.31

Python version: 3.8.12 (default, Oct 12 2021, 13:49:34)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.15.0-48-generic-x86_64-with-glibc2.17
Is CUDA available: True
CUDA runtime version: 11.4.48
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3080
Nvidia driver version: 515.65.01
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.6.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.6.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.6.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.6.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.6.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.6.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.6.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.19.2
[pip3] torch==1.12.1+cu113
[pip3] torch-cluster==1.5.9
[pip3] torch-geometric==1.7.2
[pip3] torch-scatter==2.0.7
[pip3] torch-spline-conv==1.2.1
[pip3] torch-tb-profiler==0.2.0
[pip3] torch-tensorrt==1.2.0
[pip3] torchaudio==0.12.1+cu113
[pip3] torchdata==0.3.0
[pip3] torchfile==0.1.0
[pip3] torchtext==0.12.0
[pip3] torchvision==0.13.1+cu113
[conda] _pytorch_select           0.1                       cpu_0  
[conda] blas                      1.0                         mkl  
[conda] cudatoolkit               11.3.1               h2bc3f7f_2  
[conda] cudatoolkit-dev           11.4.0               h5e8e339_5    conda-forge
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] libmklml                  2019.0.5             h06a4308_0  
[conda] mkl                       2020.2                      256  
[conda] mkl-service               2.3.0            py38he904b0f_0  
[conda] mkl_fft                   1.3.0            py38h54f3939_0  
[conda] mkl_random                1.1.1            py38h0573a6f_0  
[conda] numpy                     1.19.2           py38h54aff64_0  
[conda] numpy-base                1.19.2           py38hfa32c7d_0  
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] torch                     1.12.1+cu113             pypi_0    pypi
[conda] torch-cluster             1.5.9                    pypi_0    pypi
[conda] torch-geometric           1.7.2                    pypi_0    pypi
[conda] torch-scatter             2.0.7                    pypi_0    pypi
[conda] torch-spline-conv         1.2.1                    pypi_0    pypi
[conda] torch-tb-profiler         0.2.0                    pypi_0    pypi
[conda] torch-tensorrt            1.2.0                    pypi_0    pypi
[conda] torchaudio                0.12.1+cu113             pypi_0    pypi
[conda] torchdata                 0.3.0                    pypi_0    pypi
[conda] torchfile                 0.1.0                    pypi_0    pypi
[conda] torchtext                 0.12.0                   pypi_0    pypi
[conda] torchvision               0.13.1+cu113             pypi_0    pypi