Repository: pytorch
Issue: Convert LSTM quantized by QAT to onnx
Labels: module: onnx,triaged

### 🐛 Describe the bug

```torch.onnx.errors.SymbolicValueError: ONNX symbolic expected the output of `%2212 : Tensor = onnx::Squeeze(%2186, %2211), scope: SimpleLSTMNet::/torch.ao.nn.quantized.modules.rnn.LSTM::0/torch.ao.nn.quantizable.modules.rnn._LSTMLayer::layers.0/torch.ao.nn.quantizable.modules.rnn._LSTMSingleLayer::layer_fw # /home/ct-admin/.venv/lib/python3.11/site-packages/torch/_tensor.py:940:0
` to be a quantized tensor. Is this likely due to missing support for quantized `onnx::Squeeze`. Please create an issue on https://github.com/pytorch/pytorch/issues  [Caused by the value '2212 defined in (%2212 : Tensor = onnx::Squeeze(%2186, %2211), scope: SimpleLSTMNet::/torch.ao.nn.quantized.modules.rnn.LSTM::0/torch.ao.nn.quantizable.modules.rnn._LSTMLayer::layers.0/torch.ao.nn.quantizable.modules.rnn._LSTMSingleLayer::layer_fw # /home/ct-admin/.venv/lib/python3.11/site-packages/torch/_tensor.py:940:0
)' (type 'Tensor') in the TorchScript graph. The containing node has kind 'onnx::Squeeze'.]```
# Define the LSTM model
```
import torch
class SimpleLSTMNet(torch.nn.Module):
  def __init__(self, hidden_dim, output_dim, num_layers):
      super(SimpleLSTMNet, self).__init__()
      self.hidden_dim = hidden_dim
      self.num_layers = num_layers
      self.lstm = torch.nn.ModuleList()
      for i in range(output_dim):
          self.lstm.append(torch.nn.LSTM(1280, hidden_dim, num_layers, batch_first=True))
      self.quant = torch.quantization.QuantStub()
      self.dequant = torch.quantization.DeQuantStub()
      self.float_func = torch.nn.quantized.FloatFunctional()
  def forward(self, inputs):
      x = self.quant(inputs)
      out = list()
      for index, lstm_mod in enumerate(self.lstm):
          # Forward propagate LSTM
          out1, _ = lstm_mod(x)
          out += [out1]
      out = self.float_func.cat(out, dim=-1)
      out = self.dequant(out)
      return out
```
# Load the torch model
    frames = torch.rand(1, 25, 1280)
    model = SimpleLSTMNet(hidden_dim=128, output_dim=2, num_layers=3)
    backend = 'qnnpack'
    torch.backends.quantized.engine = backend
    model.eval()
    model.qconfig = torch.quantization.get_default_qat_qconfig(backend)
    model.train()
    torch.quantization.prepare_qat(model, inplace=True)
    torch_net = torch.quantization.convert(model, inplace=True)
    torch_net.eval()
    torch_pred = torch_net(frames)

    # Load the onnx model
    input_name = ['input']
    output_names = ['output']
    torch.onnx.export(torch_net, frames, input_names=input_name, output_names=output_names,
                      f=os.path.join(temp_save_folder, best_save_path).replace('.pt', '.onnx'))

### Versions

PyTorch version: 2.0.0+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 23.04 (x86_64)
GCC version: (Ubuntu 12.3.0-1ubuntu1~23.04) 12.3.0
Clang version: Could not collect
CMake version: version 3.25.0
Libc version: glibc-2.37

Python version: 3.11.5 (main, Sep 11 2023, 13:54:46) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-6.2.0-39-generic-x86_64-with-glibc2.37
Is CUDA available: True
CUDA runtime version: 11.8.89
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA GeForce RTX 3090
GPU 1: NVIDIA GeForce RTX 3090

Nvidia driver version: 535.146.02
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.7
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) i9-11900F @ 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:                 79%
CPU max MHz:                        5200.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 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 invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi 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 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 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 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] onnx==1.14.1
[pip3] onnxruntime==1.16.0
[pip3] torch==2.0.0+cu118
[pip3] torchaudio==2.0.1+cu118
[pip3] torchmetrics==1.4.1
[pip3] torchvision==0.15.1+cu118
[pip3] triton==2.0.0
[conda] _anaconda_depends         2023.09             py311_mkl_1  
[conda] blas                      1.0                         mkl  
[conda] mkl                       2023.1.0         h213fc3f_46343  
[conda] mkl-service               2.4.0           py311h5eee18b_1  
[conda] mkl_fft                   1.3.8           py311h5eee18b_0  
[conda] mkl_random                1.2.4           py311hdb19cb5_0  
[conda] numpy                     1.24.3          py311h08b1b3b_1  
[conda] numpy-base                1.24.3          py311hf175353_1  
[conda] numpydoc                  1.5.0           py311h06a4308_0  
[conda] torch                     2.1.1                    pypi_0    pypi
[conda] torchvision               0.16.1                   pypi_0    pypi
[conda] triton                    2.1.0                    pypi_0    pypi