8000 onnx export error · Issue #107922 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

onnx export error #107922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
WangHHY19931001 opened this issue Aug 25, 2023 · 32 comments
Closed

onnx export error #107922

WangHHY19931001 opened this issue Aug 25, 2023 · 32 comments
Labels
module: onnx Related to torch.onnx triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@WangHHY19931001
Copy link
WangHHY19931001 commented Aug 25, 2023

🐛 Describe the bug

code:

import torch
from torch import nn
import torchaudio

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):
        x1 = self.transform(x1)
        return x1


def export():
    model = DataCov().to(torch.float32)
    model.eval()
    input = torch.rand((1, 1, 12 * 48000), dtype=torch.float32)
    torch.onnx.dynamo_export(model, (input), "DataCov.onnx", verbose=False,
                      input_names=['input1'], output_names=['output1'], opset_version=18)


if __name__ == '__main__':
    export()

linux error:

Traceback (most recent call last):
  File "/root/autodl-tmp/./main.py", line 27, in <module>
    export()
  File "/root/autodl-tmp/./main.py", line 22, in export
    torch.onnx.dynamo_export(model, (input), "DataCov.onnx", verbose=False,
    ^^^^^^^^^^
  File "/root/miniconda3/envs/test_onnx/lib/python3.11/site-packages/torch/__init__.py", line 1827, in __getattr__
    return importlib.import_module(f".{name}", __name__)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/test_onnx/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/root/miniconda3/envs/test_onnx/lib/python3.11/site-packages/torch/onnx/__init__.py", line 48, in <module>
    from ._internal.exporter import (  # usort:skip. needs to be last to avoid circular import
  File "/root/miniconda3/envs/test_onnx/lib/python3.11/site-packages/torch/onnx/_internal/exporter.py", line 65, in <module>
    from torch.onnx._internal.fx import diagnostics
  File "/root/miniconda3/envs/test_onnx/lib/python3.11/site-packages/torch/onnx/_internal/fx/diagnostics.py", line 10, in <module>
    import onnxscript  # type: ignore[import]
    ^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/test_onnx/lib/python3.11/site-packages/onnxscript/__init__.py", line 7, in <module>
    from .backend.onnx_export import export2python as proto2python
  File "/root/miniconda3/envs/test_onnx/lib/python3.11/site-packages/onnxscript/backend/onnx_export.py", line 14, in <module>
    import onnxscript.onnx_types
  File "/root/miniconda3/envs/test_onnx/lib/python3.11/site-packages/onnxscript/onnx_types.py", line 177, in <module>
    class FLOAT8E4M3FN(TensorType, dtype=onnx.TensorProto.FLOAT8E4M3FN):
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: FLOAT8E4M3FN

windows error:

C:\Users\dell\miniconda3\envs\onnx_export\Lib\site-packages\torch\onnx\_internal\exporter.py:130: 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 "C:\Users\dell\miniconda3\envs\onnx_export\Lib\site-packages\torch\onnx\_internal\exporter.py", line 1091, in dynamo_export
    ).export()
      ^^^^^^^^
  File "C:\Users\dell\miniconda3\envs\onnx_export\Lib\site-packages\torch\onnx\_internal\exporter.py", line 892, in export
    graph_module = self.options.fx_tracer.generate_fx(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dell\miniconda3\envs\onnx_export\Lib\site-packages\torch\onnx\_internal\fx\dynamo_graph_extractor.py", line 199, in generate_fx
    graph_module, graph_guard = torch._dynamo.export(
                                ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dell\miniconda3\envs\onnx_export\Lib\site-packages\torch\_dynamo\eval_frame.py", line 1018, in inner
    check_if_dynamo_supported()
  File "C:\Users\dell\miniconda3\envs\onnx_export\Lib\site-packages\torch\_dynamo\eval_frame.py", line 533, in check_if_dynamo_supported
    raise RuntimeError("Windows not yet supported for torch.compile")
RuntimeError: Windows not yet supported for torch.compile

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\work\pytorch_to_onnx\main.py", line 27, in <module>
    export()
  File "C:\work\pytorch_to_onnx\main.py", line 22, in export
    torch.onnx.dynamo_export(model, (input), "DataCov.onnx", verbose=False,
  File "C:\Users\dell\miniconda3\envs\onnx_export\Lib\site-packages\torch\onnx\_internal\exporter.py", line 1102, in dynamo_export
    raise OnnxExporterError(
torch.onnx.OnnxExporterError: Failed to export the model to ONNX. Generating SARIF report at {sarif_report_path}. SARIF is a standard format for the output of static analysis tools. SARIF log can be loaded in VS Code SARIF viewer extension, or SARIF web viewer(https://microsoft.github.io/sarif-web-component/).Please report a bug on PyTorch Github: https://github.com/pytorch/pytorch/issues

Versions

linux versions:

Collecting environment information...
PyTorch version: 2.1.0.dev20230824
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.3 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
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:                   46 bits physical, 57 bits virtual
Byte Order:                      Little Endian
CPU(s):                          128
On-line CPU(s) list:             0-127
Vendor ID:                       GenuineIntel
Model name:                      Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz
CPU family:                      6
Model:                           106
Thread(s) per core:              2
Core(s) per socket:              32
Socket(s):                       2
Stepping:                        6
Frequency boost:                 enabled
CPU m
8000
ax MHz:                     2901.0000
CPU min MHz:                     800.0000
BogoMIPS:                        5800.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 pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 invpcid_single ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local wbnoinvd dtherm ida arat pln pts avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq rdpid md_clear pconfig flush_l1d arch_capabilities
Virtualization:                  VT-x
L1d cache:                       3 MiB (64 instances)
L1i cache:                       2 MiB (64 instances)
L2 cache:                        80 MiB (64 instances)
L3 cache:                        108 MiB (2 instances)
NUMA node(s):                    2
NUMA node0 CPU(s):               0-31,64-95
NUMA node1 CPU(s):               32-63,96-127
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 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; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] numpy==1.24.3
[pip3] torch==2.1.0.dev20230824
[pip3] torchaudio==2.1.0.dev20230824
[pip3] torchvision==0.16.0.dev20230824
[conda] blas                      1.0                         mkl    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
[conda] brotlipy                  0.7.0           py311h9bf148f_1002    pytorch-nightly
[conda] cffi                      1.15.1          py311h9bf148f_3    pytorch-nightly
[conda] cpuonly                   2.0                           0    pytorch-nightly
[conda] cryptography              38.0.4          py311h46ebde7_0    pytorch-nightly
[conda] filelock                  3.9.0                   py311_0    pytorch-nightly
[conda] libjpeg-turbo             2.0.0                h9bf148f_0    pytorch-nightly
[conda] mkl                       2021.4.0           h06a4308_640    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
[conda] mkl-service               2.4.0           py311h9bf148f_0    pytorch-nightly
[conda] mkl_fft                   1.3.1           py311hc796f24_0    pytorch-nightly
[conda] mkl_random                1.2.2           py311hbba84a0_0    pytorch-nightly
[conda] mpmath                    1.2.1                   py311_0    pytorch-nightly
[conda] numpy                     1.24.3          py311hc206e33_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
[conda] numpy-base                1.24.3          py311hfd5febd_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
[conda] pillow                    9.3.0           py311h3fd9d12_2    pytorch-nightly
[conda] pysocks                   1.7.1                   py311_0    pytorch-nightly
[conda] pytorch                   2.1.0.dev20230824    py3.11_cpu_0    pytorch-nightly
[conda] pytorch-mutex             1.0                         cpu    pytorch-nightly
[conda] requests                  2.28.1                  py311_0    pytorch-nightly
[conda] torchaudio                2.1.0.dev20230824       py311_cpu    pytorch-nightly
[conda] torchvision               0.16.0.dev20230824       py311_cpu    pytorch-nightly
[conda] urllib3                   1.26.14                 py311_0    pytorch-nightly

onnxscript-preview in /root/miniconda3/envs/test_onnx/lib/python3.11/site-packages (0.1.0.dev20230814)

windows version:

Collecting environment information...
PyTorch version: 2.1.0.dev20230824
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 10 专业版
GCC version: (Rev5, Built by MSYS2 project) 13.1.0
Clang version: Could not collect
CMake version: version 3.26.4
Libc version: N/A

Python version: 3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 17:59:51) [MSC v.1935 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.19045-SP0
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:










Revision=

Versions of relevant libraries:
[pip3] numpy==1.24.4
[pip3] torch==2.1.0.dev20230824
[pip3] torchaudio==2.1.0.dev20230824
[pip3] torchvision==0.16.0.dev20230824
[conda] blas                      1.0                         mkl    defaults
[conda] cpuonly                   2.0                           0    pytorch-nightly
[conda] mkl                       2023.1.0         h6b88ed4_46357    defaults
[conda] mkl-service               2.4.0           py311h2bbff1b_1    defaults
[conda] mkl_fft                   1.3.6           py311hf62ec03_1    defaults
[conda] mkl_random                1.2.2           py311hf62ec03_1    defaults
[conda] mpmath                    1.2.1                   py311_0    pytorch-nightly
[conda] numpy                     1.24.4                   pypi_0    pypi
[conda] numpy-base                1.25.2          py311hd01c5d8_0    defaults
[conda] pytorch                   2.1.0.dev20230824    py3.11_cpu_0    pytorch-nightly
[conda] pytorch-mutex             1.0                         cpu    pytorch-nightly
[conda] torchaudio                2.1.0.dev20230824       py311_cpu    pytorch-nightly
[conda] torchvision               0.16.0.dev20230824       py311_cpu    pytorch-nightly

onnxscript-preview in c:\users\dell\miniconda3\envs\onnx_export\lib\site-packages (0.1.0.dev20230814)
@justinchuby
Copy link
Collaborator
justinchuby commented Aug 25, 2023

Please share the onnx version you use. ONNX Script requires a onnx version >= 1.14. Thanks!

@janeyx99 janeyx99 added the module: onnx Related to torch.onnx label Aug 25, 2023
@janeyx99 janeyx99 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Aug 25, 2023
@github-project-automation github-project-automation bot moved this to Inbox in ONNX Aug 25, 2023
@WangHHY19931001
Copy link
Author

Please share the onnx version you use. ONNX Script requires a onnx version >= 1.14. Thanks!

windows:
Requirement already satisfied: onnxscript-preview in c:\users\dell\miniconda3\envs\onnx_export\lib\site-packages (0.1.0.dev20230828)
Requirement already satisfied: numpy in c:\users\dell\miniconda3\envs\onnx_export\lib\site-packages (from onnxscript-preview) (1.24.4)
Requirement already satisfied: onnx>=1.14 in c:\users\dell\miniconda3\envs\onnx_export\lib\site-packages (from onnxscript-preview) (1.14.0)
Requirement already satisfied: typing-extensions in c:\users\dell\miniconda3\envs\onnx_export\lib\site-packages (from onnxscript-preview) (4.7.1)
Requirement already satisfied: protobuf>=3.20.2 in c:\users\dell\miniconda3\envs\onnx_export\lib\site-packages (from onnx>=1.14->onnxscript-preview) (3.20.3)

@WangHHY19931001
Copy link
Author

Please share the onnx version you use. ONNX Script requires a onnx version >= 1.14. Thanks!

linux:
Requirement already satisfied: onnxscript-preview in ./miniconda3/envs/test_onnx/lib/python3.11/site-packages (0.1.0.dev20230827)
Requirement already satisfied: numpy in ./miniconda3/envs/test_onnx/lib/python3.11/site-packages (from onnxscript-preview) (1.24.3)
Requirement already satisfied: onnx>=1.14 in ./miniconda3/envs/test_onnx/lib/python3.11/site-packages (from onnxscript-preview) (1.14.0)
Requirement already satisfied: typing-extensions in ./miniconda3/envs/test_onnx/lib/python3.11/site-packages (from onnxscript-preview) (4.7.1)
Requirement already satisfied: protobuf>=3.20.2 in ./miniconda3/envs/test_onnx/lib/python3.11/site-packages (from onnx>=1.14->onnxscript-preview) (4.24.1)

@justinchuby
Copy link
Collaborator

Could you install the latest onnx (1.15) and onnxscript (uninstall onnxscript-preview first)? Thanks!

@WangHHY19931001
Copy link
Author

Traceback (most recent call last):
File "/Users/celebi/./export.py", line 27, in
export()
File "/Users/celebi/./export.py", line 22, in export
torch.onnx.dynamo_export(model, (input), "DataCov.onnx", verbose=False,
File "/Users/celebi/miniconda3/envs/ai/lib/python3.11/site-packages/torch/onnx/_internal/exporter.py", line 1222, in dynamo_export
resolved_export_options = ResolvedExportOptions(ExportOptions(), model=model)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/celebi/miniconda3/envs/ai/lib/python3.11/site-packages/torch/onnx/_internal/exporter.py", line 362, in init
from torch.onnx._internal.fx import ( # TODO: Prevent circular dep
File "/Users/celebi/miniconda3/envs/ai/lib/python3.11/site-packages/torch/onnx/_internal/fx/diagnostics.py", line 10, in
import onnxscript # type: ignore[import]
^^^^^^^^^^^^^^^^^
File "/Users/celebi/miniconda3/envs/ai/lib/python3.11/site-packages/onnxscript/init.py", line 8, in
from .main import export_onnx_lib, graph, script
File "/Users/celebi/miniconda3/envs/ai/lib/python3.11/site-packages/onnxscript/main.py", line 17, in
from onnxscript import converter, irbuilder, values
File "/Users/celebi/miniconda3/envs/ai/lib/python3.11/site-packages/onnxscript/converter.py", line 24, in
from onnxscript import irbuilder, onnx_types, sourceinfo
File "/Users/celebi/miniconda3/envs/ai/lib/python3.11/site-packages/onnxscript/irbuilder.py", line 20, in
from onnxscript._internal import version_utils
File "/Users/celebi/miniconda3/envs/ai/lib/python3.11/site-packages/onnxscript/_internal/version_utils.py", line 3, in
import packaging.version
ModuleNotFoundError: No module named 'packaging'

@WangHHY19931001
Copy link
Author

pip install --upgrade onnxscript
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting onnxscript
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/e1/32/78064ae06bb04fa471675795ae981411ce12562fc4c2230768aa2edd5674/onnxscript-0.1.0.dev20231111-py3-none-any.whl (543 kB)
Requirement already satisfied: numpy in ./miniconda3/envs/ai_tmp/lib/python3.10/site-packages (from onnxscript) (1.26.0)
Collecting onnx>=1.14 (from onnxscript)
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f7/08/9d107e9cdc9080d9ca2e8833087988ed202c88b224c3263ec3edc4ea2504/onnx-1.15.0-cp310-cp310-macosx_10_12_universal2.whl (16.3 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 16.3/16.3 MB 17.4 MB/s eta 0:00:00
Requirement already satisfied: typing-extensions in ./miniconda3/envs/ai_tmp/lib/python3.10/site-packages (from onnxscript) (4.7.1)
Collecting protobuf>=3.20.2 (from onnx>=1.14->onnxscript)
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/86/f5/74106012afe8b14e87c43a20605d495d23bdbb5b4df3913ea77af6401765/protobuf-4.25.0-cp37-abi3-macosx_10_9_universal2.whl (393 kB)
Installing collected packages: protobuf, onnx, onnxscript
Successfully installed onnx-1.15.0 onnxscript-0.1.0.dev20231111 protobuf-4.25.0
(ai_tmp) celebi@celebideMacBook-Air ~ % python ./export.py
Traceback (most recent call last):
File "/Users/celebi/./export.py", line 27, in
export()
File "/Users/celebi/./export.py", line 22, in export
torch.onnx.dynamo_export(model, (input), "DataCov.onnx", verbose=False,
File "/Users/celebi/miniconda3/envs/ai_tmp/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py", line 1222, in dynamo_export
resolved_export_options = ResolvedExportOptions(ExportOptions(), model=model)
File "/Users/celebi/miniconda3/envs/ai_tmp/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py", line 362, in init
from torch.onnx._internal.fx import ( # TODO: Prevent circular dep
File "/Users/celebi/miniconda3/envs/ai_tmp/lib/python3.10/site-packages/torch/onnx/_internal/fx/diagnostics.py", line 10, in
import onnxscript # type: ignore[import]
File "/Users/celebi/miniconda3/envs/ai_tmp/lib/python3.10/site-packages/onnxscript/init.py", line 8, in
from .main import export_onnx_lib, graph, script
File "/Users/celebi/miniconda3/envs/ai_tmp/lib/python3.10/site-packages/onnxscript/main.py", line 17, in
from onnxscript import converter, irbuilder, values
File "/Users/celebi/miniconda3/envs/ai_tmp/lib/python3.10/site-packages/onnxscript/converter.py", line 24, in
from onnxscript import irbuilder, onnx_types, sourceinfo
File "/Users/celebi/miniconda3/envs/ai_tmp/lib/python3.10/site-packages/onnxscript/irbuilder.py", line 20, in
from onnxscript._internal import version_utils
File "/Users/celebi/miniconda3/envs/ai_tmp/lib/python3.10/site-packages/onnxscript/_internal/version_utils.py", line 3, in
import packaging.version
ModuleNotFoundError: No module named 'packaging'

@justinchuby
Copy link
Collaborator

pip install packaging. We will fix this in the next release

@WangHHY19931001
Copy link
Author

PS F:\ai_export> pip install --upgrade onnxscript
Looking in indexes: https://mirrors.bfsu.edu.cn/pypi/web/simple
Collecting onnxscript
Downloading https://mirrors.bfsu.edu.cn/pypi/web/packages/46/2c/cdb74aceb551d8c1d3791a953edc71e01cdbe948c39cdbbc54971f6e75a8/onnxscript-0.1.0.dev20231104-py3-none-any.whl (541 kB)
Requirement already satisfied: numpy in c:\users\dell\miniconda3\lib\site-packages (from onnxscript) (1.26.0)
Collecting onnx>=1.14
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.3/14.3 MB 2.3 MB/s eta 0:00:00
Requirement already satisfied: typing-extensions in c:\users\dell\miniconda3\lib\site-packages (from onnxscript) (4.7.1)
Collecting protobuf>=3.20.2
Downloading https://mirrors.bfsu.edu.cn/pypi/web/packages/72/eb/a07cc36ed9b119062886935a8371da8a977dda30b19cf57fe9162589b6f7/protobuf-4.25.0-cp310-abi3-win_amd64.whl (413 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 413.2/413.2 kB 2.3 MB/s eta 0:00:00
Installing collected packages: protobuf, onnx, onnxscript
Successfully installed onnx-1.15.0 onnxscript-0.1.0.dev20231104 protobuf-4.25.0
PS F:\ai_export> pip install packaging
Looking in indexes: https://mirrors.bfsu.edu.cn/pypi/web/simple
Requirement already satisfied: packaging in c:\users\dell\miniconda3\lib\site-packages (23.1)
PS F:\ai_export> python .\main.py
C:\Users\dell\miniconda3\lib\site-packages\torch\onnx_internal\exporter.py:135: 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 "C:\Users\dell\miniconda3\lib\site-packages\torch\onnx_internal\exporter.py", line 1232, in dynamo_export
).export()
File "C:\Users\dell\miniconda3\lib\site-packages\torch\onnx_internal\exporter.py", line 978, in export
graph_module = self.options.fx_tracer.generate_fx(
File "C:\Users\dell\miniconda3\lib\site-packages\torch\onnx_internal\fx\dynamo_graph_extractor.py", line 199, in generate_fx
graph_module, graph_guard = torch._dynamo.export(
File "C:\Users\dell\miniconda3\lib\site-packages\torch_dynamo\eval_frame.py", line 1128, in inner
check_if_dynamo_supported()
File "C:\Users\dell\miniconda3\lib\site-packages\torch_dynamo\eval_frame.py", line 614, in check_if_dynamo_supported
raise RuntimeError("Windows not yet supported for torch.compile")
RuntimeError: Windows not yet supported for torch.compile

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "F:\ai_export\main.py", line 27, in
export()
File "F:\ai_export\main.py", line 22, in export
torch.onnx.dynamo_export(model, (input), "DataCov.onnx", verbose=False,
File "C:\Users\dell\miniconda3\lib\site-packages\torch\onnx_internal\exporter.py", line 1243, in dynamo_export
raise OnnxExporterError(
torch.onnx.OnnxExporterError: Failed to export the model to ONNX. Generating SARIF report at 'report_dynamo_export.sarif'. SARIF is a standard format for the output of static analysis tools. SARIF logs can be loaded in VS Code S
ARIF viewer extension, or SARIF web viewer (https://microsoft.github.io/sarif-web-component/). Please report a bug on PyTorch Github: https://github.com/pytorch/pytorch/issues

@WangHHY19931001
Copy link
Author

pip install packaging. We will fix this in the next release

after install, it still not work

@WangHHY19931001
Copy link
Author

ai_export.zip

@WangHHY19931001
Copy link
Author

pip install packaging. We will fix this in the next release

after install, it still not work

@justinchuby
Copy link
Collaborator

dynamo doesn’t support Windows yet. I suggest using WSL or if you like hack the check_if_dynamo_supported function above to always return True

@justinchuby
Copy link
Collaborator

Looks like duplicate of #112844

@WangHHY19931001
Copy link
Author

pip install --upgrade onnxscript packaging
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: onnxscript in /home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages (0.1.0.dev20231114)
Requirement already satisfied: packaging in /home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages (23.2)
Requirement already satisfied: numpy in /home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages (from onnxscript) (1.26.0)
Requirement already satisfied: onnx>=1.14 in /home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages (from onnxscript) (1.15.0)
Requirement already satisfied: typing-extensions in /home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages (from onnxscript) (4.7.1)
Requirement already satisfied: protobuf>=3.20.2 in /home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages (from onnx>=1.14->onnxscript) (4.25.0)
(ai) celebi@wangyafeng-PC:/mnt/f/ai_export$ python ./main.py
/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py:135: 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 "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py", line 1232, in dynamo_export
).export()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py", line 978, in export
graph_module = self.options.fx_tracer.generate_fx(
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/onnx/_internal/fx/dynamo_graph_extractor.py", line 199, in generate_fx
graph_module, graph_guard = torch._dynamo.export(
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 1237, in inner
result_traced = opt_f(*args, **kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 408, in _fn
return fn(*args, **kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/onnx/_internal/fx/dynamo_graph_extractor.py", line 154, in wrapped
return output_adapter.apply(model_func(*args, **kwargs))
TypeError: DataCov.forward() got an unexpected keyword argument 'verbose'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/mnt/f/ai_export/./main.py", line 27, in
export()
File "/mnt/f/ai_export/./main.py", line 22, in export
torch.onnx.dynamo_export(model, (input), "DataCov.onnx", verbose=False,
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py", line 1243, in dynamo_export
raise OnnxExporterError(
torch.onnx.OnnxExporterError: Failed to export the model to ONNX. Generating SARIF report at 'report_dynamo_export.sarif'. SARIF is a standard format for the output of static analysis tools. SARIF logs can be loaded in VS Code SARIF viewer extension, or SARIF web viewer (https://microsoft.github.io/sarif-web-component/). Please report a bug on PyTorch Github: https://github.com/pytorch/pytorch/issues

@WangHHY19931001
Copy link
Author

ai_export.zip

@WangHHY19931001
Copy link
Author

Looks like duplicate of #112844

use wsl still not work

@justinchuby
Copy link
Collaborator

Please check the function call as the signature has changed:

torch.onnx.dynamo_export(model, input)

There are also known issues reported in #112844

@WangHHY19931001
Copy link
Author

torch.onnx.dynamo_export(

python ./main.py
/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py:135: 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 "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py", line 1232, in dynamo_export
).export()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py", line 978, in export
graph_module = self.options.fx_tracer.generate_fx(
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/onnx/_internal/fx/dynamo_graph_extractor.py", line 199, in generate_fx
graph_module, graph_guard = torch._dynamo.export(
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 1237, in inner
result_traced = opt_f(*args, **kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 408, in _fn
return fn(*args, **kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/onnx/_internal/fx/dynamo_graph_extractor.py", line 154, in wrapped
return output_adapter.apply(model_func(*args, **kwargs))
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 569, in catch_errors
return callback(frame, cache_entry, hooks, frame_state)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 377, in _convert_frame_assert
return _compile(
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 595, in _compile
guarded_code = compile_inner(code, one_graph, hooks, transform)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 243, in time_wrapper
r = func(*args, **kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 512, in compile_inner
out_code = transform_code_object(code, transform)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/bytecode_transformation.py", line 1033, in transform_code_object
transformations(instructions, code_options)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 150, in _fn
return fn(*args, **kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 477, in transform
tracer.run()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 2120, in run
super().run()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 815, in run
and self.step()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 778, in step
getattr(self, inst.opname)(inst)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 469, in wrapper
return inner_fn(self, inst)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 1209, in CALL_FUNCTION
self.call_function(fn, args, {})
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 650, in call_function
self.push(fn.call_function(self, args, kwargs))
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/variables/nn_module.py", line 266, in call_function
tx.call_function(
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 650, in call_function
self.push(fn.call_function(self, args, kwargs))
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/variables/nn_module.py", line 328, in call_function
return tx.inline_user_function_return(
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 685, in inline_user_function_return
return InliningInstructionTranslator.inline_call(self, fn, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/dynamo/symbolic_convert.py", line 2252, in inline_call
return cls.inline_call
(parent, func, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/dynamo/symbolic_convert.py", line 2384, in inline_call
tracer.run()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 815, in run
and self.step()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 778, in step
getattr(self, inst.opname)(inst)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 469, in wrapper
return inner_fn(self, inst)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 1247, in CALL_FUNCTION_EX
self.call_function(fn, argsvars.items, kwargsvars.items)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 650, in call_function
self.push(fn.call_function(self, args, kwargs))
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py", line 294, in call_function
return super().call_function(tx, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py", line 248, in call_function
return super().call_function(tx, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py", line 81, in call_function
return tx.inline_user_function_return(
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 685, in inline_user_function_return
return InliningInstructionTranslator.inline_call(self, fn, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/dynamo/symbolic_convert.py", line 2252, in inline_call
return cls.inline_call
(parent, func, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/dynamo/symbolic_convert.py", line 2384, in inline_call
tracer.run()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 815, in run
and self.step()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 778, in step
getattr(self, inst.opname)(inst)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 469, in wrapper
return inner_fn(self, inst)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 1209, in CALL_FUNCTION
self.call_function(fn, args, {})
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 650, in call_function
self.push(fn.call_function(self, args, kwargs))
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/variables/nn_module.py", line 328, in call_function
return tx.inline_user_function_return(
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 685, in inline_user_function_return
return InliningInstructionTranslator.inline_call(self, fn, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/dynamo/symbolic_convert.py", line 2252, in inline_call
return cls.inline_call
(parent, func, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/dynamo/symbolic_convert.py", line 2384, in inline_call
tracer.run()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 815, in run
and self.step()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 778, in step
getattr(self, inst.opname)(inst)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 469, in wrapper
return inner_fn(self, inst)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 1247, in CALL_FUNCTION_EX
self.call_function(fn, argsvars.items, kwargsvars.items)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 650, in call_function
self.push(fn.call_function(self, args, kwargs))
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py", line 294, in call_function
return super().call_function(tx, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py", line 248, in call_function
return super().call_function(tx, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py", line 81, in call_function
return tx.inline_user_function_return(
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 685, in inline_user_function_return
return InliningInstructionTranslator.inline_call(self, fn, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/dynamo/symbolic_convert.py", line 2252, in inline_call
return cls.inline_call
(parent, func, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/dynamo/symbolic_convert.py", line 2384, in inline_call
tracer.run()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 815, in run
and self.step()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 778, in step
getattr(self, inst.opname)(inst)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 469, in wrapper
return inner_fn(self, inst)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 1209, in CALL_FUNCTION
self.call_function(fn, args, {})
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 650, in call_function
self.push(fn.call_function(self, args, kwargs))
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py", line 248, in call_function
return super().call_function(tx, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py", line 81, in call_function
return tx.inline_user_function_return(
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 685, in inline_user_function_return
return InliningInstructionTranslator.inline_call(self, fn, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/dynamo/symbolic_convert.py", line 2252, in inline_call
return cls.inline_call
(parent, func, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/dynamo/symbolic_convert.py", line 2384, in inline_call
tracer.run()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 815, in run
and self.step()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 778, in step
getattr(self, inst.opname)(inst)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 469, in wrapper
return inner_fn(self, inst)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 1209, in CALL_FUNCTION
self.call_function(fn, args, {})
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 650, in call_function
self.push(fn.call_function(self, args, kwargs))
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py", line 248, in call_function
return super().call_function(tx, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/variables/functions.py", line 81, in call_function
return tx.inline_user_function_return(
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 685, in inline_user_function_return
return InliningInstructionTranslator.inline_call(self, fn, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/dynamo/symbolic_convert.py", line 2252, in inline_call
return cls.inline_call
(parent, func, args, kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/dynamo/symbolic_convert.py", line 2384, in inline_call
tracer.run()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 815, in run
and self.step()
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 778, in step
getattr(self, inst.opname)(inst)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 469, in wrapper
return inner_fn(self, inst)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 1209, in CALL_FUNCTION
self.call_function(fn, args, {})
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 650, in call_function
self.push(fn.call_function(self, args, kwargs))
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/variables/misc.py", line 887, in call_function
unimplemented(
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/_dynamo/exc.py", line 193, in unimplemented
raise Unsupported(msg)
torch._dynamo.exc.Unsupported: 'call_function isinstance in skip_files /home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/jit/init.py, skipped according skipfiles.SKIP_DIRS'

from user code:
File "/mnt/f/ai_export/./main.py", line 14, in forward
x1 = self.transform(x1)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1519, in _call_impl
return forward_call(*args, **kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torchaudio/transforms/_transforms.py", line 619, in forward
specgram = self.spectrogram(waveform)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1519, in _call_impl
return forward_call(*args, **kwargs)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torchaudio/transforms/_transforms.py", line 110, in forward
return F.spectrogram(
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torchaudio/functional/functional.py", line 119, in spectrogram
frame_length_norm, window_norm = _get_spec_norms(normalized)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torchaudio/functional/functional.py", line 233, in _get_spec_norms
if torch.jit.isinstance(normalized, str):

Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/mnt/f/ai_export/./main.py", line 26, in
export()
File "/mnt/f/ai_export/./main.py", line 22, in export
torch.onnx.dynamo_export(model, input)
File "/home/celebi/miniconda3/envs/ai/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py", line 1243, in dynamo_export
raise OnnxExporterError(
torch.onnx.OnnxExporterError: Failed to export the model to ONNX. Generating SARIF report at 'report_dynamo_export.sarif'. SARIF is a standard format for the output of static analysis tools. SARIF logs can be loaded in VS Code SARIF viewer extension, or SARIF web viewer (https://microsoft.github.io/sarif-web-component/). Please report a bug on PyTorch Github: https://github.com/pytorch/pytorch/issues

@WangHHY19931001
Copy link
Author

import torch
from torch import nn
import torchaudio

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):
    x1 = self.transform(x1)
    return x1

def export():
model = DataCov().to(torch.float32)
model.eval()
input = torch.rand((1, 1, 12 * 48000), dtype=torch.float32)
torch.onnx.dynamo_export(model, input)

if name == 'main':
export()

@WangHHY19931001
Copy link
Author

{
"runs":[
{
"tool":{
"driver":{
"name":"torch.onnx.dynamo_export",
"contents":[
"localizedData",
"nonLocalizedData"
],
"language":"en-US",
"rules":[],
"version":"2.2.0.dev20231113"
}
},
"language":"en-US",
"newlineSequences":[
"\r\n",
"\n"
],
"results":[]
}
],
"version":"2.1.0",
"schemaUri":"https://docs.oasis-open.org/sarif/sarif/v2.1.0/cs01/schemas/sarif-schema-2.1.0.json"
}

@justinchuby
Copy link
Collaborator

Now this is the same error as #112844. Please track it over there. Thanks.

Duplicate of #112844

@justinchuby justinchuby closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2023
@github-project-automation github-project-automation bot moved this from Inbox to Done in ONNX Nov 14, 2023
@kunyao2015
Copy link

@WangHHY19931001 Hi, Did you sloved this error?

@WangHHY19931001
Copy link
Author

@WangHHY19931001 Hi, Did you sloved this error?
with pytorch-2.5.0.dev20240613 py3.12_cpu_0 onnxscript-0.1.0.dev20240614

it still error

/home/yafeng_wang/miniconda3/envs/onnx_export/lib/python3.12/site-packages/torch/onnx/_internal/exporter.py:137: 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 "/home/yafeng_wang/miniconda3/envs/onnx_export/lib/python3.12/site-packages/torch/onnx/_internal/exporter.py", line 1509, in dynamo_export
).export()
^^^^^^^^
File "/home/yafeng_wang/miniconda3/envs/onnx_export/lib/python3.12/site-packages/torch/onnx/_internal/exporter.py", line 1236, in export
graph_module = self.options.fx_tracer.generate_fx(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/yafeng_wang/miniconda3/envs/onnx_export/lib/python3.12/site-packages/torch/onnx/_internal/fx/dynamo_graph_extractor.py", line 214, in generate_fx
graph_module, graph_guard = torch._dynamo.export(
^^^^^^^^^^^^^^^^^^^^^
File "/home/yafeng_wang/miniconda3/envs/onnx_export/lib/python3.12/site-packages/torch/_dynamo/eval_frame.py", line 1379, in inner
result_traced = opt_f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/yafeng_wang/miniconda3/envs/onnx_export/lib/python3.12/site-packages/torch/_dynamo/eval_frame.py", line 433, in _fn
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/home/yafeng_wang/miniconda3/envs/onnx_export/lib/python3.12/site-packages/torch/onnx/_internal/fx/dynamo_graph_extractor.py", line 169, in wrapped
return output_adapter.apply(model_func(*args, **kwargs), model=model)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: DataCov.forward() takes 2 positional arguments but 3 were given

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/yafeng_wang/pytorch/./pytorch_export.py", line 26, in
export()
File "/home/yafeng_wang/pytorch/./pytorch_export.py", line 22, in export
torch.onnx.dynamo_export(model, (input), "DataCov.onnx")
File "/home/yafeng_wang/miniconda3/envs/onnx_export/lib/python3.12/site-packages/torch/onnx/_internal/exporter.py", line 1520, in dynamo_export
raise OnnxExporterError(
torch.onnx.OnnxExporterError: Failed to export the model to ONNX. Generating SARIF report at 'report_dynamo_export.sarif'. SARIF is a standard format for the output of static analysis tools. SARIF logs can be loaded in VS Code SARIF viewer extension, or SARIF web viewer (https://microsoft.github.io/sarif-web-component/). Please report a bug on PyTorch Github: https://github.com/pytorch/pytorch/issues

@WangHHY19931001
Copy link
Author

{
"runs":[
{
"tool":{
"driver":{
"name":"torch.onnx.dynamo_export",
"contents":[
"localizedData",
"nonLocalizedData"
],
"language":"en-US",
"rules":[],
"version":"2.5.0.dev20240613"
}
},
"language":"en-US",
"newlineSequences":[
"\r\n",
"\n"
],
"results":[]
}
],
"version":"2.1.0",
"schemaUri":"https://docs.oasis-open.org/sarif/sarif/v2.1.0/cs01/schemas/sarif-schema-2.1.0.json"
}

@heindrickdumdum0217
Copy link

Set following environment variable.

TORCH_ONNX_USE_EXPERIMENTAL_LOGIC=1

https://github.com/pytorch/pytorch/blob/main/torch/onnx/__init__.py#L473

@WangHHY19931001
Copy link
Author

TORCH_ONNX_USE_EXPERIMENTAL_LOGIC=1

still not work

@heindrickdumdum0217
Copy link

TORCH_ONNX_USE_EXPERIMENTAL_LOGIC=1

still not work

As my checking, dynamo export works, but next code in PyTorch tutorials do not work, because all code there supposed to use legacy exporter.

@justinchuby
Copy link
Collaborator

We are in the process of updating the tutorials. For now, please test with torch.onnx.export(..., dynamo=True, report=True) using the latest torch-nightly. Attach the generated report if there is an error. Thanks!

@heindrickdumdum0217
Copy link

We are in the process of updating the tutorials. For now, please test with torch.onnx.export(..., dynamo=True, report=True) using the latest torch-nightly. Attach the generated report if there is an error. Thanks!

Yes, as I said export works. I could export my model.
But subsequent codes in the tutorial doesn't work with new exporter, they are supposed to work with legacy exporter.

@WangHHY19931001
Copy link
Author

PyTorch ONNX Conversion Report

✅ Obtain model graph with `torch.export.export(..., strict=False)`
⚪ Obtain model graph with `torch.export.export(..., strict=True)`
⚪ Obtain model graph with `torch.jit.trace`
✅ Decompose operators for ONNX compatibility
✅ Translate the graph into ONNX
⚪ Run `onnx.checker` on the ONNX model
⚪ Execute the model with ONNX Runtime
⚪ Validate model output accuracy

Error messages

No errors

Exported program

ExportedProgram:
    class GraphModule(torch.nn.Module):
        def forward(self, b_transform_0_spectrogram_window: "f32[1536]", b_transform_0_mel_scale_fb: "f32[769, 128]", x1: "f32[1, 1, 576000]"):
             # File: /home/dingli/miniconda3/envs/ai_mos_export_onnx/lib/python3.12/site-packages/torchaudio/transforms/_transforms.py:110 in forward, code: return F.spectrogram(
            view: "f32[1, 576000]" = torch.ops.aten.view.default(x1, [-1, 576000]);  x1 = None
            view_1: "f32[1, 1, 576000]" = torch.ops.aten.view.default(view, [1, 1, 576000]);  view = None
            reflection_pad1d: "f32[1, 1, 577536]" = torch.ops.aten.reflection_pad1d.default(view_1, [768, 768]);  view_1 = None
            view_2: "f32[1, 577536]" = torch.ops.aten.view.default(reflection_pad1d, [1, 577536]);  reflection_pad1d = None
            unfold: "f32[1, 751, 1536]" = torch.ops.aten.unfold.default(view_2, -1, 1536, 768);  view_2 = None
            mul: "f32[1, 751, 1536]" = torch.ops.aten.mul.Tensor(unfold, b_transform_0_spectrogram_window);  unfold = b_transform_0_spectrogram_window = None
            _fft_r2c: "c64[1, 751, 769]" = torch.ops.aten._fft_r2c.default(mul, [2], 0, True);  mul = None
            transpose: "c64[1, 769, 751]" = torch.ops.aten.transpose.int(_fft_r2c, 1, 2);  _fft_r2c = None
            view_3: "c64[1, 1, 769, 751]" = torch.ops.aten.view.default(transpose, [1, 1, 769, 751]);  transpose = None
            abs_1: "f32[1, 1, 769, 751]" = torch.ops.aten.abs.default(view_3);  view_3 = None
            pow_1: "f32[1, 1, 769, 751]" = torch.ops.aten.pow.Tensor_Scalar(abs_1, 2.0);  abs_1 = None
            
             # File: /home/dingli/miniconda3/envs/ai_mos_export_onnx/lib/python3.12/site-packages/torchaudio/transforms/_transforms.py:412 in forward, code: mel_specgram = torch.matmul(specgram.transpose(-1, -2), self.fb).transpose(-1, -2)
            transpose_1: "f32[1, 1, 751, 769]" = torch.ops.aten.transpose.int(pow_1, -1, -2);  pow_1 = None
            matmul: "f32[1, 1, 751, 128]" = torch.ops.aten.matmul.default(transpose_1, b_transform_0_mel_scale_fb);  transpose_1 = b_transform_0_mel_scale_fb = None
            transpose_2: "f32[1, 1, 128, 751]" = torch.ops.aten.transpose.int(matmul, -1, -2);  matmul = None
            return (transpose_2,)
            
Graph signature: ExportGraphSignature(input_specs=[InputSpec(kind=<InputKind.BUFFER: 3>, arg=TensorArgument(name='b_transform_0_spectrogram_window'), target='transform.0.spectrogram.window', persistent=True), InputSpec(kind=<InputKind.BUFFER: 3>, arg=TensorArgument(name='b_transform_0_mel_scale_fb'), target='transform.0.mel_scale.fb', persistent=True), InputSpec(kind=<InputKind.USER_INPUT: 1>, arg=TensorArgument(name='x1'), target=None, persistent=None)], output_specs=[OutputSpec(kind=<OutputKind.USER_OUTPUT: 1>, arg=TensorArgument(name='transpose_2'), target=None)])
Range constraints: {}

ONNX model

<
    ir_version=10,
    opset_imports={'pkg.onnxscript.torch_lib.common': 1, '': 18, 'pkg.onnxscript.torch_lib': 1},
    producer_name='pytorch',
    producer_version='2.7.0.dev20250107+cpu',
    domain=None,
    model_version=None,
>
graph(
    name=main_graph,
    inputs=(
        %"wav_data"<FLOAT,[1,1,576000]>
    ),
    outputs=(
        %"ans"<FLOAT,[1,1,128,751]>
    ),
    initializers=(
        %"transform.0.spectrogram.window"<FLOAT,[1536]>,
        %"transform.0.mel_scale.fb"<FLOAT,[769,128]>
    ),
) {
     0 |  # node_Constant_0
          %"val_0"<?,?> ⬅️ ::Constant() {value=Tensor<INT64,[2]>(array([    -1, 576000]), name=None)}
     1 |  # node_Cast_1
          %"val_1"<?,?> ⬅️ ::Cast(%"val_0") {to=INT64}
     2 |  # node_Reshape_2
          %"view"<FLOAT,[1,576000]> ⬅️ ::Reshape(%"wav_data", %"val_1") {allowzero=0}
     3 |  # node_Constant_3
          %"val_2"<?,?> ⬅️ ::Constant() {value=Tensor<INT64,[3]>(array([     1,      1, 576000]), name=None)}
     4 |  # node_Cast_4
          %"val_3"<?,?> ⬅️ ::Cast(%"val_2") {to=INT64}
     5 |  # node_Reshape_5
          %"view_1"<FLOAT,[1,1,576000]> ⬅️ ::Reshape(%"view", %"val_3") {allowzero=0}
     6 |  # node_Constant_6
          %"val_4"<?,?> ⬅️ ::Constant() {value=Tensor<INT64,[2]>(array([768, 768]), name=None)}
     7 |  # node_aten_reflection_pad1d_7
          %"reflection_pad1d"<FLOAT,[1,1,577536]> ⬅️ pkg.onnxscript.torch_lib::aten_reflection_pad1d(%"view_1", %"val_4")
     8 |  # node_Constant_8
          %"val_5"<?,?> ⬅️ ::Constant() {value=Tensor<INT64,[2]>(array([     1, 577536]), name=None)}
     9 |  # node_Cast_9
          %"val_6"<?,?> ⬅️ ::Cast(%"val_5") {to=INT64}
    10 |  # node_Reshape_10
          %"view_2"<FLOAT,[1,577536]> ⬅️ ::Reshape(%"reflection_pad1d", %"val_6") {allowzero=0}
    11 |  # node__aten_unfold_onnx_11
          %"unfold"<FLOAT,[1,751,1536]> ⬅️ pkg.onnxscript.torch_lib::_aten_unfold_onnx(%"view_2") {dim=1, size=1536, step=768, target_end=751, perm=[0, 1, 2]}
    12 |  # node_Mul_12
          %"mul"<FLOAT,[1,751,1536]> ⬅️ ::Mul(%"unfold", %"transform.0.spectrogram.window")
    13 |  # node_Constant_13
          %"val_7"<?,?> ⬅️ ::Constant() {value=Tensor<INT64,[1]>(array([-1]), name=None)}
    14 |  # node_Unsqueeze_14
          %"val_8"<?,?> ⬅️ ::Unsqueeze(%"mul", %"val_7")
    15 |  # node_Constant_15
          %"val_9"<?,?> ⬅️ ::Constant() {value=Tensor<INT64,[1]>(array([0]), name=None)}
    16 |  # node_Unsqueeze_16
          %"val_10"<?,?> ⬅️ ::Unsqueeze(%"val_8", %"val_9")
    17 |  # node_DFT_17
          %"val_11"<?,?> ⬅️ ::DFT(%"val_10") {axis=3, inverse=False, onesided=True}
    18 |  # node_Squeeze_18
          %"_fft_r2c"<FLOAT,[1,751,769,2]> ⬅️ ::Squeeze(%"val_11", %"val_9")
    19 |  # node_Shape_19
          %"val_12"<?,?> ⬅️ ::Shape(%"val_8") {start=0}
    20 |  # node_Constant_20
          %"val_13"<?,?> ⬅️ ::Constant() {value=Tensor<INT64,[1]>(array([2]), name=None)}
    21 |  # node_Gather_21
          %"val_14"<?,?> ⬅️ ::Gather(%"val_12", %"val_13") {axis=0}
    22 |  # node_ReduceProd_22
          %"val_15"<?,?> ⬅️ ::ReduceProd(%"val_14") {keepdims=0, noop_with_empty_axes=0}
    23 |  # node_CastLike_23
          %"val_16"<?,?> ⬅️ ::CastLike(%"val_15", %"_fft_r2c")
    24 |  # node_Transpose_24
          %"transpose"<FLOAT,[1,769,751,2]> ⬅️ ::Transpose(%"_fft_r2c") {perm=[0, 2, 1, 3]}
    25 |  # node_Constant_25
          %"val_17"<?,?> ⬅️ ::Constant() {value=Tensor<INT64,[4]>(array([  1,   1, 769, 751]), name=None)}
    26 |  # node_aten_view_complex_26
          %"view_3"<FLOAT,[1,1,769,751,2]> ⬅️ pkg.onnxscript.torch_lib::aten_view_complex(%"transpose", %"val_17")
    27 |  # node_ReduceL2_27
          %"abs_1"<FLOAT,[1,1,769,751]> ⬅️ ::ReduceL2(%"view_3", %"val_7") {keepdims=False, noop_with_empty_axes=0}
    28 |  # node_Constant_28
          %"val_18"<?,?> ⬅️ ::Constant() {value=Tensor<FLOAT,[]>(array(2., dtype=float32), name=None)}
    29 |  # node_Pow_29
          %"pow_1"<FLOAT,[1,1,769,751]> ⬅️ ::Pow(%"abs_1", %"val_18")
    30 |  # node_Transpose_30
          %"transpose_1"<FLOAT,[1,1,751,769]> ⬅️ ::Transpose(%"pow_1") {perm=[0, 1, 3, 2]}
    31 |  # node_aten_matmul_31
          %"matmul"<FLOAT,[1,1,751,128]> ⬅️ pkg.onnxscript.torch_lib::aten_matmul(%"transpose_1", %"transform.0.mel_scale.fb")
    32 |  # node_Transpose_32
          %"ans"<FLOAT,[1,1,128,751]> ⬅️ ::Transpose(%"matmul") {perm=[0, 1, 3, 2]}
    return %"ans"<FLOAT,[1,1,128,751]>
}

<
    opset_imports={'': 18},
>
def pkg.onnxscript.torch_lib::aten_reflection_pad1d(
    inputs=(
        %"self"<?,?>,
        %"padding"<?,?>
    ),
    outputs=(
        %"return_val"<?,?>
    ),
) {
     0 |  # n0
          %"int64_0_1d"<?,?> ⬅️ ::Constant() {value=TensorProtoTensor<INT64,[1]>(name='int64_0_1d')}
     1 |  # n1
          %"int64_1_1d"<?,?> ⬅️ ::Constant() {value=TensorProtoTensor<INT64,[1]>(name='int64_1_1d')}
     2 |  # n2
          %"int64_0_1d_0"<?,?> ⬅️ ::Constant() {value=TensorProtoTensor<INT64,[1]>(name='int64_0_1d_0')}
     3 |  # n3
          %"start"<?,?> ⬅️ ::Slice(%"padding", %"int64_0_1d", %"int64_1_1d", %"int64_0_1d_0")
     4 |  # n4
          %"int64_1_1d_1"<?,?> ⬅️ ::Constant() {value=TensorProtoTensor<INT64,[1]>(name='int64_1_1d_1')}
     5 |  # n5
          %"int64_2_1d"<?,?> ⬅️ ::Constant() {value=TensorProtoTensor<INT64,[1]>(name='int64_2_1d')}
     6 |  # n6
          %"int64_0_1d_2"<?,?> ⬅️ ::Constant() {value=TensorProtoTensor<INT64,[1]>(name='int64_0_1d_2')}
     7 |  # n7
          %"end"<?,?> ⬅️ ::Slice(%"padding", %"int64_1_1d_1", %"int64_2_1d", %"int64_0_1d_2")
     8 |  # n8
          %"tmp"<?,?> ⬅️ ::Constant() {value_ints=[0]}
     9 |  # n9
          %"tmp_3"<?,?> ⬅️ ::Constant() {value_ints=[0]}
    10 |  # n10
          %"padding_onnx"<?,?> ⬅️ ::Concat(%"tmp", %"start", %"tmp_3", %"end") {axis=0}
    11 |  # n11
          %"return_val"<?,?> ⬅️ ::Pad(%"self", %"padding_onnx") {mode=reflect}
    return %"return_val"<?,?>
}

<
    opset_imports={'': 18},
>
def pkg.onnxscript.torch_lib::_aten_unfold_onnx(
    inputs=(
        %"self"<?,?>
    ),
    attributes={
        dim: UNDEFINED,
        size: UNDEFINED,
        step: UNDEFINED,
        target_end: UNDEFINED,
        perm: UNDEFINED
    }
    outputs=(
        %"return_val"<?,?>
    ),
) {
     0 |  # n0
          %"tmp"<?,?> ⬅️ ::Constant() {value_int=RefAttr('value_int', INT, ref_attr_name='dim')}
     1 |  # n1
          %"tmp_0"<?,?> ⬅️ ::Constant() {value_ints=[-1]}
     2 |  # n2
          %"dims"<?,?> ⬅️ ::Reshape(%"tmp", %"tmp_0")
     3 |  # n3
          %"seq_result"<?,?> ⬅️ ::SequenceEmpty()
     4 |  # n4
          %"i"<?,?> ⬅️ ::Constant() {value_int=0}
     5 |  # n5
          %"target_end"<?,?> ⬅️ ::Constant() {value_int=RefAttr('value_int', INT, ref_attr_name='target_end')}
     6 |  # n6
          %"target_end_cast"<?,?> ⬅️ ::CastLike(%"target_end", %"i")
     7 |  # n7
          %"cond"<?,?> ⬅️ ::Less(%"i", %"target_end_cast")
     8 |  # n8
          %"seq_result_8"<?,?>, %"i_9"<?,?> ⬅️ ::Loop(None, %"cond", %"seq_result", %"i") {body=
              graph(
                  name=loop_body,
                  inputs=(
                      %"infinite_loop"<INT64,[]>,
                      %"cond"<BOOL,[]>,
                      %"seq_result_1"<?,?>,
                      %"i_2"<?,?>
                  ),
                  outputs=(
                      %"cond_out"<BOOL,[]>,
                      %"seq_result_4"<?,?>,
                      %"i_5"<?,?>
                  ),
              ) {
                   0 |  # n0
                        %"step"<?,?> ⬅️ ::Constant() {value_int=RefAttr('value_int', INT, ref_attr_name='step')}
                   1 |  # n1
                        %"step_cast"<?,?> ⬅️ ::CastLike(%"step", %"i_2")
                   2 |  # n2
                        %"tmp_3"<?,?> ⬅️ ::Mul(%"i_2", %"step_cast")
                   3 |  # n3
                        %"int64_m1_1d"<?,?> ⬅️ ::Constant() {value=TensorProtoTensor<INT64,[1]>(name='int64_m1_1d')}
                   4 |  # n4
                        %"starts"<?,?> ⬅️ ::Reshape(%"tmp_3", %"int64_m1_1d")
                   5 |  # n5
                        %"size"<?,?> ⬅️ ::Constant() {value_int=RefAttr('value_int', INT, ref_attr_name='size')}
                   6 |  # n6
                        %"size_cast"<?,?> ⬅️ ::CastLike(%"size", %"starts")
                   7 |  # n7
                        %"ends"<?,?> ⬅️ ::Add(%"starts", %"size_cast")
                   8 |  # n8
                        %"slice_result"<?,?> ⬅️ ::Slice(%"self", %"starts", %"ends", %"dims")
                   9 |  # n9
                        %"slice_result_float32"<?,?> ⬅️ ::Cast(%"slice_result") {to=1}
                  10 |  # n10
                        %"seq_result_4"<?,?> ⬅️ ::SequenceInsert(%"seq_result_1", %"slice_result_float32")
                  11 |  # n11
                        %"int64_1"<?,?> ⬅️ ::Constant() {value=TensorProtoTensor<INT64,[]>(name='int64_1')}
                  12 |  # n12
                        %"int64_1_cast"<?,?> ⬅️ ::CastLike(%"int64_1", %"i_2")
                  13 |  # n13
                        %"i_5"<?,?> ⬅️ ::Add(%"i_2", %"int64_1_cast")
                  14 |  # n14
                        %"target_end_6"<?,?> ⬅️ ::Constant() {value_int=RefAttr('value_int', INT, ref_attr_name='target_end')}
                  15 |  # n15
                        %"target_end_6_cast"<?,?> ⬅️ ::CastLike(%"target_end_6", %"i_5")
                  16 |  # n16
                        %"cond_7"<?,?> ⬅️ ::Less(%"i_5", %"target_end_6_cast")
                  17 |  # n17
                        %"cond_out"<BOOL,[]> ⬅️ ::Identity(%"cond_7")
                  return %"cond_out"<BOOL,[]>, %"seq_result_4"<?,?>, %"i_5"<?,?>
              }}
     9 |  # n9
          %"concat_result"<?,?> ⬅️ ::ConcatFromSequence(%"seq_result_8") {axis=RefAttr('axis', INT, ref_attr_name='dim'), new_axis=1}
    10 |  # n10
          %"result"<?,?> ⬅️ ::Transpose(%"concat_result") {perm=RefAttr('perm', INTS, ref_attr_name='perm')}
    11 |  # n11
          %"return_val"<?,?> ⬅️ ::CastLike(%"result", %"self")
    return %"return_val"<?,?>
}

<
    opset_imports={'': 18},
>
def pkg.onnxscript.torch_lib::aten_view_complex(
    inputs=(
        %"self"<?,?>,
        %"size"<?,?>
    ),
    outputs=(
        %"return_val"<?,?>
    ),
) {
    0 |  # n0
         %"size_0"<?,?> ⬅️ ::Cast(%"size") {to=7}
    1 |  # n1
         %"tmp"<?,?> ⬅️ ::Constant() {value_ints=[2]}
    2 |  # n2
         %"complex_size"<?,?> ⬅️ ::Concat(%"size_0", %"tmp") {axis=0}
    3 |  # n3
         %"return_val"<?,?> ⬅️ ::Reshape(%"self", %"complex_size")
    return %"return_val"<?,?>
}

<
    opset_imports={'': 18},
>
def pkg.onnxscript.torch_lib::aten_matmul(
    inputs=(
        %"self"<?,?>,
        %"other"<?,?>
    ),
    outputs=(
        %"return_val"<?,?>
    ),
) {
    0 |  # n0
         %"return_val"<?,?> ⬅️ ::MatMul(%"self", %"other")
    return %"return_val"<?,?>
}

<
    opset_imports={'': 18},
>
def pkg.onnxscript.torch_lib.common::Rank(
    inputs=(
        %"input"<?,?>
    ),
    outputs=(
        %"return_val"<?,?>
    ),
) {
    0 |  # n0
         %"tmp"<?,?> ⬅️ ::Shape(%"input")
    1 |  # n1
         %"return_val"<?,?> ⬅️ ::Size(%"tmp")
    return %"return_val"<?,?>
}

<
    opset_imports={'': 18},
>
def pkg.onnxscript.torch_lib.common::IsScalar(
    inputs=(
        %"input"<?,?>
    ),
    outputs=(
        %"return_val"<?,?>
    ),
) {
    0 |  # n0
         %"tmp"<?,?> ⬅️ ::Shape(%"input")
    1 |  # n1
         %"tmp_0"<?,?> ⬅️ ::Size(%"tmp")
    2 |  # n2
         %"tmp_1"<?,?> ⬅️ ::Constant() {value_int=0}
    3 |  # n3
         %"return_val"<?,?> ⬅️ ::Equal(%"tmp_0", %"tmp_1")
    return %"return_val"<?,?>
}

Analysis

PyTorch ONNX Conversion Analysis

Model Information

The model has 0 parameters and 99968 buffers (non-trainable parameters).
Number of parameters per dtype:

defaultdict(<class 'int'>, {})

Number of buffers per dtype:

defaultdict(<class 'int'>, {torch.float32: 99968})

Inputs:

  • x1: TensorMetadata(shape=torch.Size([1, 1, 576000]), dtype=torch.float32, requires_grad=True, stride=(576000, 576000, 1), memory_format=torch.contiguous_format, is_quantized=False, qparams={})

Outputs:

  • transpose_2: TensorMetadata(shape=torch.Size([1, 1, 128, 751]), dtype=torch.float32, requires_grad=False, stride=(96128, 96128, 1, 128), memory_format=None, is_quantized=False, qparams={})

The FX graph has 18 nodes in total. Number of FX nodes per op:

  • placeholder: 3
  • call_function: 14
  • output: 1

Of the call_function nodes, the counts of operators used are:

  • aten.view.default: 4
  • aten.transpose.int: 3
  • aten.reflection_pad1d.default: 1
  • aten.unfold.default: 1
  • aten.mul.Tensor: 1
  • aten._fft_r2c.default: 1
  • aten.abs.default: 1
  • aten.pow.Tensor_Scalar: 1
  • aten.matmul.default: 1

ONNX Conversion Information

All operators in the model have registered ONNX decompositions.

Decomposition comparison

Ops exist only in the ExportedProgram before decomposition: ['aten.pad.default', 'aten.reshape.default', 'aten.stft.default']

Ops exist only in the ExportedProgram after decomposition: ['aten._fft_r2c.default', 'aten.mul.Tensor', 'aten.reflection_pad1d.default', 'aten.unfold.default']

@WangHHY19931001
Copy link
Author

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

@WangHHY19931001
Copy link
Author
WangHHY19931001 commented Jan 8, 2025

still has some error with test:
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.

test code :

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)

onnx export code:

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)

model:

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: onnx Related to torch.onnx triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
Status: Done
Development

No branches or pull requests

5 participants
0