Skip to content

[ONNX] torch.onnx.errors.SymbolicValueError: Unsupported: ONNX export of operator get_pool_ceil_padding, input size not accessible. #113155

@daniil-lyakhov

Description

@daniil-lyakhov

🐛 Describe the bug

Hi there! I'm updating PyTorch version in our project, but I've encountered an issue:
Following code

from pathlib import Path
import torch
import torchvision

def main():
    weights_name = "SSD300_VGG16_Weights.DEFAULT"
    # Get the pretrained ssd300_vgg16 model from torchvision.models
    model = torchvision.models.get_model("ssd300_vgg16", weights=weights_name)
    device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
    model.to(device)
    model.eval()

    dummy_input = torch.randn(1, 3, 480, 480)
    ROOT = Path(__file__).parent.resolve()
    fp32_onnx_path = f"{ROOT}/ssd300_vgg16_fp32.onnx"
    torch.onnx.export(model.cpu(), dummy_input, fp32_onnx_path)


if __name__ == "__main__":
    main()

leads to following error:

/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torchvision/ops/boxes.py:157: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  boxes_x = torch.min(boxes_x, torch.tensor(width, dtype=boxes.dtype, device=boxes.device))
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torchvision/ops/boxes.py:159: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  boxes_y = torch.min(boxes_y, torch.tensor(height, dtype=boxes.dtype, device=boxes.device))
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torchvision/models/detection/transform.py:306: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  torch.tensor(s, dtype=torch.float32, device=boxes.device)
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torchvision/models/detection/transform.py:307: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  / torch.tensor(s_orig, dtype=torch.float32, device=boxes.device)
Traceback (most recent call last):
  File "main_test.py", line 20, in <module>
    main()
  File "main_test.py", line 16, in main
    torch.onnx.export(model.cpu(), dummy_input, fp32_onnx_path)
  File "/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/utils.py", line 516, in export
    _export(
  File "/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/utils.py", line 1596, in _export
    graph, params_dict, torch_out = _model_to_graph(
  File "/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/utils.py", line 1139, in _model_to_graph
    graph = _optimize_graph(
  File "/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/utils.py", line 677, in _optimize_graph
    graph = _C._jit_pass_onnx(graph, operator_export_type)
  File "/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/utils.py", line 1940, in _run_symbolic_function
    return symbolic_fn(graph_context, *inputs, **attrs)
  File "/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/symbolic_helper.py", line 395, in wrapper
    return fn(g, *args, **kwargs)
  File "/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/symbolic_helper.py", line 306, in wrapper
    return fn(g, *args, **kwargs)
  File "/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/symbolic_opset10.py", line 203, in symbolic_fn
    padding_ceil = opset9.get_pool_ceil_padding(
  File "/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/symbolic_opset9.py", line 1565, in get_pool_ceil_padding
    return symbolic_helper._unimplemented(
  File "/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/symbolic_helper.py", line 612, in _unimplemented
    _onnx_unsupported(f"{op}, {msg}", value)
  File "/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/symbolic_helper.py", line 623, in _onnx_unsupported
    raise errors.SymbolicValueError(
torch.onnx.errors.SymbolicValueError: Unsupported: ONNX export of operator get_pool_ceil_padding, input size not accessible. Please feel free to request support or submit a pull request on PyTorch GitHub: https://github.com/pytorch/pytorch/issues  [Caused by the value '217 defined in (%217 : Float(1, 256, *, *, strides=[1440000, 5625, 75, 1], requires_grad=1, device=cpu) = onnx::Relu(%input.35), scope: torchvision.models.detection.ssd.SSD::/torchvision.models.detection.ssd.SSDFeatureExtractorVGG::backbone/torch.nn.modules.container.Sequential::features/torch.nn.modules.activation.ReLU::features.15 # /home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/functional.py:1469:0
)' (type 'Tensor') in the TorchScript graph. The containing node has kind 'onnx::Relu'.] 
    (node defined in /home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/functional.py(1469): relu
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/activation.py(101): forward
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/module.py(1508): _slow_forward
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/module.py(1527): _call_impl
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/module.py(1518): _wrapped_call_impl
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/container.py(215): forward
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/module.py(1508): _slow_forward
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/module.py(1527): _call_impl
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/module.py(1518): _wrapped_call_impl
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torchvision/models/detection/ssd.py(541): forward
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/module.py(1508): _slow_forward
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/module.py(1527): _call_impl
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/module.py(1518): _wrapped_call_impl
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torchvision/models/detection/ssd.py(371): forward
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/module.py(1508): _slow_forward
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/module.py(1527): _call_impl
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/module.py(1518): _wrapped_call_impl
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/jit/_trace.py(124): wrapper
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/jit/_trace.py(133): forward
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/module.py(1527): _call_impl
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/module.py(1518): _wrapped_call_impl
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/jit/_trace.py(1285): _get_trace_graph
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/utils.py(915): _trace_and_get_graph_from_model
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/utils.py(1011): _create_jit_graph
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/utils.py(1135): _model_to_graph
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/utils.py(1596): _export
/home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/onnx/utils.py(516): export
main_test.py(16): main
main_test.py(20): <module>
)

    Inputs:
        #0: input.35 defined in (%input.35 : Float(1, 256, *, *, strides=[1440000, 5625, 75, 1], requires_grad=0, device=cpu) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[1, 1, 1, 1], strides=[1, 1]](%215, %backbone.features.14.weight, %backbone.features.14.bias), scope: torchvision.models.detection.ssd.SSD::/torchvision.models.detection.ssd.SSDFeatureExtractorVGG::backbone/torch.nn.modules.container.Sequential::features/torch.nn.modules.conv.Conv2d::features.14 # /home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/modules/conv.py:456:0
    )  (type 'Tensor')
    Outputs:
        #0: 217 defined in (%217 : Float(1, 256, *, *, strides=[1440000, 5625, 75, 1], requires_grad=1, device=cpu) = onnx::Relu(%input.35), scope: torchvision.models.detection.ssd.SSD::/torchvision.models.detection.ssd.SSDFeatureExtractorVGG::backbone/torch.nn.modules.container.Sequential::features/torch.nn.modules.activation.ReLU::features.15 # /home/dlyakhov/Projects/nncf_legacy/nncf_/lib/python3.8/site-packages/torch/nn/functional.py:1469:0
    )  (type 'Tensor')

Works fine with torch==2.0.1 torchvision==0.15.2

Can be related to the #101397 issue
CC: @titaiwangms

Versions

PyTorch version: 2.1.0+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Clang version: Could not collect
CMake version: version 3.27.7
Libc version: glibc-2.31

Python version: 3.8.10 (default, May 26 2023, 14:05:08)  [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.15.0-88-generic-x86_64-with-glibc2.29
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA GeForce RTX 3090
GPU 1: NVIDIA GeForce RTX 3090
GPU 2: NVIDIA GeForce RTX 3090

Nvidia driver version: 525.147.05
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                       x86_64
CPU op-mode(s):                     32-bit, 64-bit
Byte Order:                         Little Endian
Address sizes:                      46 bits physical, 48 bits virtual
CPU(s):                             36
On-line CPU(s) list:                0-35
Thread(s) per core:                 2
Core(s) per socket:                 18
Socket(s):                          1
NUMA node(s):                       1
Vendor ID:                          GenuineIntel
CPU family:                         6
Model:                              85
Model name:                         Intel(R) Core(TM) i9-10980XE CPU @ 3.00GHz
Stepping:                           7
CPU MHz:                            3000.000
CPU max MHz:                        4800,0000
CPU min MHz:                        1200,0000
BogoMIPS:                           6000.00
Virtualization:                     VT-x
L1d cache:                          576 KiB
L1i cache:                          576 KiB
L2 cache:                           18 MiB
L3 cache:                           24,8 MiB
NUMA node0 CPU(s):                  0-35
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit:        KVM: Mitigation: VMX disabled
Vulnerability L1tf:                 Not affected
Vulnerability Mds:                  Not affected
Vulnerability Meltdown:             Not affected
Vulnerability Mmio stale data:      Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:             Mitigation; Enhanced IBRS
Vulnerability Spec rstack overflow: 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:      Mitigation; TSX disabled
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 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 cdp_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 mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512_vnni md_clear flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] efficientnet-pytorch==0.7.1
[pip3] numpy==1.24.4
[pip3] onnx==1.13.1
[pip3] onnxruntime==1.14.1
[pip3] torch==2.1.0+cu118
[pip3] torchmetrics==1.0.1
[pip3] torchvision==0.16.0+cu118
[pip3] triton==2.1.0
[conda] Could not collect

Metadata

Metadata

Assignees

Labels

module: onnxRelated to torch.onnxmodule: regressionIt used to work, and now it doesn'tonnx-triagedtriaged by ONNX teamtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions