Skip to content
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

torch.onnx.dynamo_export optimizer failed when slice the array with dynamic_shapes #1934

Open
laan8613 opened this issue Nov 7, 2024 · 1 comment

Comments

@laan8613
Copy link

laan8613 commented Nov 7, 2024

Problem

Transfer model from pytorch to onnx by torch.onnx.dynamo_export failed.
These failed occured when array slicing inside model and set torch.onnx.ExportOptions(dynamic_shapes=True), it can run successfully when not set dynamic_shapes.
Also, some slicing can run successfully, and some not

I am not sure pytorch or onnxscript cause the problem, so I report both.

Provided a minimum reproduced code below

Code

import torch
from torch import nn
class Model(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc0 = nn.Conv2d(3, 64, 3, bias=True)
    
    def forward(self, x: torch.Tensor):
        x = self.fc0(x)
        return x[:, 2:, :-1] # failed
        # return x[:, :, :, :2] # failed
        # return x[:, 2:] # ok
        # return x[:, :-1] # ok
        # return x[:, :, 2:, 2:] # ok
        # return x[:, :, 2:, :-1] # failed

model = Model()
tensor_x = torch.rand((1, 3, 64,64), dtype=torch.float32)
export_options = torch.onnx.ExportOptions(dynamic_shapes=True)
onnx_program = torch.onnx.dynamo_export(model, tensor_x, export_options=export_options)

Log

/home/user/anaconda3/envs/imw/lib/python3.10/site-packages/onnxscript/converter.py:820: FutureWarning: 'onnxscript.values.Op.param_schemas' is deprecated in version 0.1 and will be removed in the future. Please use '.op_signature' instead.
  param_schemas = callee.param_schemas()
/home/user/anaconda3/envs/imw/lib/python3.10/site-packages/onnxscript/converter.py:820: FutureWarning: 'onnxscript.values.OnnxFunction.param_schemas' is deprecated in version 0.1 and will be removed in the future. Please use '.op_signature' instead.
  param_schemas = callee.param_schemas()
/home/user/anaconda3/envs/imw/lib/python3.10/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(
/home/user/anaconda3/envs/imw/lib/python3.10/site-packages/torch/onnx/_internal/fx/onnxfunction_dispatcher.py:529: FutureWarning: 'onnxscript.values.TracedOnnxFunction.param_schemas' is deprecated in version 0.1 and will be removed in the future. Please use '.op_signature' instead.
  self.param_schema = self.onnxfunction.param_schemas()
/home/user/anaconda3/envs/imw/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py:1281: UserWarning: ONNXScript optimizer failed. Skipping optimization. 

PLEASE REPORT A BUG AT https://github.com/microsoft/onnxscript/issues 

Detail:
'<' not supported between instances of 'int' and 'SymbolicDim'
  warnings.warn(

Versions

PyTorch version: 2.4.0
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.30.2
Libc version: glibc-2.35

Python version: 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:08:06) [GCC 11.3.0] (64-bit runtime)
Python platform: Linux-6.1.21.2-microsoft-standard-WSL2+-x86_64-with-glibc2.35
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:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 46 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 20
On-line CPU(s) list: 0-19
Vendor ID: GenuineIntel
Model name: 12th Gen Intel(R) Core(TM) i7-12700
CPU family: 6
Model: 151
Thread(s) per core: 2
Core(s) per socket: 10
Socket(s): 1
Stepping: 2
BogoMIPS: 4223.99
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves avx_vnni umip waitpkg gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm md_clear serialize ibt flush_l1d arch_capabilities
Virtualization: VT-x
Hypervisor vendor: Microsoft
Virtualization type: full
L1d cache: 480 KiB (10 instances)
L1i cache: 320 KiB (10 instances)
L2 cache: 12.5 MiB (10 instances)
L3 cache: 25 MiB (1 instance)
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: Mitigation; Enhanced IBRS
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 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==2.0.2
[pip3] onnx==1.17.0
[pip3] onnx-tf==1.10.0
[pip3] onnxruntime==1.19.2
[pip3] onnxscript==0.1.0.dev20241104
[pip3] onnxslim==0.1.36
[pip3] optree==0.13.0
[pip3] pytorch-lightning==1.4.9
[pip3] torch==2.4.0
[pip3] torch-xla==2.5.1
[pip3] torchmetrics==0.6.0
[pip3] torchvision==0.19.0
[pip3] triton==3.0.0
[conda] blas 2.16 mkl conda-forge
[conda] cuda-cudart 12.1.105 0 nvidia
[conda] cuda-cupti 12.1.105 0 nvidia
[conda] cuda-libraries 12.1.0 0 nvidia
[conda] cuda-nvrtc 12.1.105 0 nvidia
[conda] cuda-nvtx 12.1.105 0 nvidia
[conda] cuda-opencl 12.6.77 0 nvidia
[conda] cuda-runtime 12.1.0 0 nvidia
[conda] libblas 3.8.0 16_mkl conda-forge
[conda] libcblas 3.8.0 16_mkl conda-forge
[conda] libcublas 12.1.0.26 0 nvidia
[conda] libcufft 11.0.2.4 0 nvidia
[conda] libcurand 10.3.7.77 0 nvidia
[conda] libcusolver 11.4.4.55 0 nvidia
[conda] libcusparse 12.0.2.55 0 nvidia
[conda] liblapack 3.8.0 16_mkl conda-forge
[conda] liblapacke 3.8.0 16_mkl conda-forge
[conda] libnvjitlink 12.1.105 0 nvidia
[conda] mkl 2020.2 256
[conda] numpy 1.23.5 pypi_0 pypi
[conda] pytorch 2.4.0 py3.10_cuda12.1_cudnn9.1.0_0 pytorch
[conda] pytorch-cuda 12.1 ha16c6d3_6 pytorch
[conda] pytorch-lightning 1.4.9 pypi_0 pypi
[conda] pytorch-mutex 1.0 cuda pytorch
[conda] torch-xla 2.5.1 pypi_0 pypi
[conda] torchmetrics 0.6.0 pypi_0 pypi
[conda] torchtriton 3.0.0 py310 pytorch
[conda] torchvision 0.19.0 pypi_0 pypi

@justinchuby
Copy link
Collaborator

Cc @gramalingam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants