Repository: pytorch
Issue: zero-numel tensor has "RuntimeError: strides[cur - 1] == sizes[cur] * strides[cur] INTERNAL ASSERT FAILED" in multi-thread.
Labels: oncall: jit,triaged,module: nvfuser

### 🐛 Describe the bug

Hello, 

We encountered the following error and provide a reproduction example below. 
```
terminate called after throwing an instance of 'std::runtime_error'
  what():  The following operation failed in the TorchScript interpreter.
Traceback of TorchScript (most recent call last):
RuntimeError: strides[cur - 1] == sizes[cur] * strides[cur]
INTERNAL ASSERT FAILED at "../torch/csrc/jit/codegen/fuser/executor.cpp":177, please report a bug to PyTorch.
```
There are multiple required conditions to reproduce this bug.
(1) a zero-numel() tensor is operated on.
(2) model runs `forward` in a separate thread than the main thread.
(3) model is on a GPU device.

We provide a close-to-minimal reproduction code in the following [gist](https://gist.github.com/ehuaurora/34e2e2eeebaf22b67b54c6a7b99bdb18). 
It has two parts. 
(A) a python script to create a mock torchscript to be loaded by c++ modules, [generate_mock_model.py](https://gist.github.com/ehuaurora/34e2e2eeebaf22b67b54c6a7b99bdb18#file-generate_mock_model-py),
Simply run `python3 generate_mock_model.py` to create a mock model at `/tmp/internal_crash/model.zip`.
(B) C++ source to load the mock torchscript to demonstrate that the requirement (1)(2)(3) are necessary, [reproduce_and_ablation.cc](https://gist.github.com/ehuaurora/34e2e2eeebaf22b67b54c6a7b99bdb18#file-reproduce_and_ablation-cc). Run this without args to load torchscript in `/tmp/internal_crash/model.zip` to reproduce the bug and run some ablation studies.

The expected output of the C++ binary:
```
-----------------------------------------------------------------------------
Make sure you first generate a model with command
   python3 internal_error_crash_model.py
It should generate a model at /tmp/internal_crash/model.zip
------------------------
Running not_crash_if_no_threads()
feature_cp shape [15, 0]
about to do operations
about to return
feature_cp shape [15, 0]
about to do operations
about to return
------------------------
Running not_crash_if_not_gpu()
feature_cp shape [15, 0]
about to do operations
about to return
feature_cp shape [15, 0]
about to do operations
about to return
------------------------
Running not_crash_if_not_zero_numel()
feature_cp shape [15, 1]
about to do operations
about to return
feature_cp shape [15, 1]
about to do operations
about to return
------------------------
Running crash_with_threads()
terminate called after throwing an instance of 'std::runtime_error'
  what():  The following operation failed in the TorchScript interpreter.
Traceback of TorchScript (most recent call last):
RuntimeError: strides[cur - 1] == sizes[cur] * strides[cur]
INTERNAL ASSERT FAILED at "../torch/csrc/jit/codegen/fuser/executor.cpp":177, please report a bug to PyTorch.
```



### Versions

```
Collecting environment information...
PyTorch version: 1.9.0a0+d69c22d.cuda11.4.bionic.aurora.b38
Is debug build: False
CUDA used to build PyTorch: 11.4
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.6 LTS (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: Could not collect
CMake version: version 3.10.2
Libc version: -

Python version: 3.7.13 (default, Jul  6 2022, 21:28:00)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.4.0-1083-aws-x86_64-with-debian-buster-sid
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: NVIDIA A10G
Nvidia driver version: 510.85.02
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.3
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] No relevant packages
[conda] Could not collect
```