Repository: pytorch
Issue: Export to ONNX of `as_strided()` hard codes stride in the graph, although it should be dynamic
Labels: module: onnx,triaged,release notes: onnx

### 🐛 Describe the bug

Exporting  to ONNX a very simple PyTorch model with a `tensor.as_strided()` operation, no warning or error is raised during the export, but the exported ONNX model is wrong.

I suspect the issue is related to a limited dynamic shape/stride support, either in `as_strided` or in `tensor.stride()`.

### To reproduce

Define the model:

```python
import torch
import torch.nn as nn

class MyModel3(nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x: torch.Tensor):
        a, b, c = x.size()

        strides_original = x.stride()

        shape = (a, b // 2, 4)
        stride = (strides_original[0] // 2, strides_original[1] - 3, 3)
        
        # stride = (x[0][0][0], 4, 3)  <-- if used instead, this will raise an error

        x_strided = x.as_strided(size=shape, stride=stride)

        return x_strided
```

Export to ONNX:
```python
model = MyModel3()
x = torch.randint(8, (50, 30, 15)) + 1
res = model(x)
print(res)

torch.onnx.export(
    model,
    (x,),
    "/home/fxmarty/asstrided_model.onnx",
    input_names=["x"],
    output_names=["x_out"],
    dynamic_axes={"x":  {0: "axis0", 1: "axis1", 2: "axis2"}},
    opset_version=14
)
```

The issue remains with opset 15, 16, 17.

**No warning or error is shown during the export**.

The exported model can be found [here](https://huggingface.co/fxmarty/broken-onnx-as-strided/blob/main/asstrided_model.onnx) and a preview in netron [here](https://netron.app/?url=https://huggingface.co/fxmarty/broken-onnx-as-strided/blob/main/asstrided_model.onnx).

Trying to put dynamic stride by using the shape values (`a, b, c`), or e.g. `x[0][0][0]` (see the comment in the original model for an example), then `torch.onnx.export` rightfully raises:

```
torch.onnx.errors.SymbolicValueError: Failed to export a node '%17 : Long(requires_grad=0, device=cpu) = onnx::Gather[axis=0](%16, %1), scope: __main__.MyModel3:: # /home/fxmarty/test_torchsript.py:48:0
' (in list node %21 : int[] = prim::ListConstruct(%17, %18, %20), scope: __main__.MyModel3::
) because it is not constant. Please try to make things (e.g. kernel sizes) static if possible.  [Caused by the value '21 defined in (%21 : int[] = prim::ListConstruct(%17, %18, %20), scope: __main__.MyModel3::
)' (type 'List[int]') in the TorchScript graph. The containing node has kind 'prim::ListConstruct'.] 
```

You can as well compare the results of ORT and PyTorch following the code in https://github.com/microsoft/onnxruntime/issues/13920 .

Thank you, pinging @justinchuby as requested!

### Versions

PyTorch version: 1.13.0+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](callto:22.04) 11.3.0)
Clang version: Could not collect
CMake version: version 3.22.1
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.7.99
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3060 Laptop GPU
Nvidia driver version: 515.65.01
cuDNN version: Probably one of the following:
/usr/local/cuda-11.7/targets/x86_64-linux/lib/libcudnn.so.8.4.1
/usr/local/cuda-11.7/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.4.1
/usr/local/cuda-11.7/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.4.1
/usr/local/cuda-11.7/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.4.1
/usr/local/cuda-11.7/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.4.1
/usr/local/cuda-11.7/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.4.1
/usr/local/cuda-11.7/targets/x86_64-linux/lib/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.1
[pip3] torch==1.13.0
[pip3] torch-model-archiver==0.6.1
[pip3] torch-workflow-archiver==0.2.5
[pip3] torchaudio==0.13.0
[pip3] torchinfo==1.7.0
[pip3] torchserve==0.6.1
[pip3] torchvision==0.14.0
[conda] cudatoolkit               11.3.1               h2bc3f7f_2    anaconda
[conda] numpy                     1.23.1                   pypi_0    pypi
[conda] torch                     1.13.0                   pypi_0    pypi
[conda] torch-model-archiver      0.6.1                    pypi_0    pypi
[conda] torch-workflow-archiver   0.2.5                    pypi_0    pypi
[conda] torchaudio                0.13.0                   pypi_0    pypi
[conda] torchinfo                 1.7.0                    pypi_0    pypi
[conda] torchserve                0.6.1                    pypi_0    pypi
[conda] torchvision               0.14.0                   pypi_0    pypi