8000 [ONNX] MelSpectrogram results in "Pads has incorrect number of values" · Issue #144382 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content
[ONNX] MelSpectrogram results in "Pads has incorrect number of values" #144382
@WangHHY19931001

Description

@WangHHY19931001

🐛 Describe the bug

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()
    src_wav = torch.randn((1, 1, 48000 * 12), requires_grad=True)
    input_names = ["wav_data"]
    output_names = ["ans"]
    args = (src_wav,)
    torch.onnx.export(
        model,
        args,
        path,
        export_params=True,
        opset_version=19,
        do_constant_folding=True, 
        verbose=False,
        input_names=input_names,
        output_names=output_names,
        dynamo=True,
        report=True
    )
    onnx_model = onnx.load(path)
    onnx.checker.check_model(onnx_model)

def test_data_cov_onnx(onnx_path):
    sess_options = ort.SessionOptions()
    sess_options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL
    providers = [
        'CUDAExecutionProvider',
        'DmlExecutionProvider',
        'CPUExecutionProvider'
    ]
    session = ort.InferenceSession(onnx_path, sess_options,
                                   providers=providers)
    src_wav = torch.randn((1, 1, 48000 * 12))
    ort_inputs = {session.get_inputs()[0].name: src_wav.numpy(), }
    ort_outs = session.run(None, ort_inputs)
    ort_outs = ort_outs[0]
    ort_outs = torch.from_numpy(ort_outs)

    model = DataCov()
    model.eval()
    deal_1 = model(src_wav)

    print(f'Torch Output Shape: {deal_1.shape}, ONNX Output Shape: {ort_outs.shape}')
    print(f'Torch Output Min/Max: {torch.min(deal_1)}, {torch.max(deal_1)}')
    print(f'ONNX Output Min/Max: {torch.min(ort_outs)}, {torch.max(ort_outs)}')
    print(f'Torch Output Mean/Std: {torch.mean(deal_1)}, {torch.std(deal_1)}')
    print(f'ONNX Output Mean/Std: {torch.mean(ort_outs)}, {torch.std(ort_outs)}')

    np.testing.assert_allclose(deal_1.detach().numpy(), ort_outs.detach().numpy(), rtol=1e-02, atol=1e-04)

if __name__ == '__main__':
    export_datacov_onnx("DataCov.onnx")
    test_data_cov_onnx("DataCov.onnx")

error code:

onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Node (_inlfunc_aten_reflection_pad1d_n11) Op (Pad) [ShapeInferenceError] Pads has incorrect number of values. Expected 2 * 3 values. Got 4 values.

Versions

Collecting environment information...
PyTorch version: 2.7.0.dev20250107+cpu
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.1 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Clang version: Could not collect
CMake version: version 3.28.3
Libc version: glibc-2.39

Python version: 3.12.8 | packaged by Anaconda, Inc. | (main, Dec 11 2024, 16:31:09) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-6.8.0-51-generic-x86_64-with-glibc2.39
Is CUDA available: False
CUDA runtime version: 12.0.140
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3060
Nvidia driver version: 560.35.03
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.6.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.6.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.6.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.6.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.6.0
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.6.0
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.6.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.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: 39 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: GenuineIntel
Model name: 11th Gen Intel(R) Core(TM) i7-11700 @ 2.50GHz
CPU family: 6
Model: 167
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 1
Stepping: 1
CPU(s) scaling MHz: 53%
CPU max MHz: 4900.0000
CPU min MHz: 800.0000
BogoMIPS: 4992.00
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 arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx avx512f avx512dq rdseed adx smap avx512ifma clflushopt intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid fsrm md_clear flush_l1d arch_capabilities
Virtualization: VT-x
L1d cache: 384 KiB (8 instances)
L1i cache: 256 KiB (8 instances)
L2 cache: 4 MiB (8 instances)
L3 cache: 16 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-15
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Mitigation; Enhanced IBRS
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected

Versions of relevant libraries:
[pip3] numpy==2.2.1
[pip3] onnx==1.17.0
[pip3] onnxruntime==1.20.1
[pip3] onnxscript==0.1.0.dev20250108
[pip3] onnxsim==0.4.36
[pip3] onnxslim==0.1.46
[pip3] torch==2.7.0.dev20250107+cpu
[pip3] torchaudio==2.6.0.dev20250107+cpu
[pip3] torchvision==0.22.0.dev20250107+cpu
[pip3] triton==3.1.0
[conda] numpy 2.2.1 pypi_0 pypi
[conda] torch 2.7.0.dev20250107+cpu pypi_0 pypi
[conda] torchaudio 2.6.0.dev20250107+cpu pypi_0 pypi
[conda] torchvision 0.22.0.dev20250107+cpu pypi_0 pypi
[conda] triton 3.1.0 pypi_0 pypi

Metadata

Metadata

Assignees

Labels

module: onnxRelated to torch.onnxtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0