Repository: pytorch
Issue: cov onnx error
Labels: module: onnx,triaged

### 🐛 Describe the bug

code:
```python
import torch
import torchaudio
from torch import nn
from torch import onnx


class DataCov(nn.Module):
    def __init__(self):
        super(DataCov, self).__init__()

        self.transform = nn.Sequential(
            torchaudio.transforms.MelSpectrogram(sample_rate=48000, n_fft=1536, hop_length=768, f_min=20, f_max=20000)
        )

    def forward(self, x1):
        return self.transform(x1)

def export_datacov_onnx(path):
    model = DataCov()
    model.eval()
    model = torch.jit.script(model)
    x = torch.randn((1, 48000 * 12), requires_grad=True)
    args = (x,)
    torch.onnx.dynamo_export(model, args, path, export_params=True, opset_version=17)

if __name__ == '__main__':
    export_datacov_onnx('DataCov.onnx')
```

error:
```
/root/miniconda3/envs/onnx/lib/python3.11/site-packages/torch/onnx/_internal/exporter.py:112: UserWarning: torch.onnx.dynamo_export only implements opset version 18 for now. If you need to use a different opset version, please register them with register_custom_op.
  warnings.warn(
Traceback (most recent call last):
  File "/root/miniconda3/envs/onnx/lib/python3.11/site-packages/torch/onnx/_internal/exporter.py", line 1006, in dynamo_export
    ).export()
      ^^^^^^^^
  File "/root/miniconda3/envs/onnx/lib/python3.11/site-packages/torch/onnx/_internal/exporter.py", line 810, in export
    graph_module = self.options.fx_tracer.generate_fx(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/onnx/lib/python3.11/site-packages/torch/onnx/_internal/fx/dynamo_graph_extractor.py", line 198, in generate_fx
    graph_module, graph_guard = torch._dynamo.export(
                                ^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/onnx/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py", line 1197, in inner
    result_traced = opt_f(*args, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/onnx/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py", line 333, in _fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/onnx/lib/python3.11/site-packages/torch/onnx/_internal/fx/dynamo_graph_extractor.py", line 153, in wrapped
    return output_adapter.apply(model_func(*args, **kwargs))
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: forward() expected at most 2 argument(s) but received 5 argument(s). Declaration: forward(__torch__.DataCov self, Tensor x1) -> Tensor

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/root/autodl-tmp/./main.py", line 189, in <module>
    export_datacov_onnx('DataCov.onnx')
  File "/root/autodl-tmp/./main.py", line 183, in export_datacov_onnx
    torch.onnx.dynamo_export(model, args, path, export_params=True, opset_version=18)
  File "/root/miniconda3/envs/onnx/lib/python3.11/site-packages/torch/onnx/_internal/exporter.py", line 1016, in dynamo_export
    raise OnnxExporterError(
torch.onnx.OnnxExporterError: Failed to export the model to ONNX. Generating SARIF report at report_dynamo_export.sarif. Please report a bug on PyTorch Github: https://github.com/pytorch/pytorch/issues
[report_dynamo_export.zip](https://github.com/pytorch/pytorch/files/12319033/report_dynamo_export.zip)
```

### Versions

python ./version_check.py
Collecting environment information...
PyTorch version: 2.1.0.dev20230810+cpu
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.2 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.11.4 (main, Jul  5 2023, 13:45:01) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.4.0-146-generic-x86_64-with-glibc2.35
Is CUDA available: False
CUDA runtime version: 11.8.89
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration:
GPU 0: NVIDIA GeForce RTX 4090
GPU 1: NVIDIA GeForce RTX 4090

Nvidia driver version: 525.105.17
cuDNN version: Probably one of the following:
/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

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Address sizes:                   48 bits physical, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          128
On-line CPU(s) list:             0-127
Vendor ID:                       AuthenticAMD
Model name:                      AMD EPYC 7T83 64-Core Processor
CPU family:                      25
Model:                           1
Thread(s) per core:              2
Core(s) per socket:              64
Socket(s):                       1
Stepping:                        1
Frequency boost:                 enabled
CPU max MHz:                     2450.0000
CPU min MHz:                     1500.0000
BogoMIPS:                        4899.88
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 invpcid_single hw_pstate ssbd mba ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 invpcid cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr wbnoinvd arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold v_vmsave_vmload vgif umip pku ospke vaes vpclmulqdq rdpid overflow_recov succor smca
Virtualization:                  AMD-V
L1d cache:                       2 MiB (64 instances)
L1i cache:                       2 MiB (64 instances)
L2 cache:                        32 MiB (64 instances)
L3 cache:                        256 MiB (8 instances)
NUMA node(s):                    1
NUMA node0 CPU(s):               0-127
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          Not affected
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; Retpolines, IBPB conditional, IBRS_FW, STIBP always-on, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] numpy==1.25.2
[pip3] torch==2.1.0.dev20230810+cpu
[pip3] torchaudio==2.1.0.dev20230810+cpu
[pip3] torchvision==0.16.0.dev20230810+cpu
[conda] numpy                     1.25.2                   pypi_0    pypi
[conda] torch                     2.1.0.dev20230810+cpu          pypi_0    pypi
[conda] torchaudio                2.1.0.dev20230810+cpu          pypi_0    pypi
[conda] torchvision               0.16.0.dev20230810+cpu          pypi_0    pypi