Repository: pytorch
Issue: ` to be a quantized tensor. Is this likely due to missing support for quantized `onnx::Pad`
Labels: module: onnx,triaged

### 🐛 Describe the bug

I tried to export my quantized-model from pytorch to onnx but failed with following logs

/usr/local/lib/python3.10/dist-packages/torch/ao/quantization/observer.py:1272: UserWarning: must run observer before calling calculate_qparams.                                    Returning default scale and zero point 
  warnings.warn(
/usr/local/lib/python3.10/dist-packages/torch/_utils.py:403: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly.  To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
  device=storage.device,
/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py:1547: OnnxExporterWarning: Exporting to ONNX opset version 19 is not supported. by 'torch.onnx.export()'. The highest opset version supported is 17. To use a newer opset version, consider 'torch.onnx.dynamo_export()'. Note that dynamo_export() is in preview. Please report errors with dynamo_export() as Github issues to https://github.com/pytorch/pytorch/issues.
  warnings.warn(
/home/workspace/point-cloud-de-noising/src/orin/padding.py:31: TracerWarning: Converting a tensor to a Python float might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  math.floor(p_h / 2),
/home/workspace/point-cloud-de-noising/src/orin/padding.py:32: TracerWarning: Converting a tensor to a Python float might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  math.ceil(p_h / 2),
/home/workspace/point-cloud-de-noising/src/orin/padding.py:33: TracerWarning: Converting a tensor to a Python float might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  math.floor(p_w / 2),
/home/workspace/point-cloud-de-noising/src/orin/padding.py:34: TracerWarning: Converting a tensor to a Python float might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  math.ceil(p_w / 2),
Traceback (most recent call last):
  File "/home/workspace/point-cloud-de-noising/src/orin/train.py", line 60, in <module>
    quantized_test()
  File "/home/workspace/point-cloud-de-noising/src/orin/train.py", line 25, in quantized_test
    torch.onnx.export(
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py", line 516, in export
    _export(
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py", line 1612, in _export
    graph, params_dict, torch_out = _model_to_graph(
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py", line 1138, in _model_to_graph
    graph = _optimize_graph(
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py", line 677, in _optimize_graph
    graph = _C._jit_pass_onnx(graph, operator_export_type)
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py", line 1956, in _run_symbolic_function
    return symbolic_fn(graph_context, *inputs, **attrs)
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/symbolic_opset13.py", line 954, in quantized_conv2d_relu
    input, input_scale, _, _ = symbolic_helper.dequantize_helper(g, q_input)
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/symbolic_helper.py", line 1591, in dequantize_helper
    unpacked_qtensors = _unpack_quantized_tensor(qtensor)
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/symbolic_helper.py", line 216, in _unpack_quantized_tensor
    raise errors.SymbolicValueError(
torch.onnx.errors.SymbolicValueError: ONNX symbolic expected the output of `%input.3 : Tensor = onnx::Pad[mode="constant"](%input, %193, %194), scope: mistnet.MistNet::/lilanet.EvenBlock::lila1 # /usr/local/lib/python3.10/dist-packages/torch/nn/functional.py:4522:0
` to be a quantized tensor. Is this likely due to missing support for quantized `onnx::Pad`. Please create an issue on https://github.com/pytorch/pytorch/issues  [Caused by the value 'input.3 defined in (%input.3 : Tensor = onnx::Pad[mode="constant"](%input, %193, %194), scope: mistnet.MistNet::/lilanet.EvenBlock::lila1 # /usr/local/lib/python3.10/dist-packages/torch/nn/functional.py:4522:0
)' (type 'Tensor') in the TorchScript graph. The containing node has kind 'onnx::Pad'.] 
    (node defined in /usr/local/lib/python3.10/dist-packages/torch/nn/functional.py(4522): pad
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/padding.py(205): forward
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1501): _slow_forward
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1520): _call_impl
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1511): _wrapped_call_impl
/home/workspace/point-cloud-de-noising/src/orin/lilanet.py(160): forward
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1501): _slow_forward
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1520): _call_impl
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1511): _wrapped_call_impl
/home/workspace/point-cloud-de-noising/src/orin/mistnet.py(46): forward
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1501): _slow_forward
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1520): _call_impl
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1511): _wrapped_call_impl
/usr/local/lib/python3.10/dist-packages/torch/jit/_trace.py(1074): trace_module
/usr/local/lib/python3.10/dist-packages/torch/jit/_trace.py(806): trace
/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py(1088): _pre_trace_quant_model
/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py(1133): _model_to_graph
/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py(1612): _export
/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py(516): export
/home/workspace/point-cloud-de-noising/src/orin/train.py(25): quantized_test
/home/workspace/point-cloud-de-noising/src/orin/train.py(60): <module>
)

    Inputs:
        #0: input defined in (%input : Tensor = prim::TupleConstruct(%65, %64, %63), scope: mistnet.MistNet::/torch.ao.nn.quantized.modules.Quantize::quant # /usr/local/lib/python3.10/dist-packages/torch/ao/nn/quantized/modules/__init__.py:97:0
    )  (type 'Tensor')
        #1: 193 defined in (%193 : Long(*) = onnx::Cast[to=7](%192), scope: mistnet.MistNet::/lilanet.EvenBlock::lila1 # /usr/local/lib/python3.10/dist-packages/torch/nn/functional.py:4522:0
    )  (type 'Tensor')
        #2: 194 defined in (%194 : Double(device=cpu) = onnx::Constant[value={0}](), scope: mistnet.MistNet::/lilanet.EvenBlock::lila1 # /usr/local/lib/python3.10/dist-packages/torch/nn/functional.py:4522:0
    )  (type 'Tensor')
    Outputs:
        #0: input.3 defined in (%input.3 : Tensor = onnx::Pad[mode="constant"](%input, %193, %194), scope: mistnet.MistNet::/lilanet.EvenBlock::lila1 # /usr/local/lib/python3.10/dist-packages/torch/nn/functional.py:4522:0
    )  (type 'Tensor')

### Versions

Collecting environment information...
PyTorch version: 2.3.0a0+40ec155e58.nv24.03
Is debug build: False
CUDA used to build PyTorch: 12.4
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.28.3
Libc version: glibc-2.35

Python version: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-[5.15.146.1](http://5.15.146.1/)-microsoft-standard-WSL2-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.4.99
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3090
Nvidia driver version: 546.17
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.0.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.0.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.0.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.0.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.0.0
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.0.0
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.0.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.0.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, 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-12700K
CPU family:                         6
Model:                              151
Thread(s) per core:                 2
Core(s) per socket:                 10
Socket(s):                          1
Stepping:                           2
BogoMIPS:                           7219.19
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 sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch 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 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 Gather data sampling: Not affected
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 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:      Not affected

Versions of relevant libraries:
[pip3] numpy==1.24.4
[pip3] onnx==1.15.0rc2
[pip3] optree==0.10.0
[pip3] pytorch-quantization==2.1.2
[pip3] pytorch-triton==2.2.0+e28a256d7
[pip3] torch==2.3.0a0+40ec155e58.nv24.3
[pip3] torch-tensorrt==2.3.0a0
[pip3] torch2trt==0.5.0
[pip3] torchdata==0.7.1a0
[pip3] torchmetrics==1.4.0.post0
[pip3] torchtext==0.17.0a0
[pip3] torchvision==0.18.0a0
[conda] Could not collect