Got Expand nodes with static shape input when exporting onnx model with dynamic shape 
Labels: module: onnx, triaged, onnx-needs-info

### 🐛 Describe the bug

I'm trying to export a onnx model by running the code below. It was supposed to be a onnx model with dynamic shape. But when checking the exported model, I found there were two Expand nodes with static shape input, which seemed to be converted from 
`graph_attn_bias[:, 1:, 0, :] = t
`        
`graph_attn_bias[:, 0, :, :] = t
`
```python
import onnx
import torch
import torch.nn as nn

class Embedding(nn.Embedding):
    def __init__(
        self,
        num_embeddings: int,
        embedding_dim: int,
        padding_idx: int = None,
    ):
        super(Embedding, self).__init__(
            num_embeddings, embedding_dim, padding_idx=padding_idx
        )
        self._normal_init()

        if padding_idx is not None:
            self.weight.data[self.padding_idx].zero_()

    def _normal_init(self, std=0.02):
        nn.init.normal_(self.weight, mean=0.0, std=std)

class EdgeFeature(nn.Module):
    """
    Compute attention bias for each head.
    """

    def __init__(
        self,
        pair_dim,
        num_edge,
        num_spatial,
    ):
        super(EdgeFeature, self).__init__()
        self.pair_dim = pair_dim

        self.edge_encoder = Embedding(num_edge, pair_dim, padding_idx=0)
        self.shorest_path_encoder = Embedding(num_spatial, pair_dim, padding_idx=0)
        self.vnode_virtual_distance = Embedding(1, pair_dim)

    def forward(self, shortest_path, edge_feat, graph_attn_bias):
        shortest_path = shortest_path
        edge_input = edge_feat

        graph_attn_bias[:, 1:, 1:, :] = self.shorest_path_encoder(shortest_path)

        # reset spatial pos here
        t = self.vnode_virtual_distance.weight.view(1, 1, self.pair_dim)
        graph_attn_bias[:, 1:, 0, :] = t
        graph_attn_bias[:, 0, :, :] = t

        edge_input = self.edge_encoder(edge_input).mean(-2)
        graph_attn_bias[:, 1:, 1:, :] = graph_attn_bias[:, 1:, 1:, :] + edge_input
        return graph_attn_bias

if __name__ == "__main__":
    edge_feature = EdgeFeature(
                pair_dim=256,
                num_edge=64,
                num_spatial=512,
            ).float()
    attn_bias = torch.rand((64, 20, 20, 256),dtype=torch.float32)
    shortest_path = torch.ones((64, 19, 19),dtype=torch.int64)
    edge_feat = torch.ones((64, 19, 19, 3),dtype=torch.int64)
    torch.onnx.export(edge_feature, 
                        (shortest_path, edge_feat, attn_bias),
                        "edge_feature.onnx",
                        input_names=["shortest_path", "edge_feat", "attn_bias"],
                        # verbose=True,
                        opset_version=14,
                        output_names=["graph_attn_bias"],
                        dynamic_axes={
                            "attn_bias":{0: "batch_size", 1: "seq_len_1", 2: "seq_len_1"},
                            "shortest_path":{0: "batch_size", 1: "seq_len", 2: "seq_len"},
                            "edge_feat":{0: "batch_size", 2: "seq_len", 3: "seq_len"},
                            "graph_attn_bias":{0: "batch_size", 1: "seq_len_1", 2: "seq_len_1"}
                        }
                        )
    from onnxsim import simplify
    model = onnx.load("edge_feature.onnx")
    # convert model
    model_simp, check = simplify(model)
    assert check, "Simplified ONNX model could not be validated"
    onnx.save(model_simp, "edge_feature_modified.onnx")
```
![image](https://github.com/pytorch/pytorch/assets/16131776/3220b4ca-46c8-4fb1-a0bc-7ba07c82fab9)


### Versions

PyTorch version: 1.13.1+cu116
Is debug build: False
CUDA used to build PyTorch: 11.6
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.4 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.22.3                                                                                                                                                                            Libc version: glibc-2.31

Python version: 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:10)  [GCC 10.3.0] (64-bit runtime)
Python platform: Linux-5.11.0-49-generic-x86_64-with-glibc2.10
Is CUDA available: True
CUDA runtime version: 11.6.124
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: Quadro RTX 8000
Nvidia driver version: 510.47.03
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.4.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.4.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.4.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.4.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.4.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.4.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.4.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   46 bits physical, 48 bits virtual
CPU(s):                          24
On-line CPU(s) list:             0-23
Thread(s) per core:              2
Core(s) per socket:              6
Socket(s):                       2
NUMA node(s):                    2
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           85
Model name:                      Intel(R) Xeon(R) Gold 6128 CPU @ 3.40GHz
Stepping:                        4
CPU MHz:                         3400.000
CPU max MHz:                     3700.0000
CPU min MHz:                     1200.0000
BogoMIPS:                        6800.00
L1d cache:                       384 KiB
L1i cache:                       384 KiB
L2 cache:                        12 MiB
L3 cache:                        38.5 MiB                                                                                                                                                                NUMA node0 CPU(s):               0-5,12-17                                                                                                                                                               NUMA node1 CPU(s):               6-11,18-23                                                                                                                                                              Vulnerability Itlb multihit:     KVM: Mitigation: VMX unsupported                                                                                                                                        Vulnerability L1tf:              Mitigation; PTE Inversion
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Full generic retpoline, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Mitigation; Clear CPU buffers; SMT vulnerable
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art ar
ch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_dea
dline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd mba ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms inv
pcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida a
rat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke md_clear flush_l1d

Versions of relevant libraries:
[pip3] numpy==1.24.4
[pip3] pytorch-quantization==2.1.2
[pip3] torch==1.13.1+cu116
[pip3] torch-tensorrt==1.2.0
[pip3] torchaudio==0.13.1+cu116
[pip3] torchvision==0.14.1+cu116
[conda] magma-cuda110             2.5.2                         5    local
[conda] mkl                       2019.5                      281    conda-forge
[conda] mkl-include               2019.5                      281    conda-forge
[conda] numpy                     1.24.4                   pypi_0    pypi
[conda] pytorch-quantization      2.1.2                    pypi_0    pypi
[conda] torch                     1.13.1+cu116             pypi_0    pypi
[conda] torch-tensorrt            1.2.0                    pypi_0    pypi
[conda] torchaudio                0.13.1+cu116             pypi_0    pypi
[conda] torchvision               0.14.1+cu116             pypi_0    pypi