Repository: pytorch
Issue: Quantization issue in transformers
Labels: oncall: quantization,low priority,triaged

### 🐛 Describe the bug

This issue happened when quantizing a simple transformer model

Example
```
    class M(torch.nn.Module):
        def __init__(self):
            super(DynamicQuantModule.M, self).__init__()
            self.transformer = nn.Transformer(d_model=2, nhead=2, num_encoder_layers=1, num_decoder_layers=1)

        def forward(self):
            return self.transformer(torch.randn(1, 16, 2))
    
    torch.quantization.quantize_dynamic(M(), dtype=torch.qint8)
```

The error is

```
  File "/Users/linbin/opt/anaconda3/lib/python3.8/site-packages/torch/jit/_recursive.py", line 516, in init_fn
    scripted = create_script_module_impl(orig_value, sub_concrete_type, stubs_fn)
  File "/Users/linbin/opt/anaconda3/lib/python3.8/site-packages/torch/jit/_recursive.py", line 542, in create_script_module_impl
    create_methods_and_properties_from_stubs(concrete_type, method_stubs, property_stubs)
  File "/Users/linbin/opt/anaconda3/lib/python3.8/site-packages/torch/jit/_recursive.py", line 393, in create_methods_and_properties_from_stubs
    concrete_type._create_methods_and_properties(property_defs, property_rcbs, method_defs, method_rcbs, method_defaults)
RuntimeError:
method cannot be used as a value:
  File "/Users/linbin/opt/anaconda3/lib/python3.8/site-packages/torch/nn/modules/transformer.py", line 468
                self.norm2.weight,
                self.norm2.bias,
                self.linear1.weight,
                ~~~~~~~~~~~~~~~~~~~ <--- HERE
                self.linear1.bias,
                self.linear2.weight,
```

### Versions

PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: macOS 12.4 (x86_64)
GCC version: Could not collect
Clang version: 13.0.0 (clang-1300.0.18.6)
CMake version: version 3.21.3
Libc version: N/A

Python version: 3.7.5 (default, Oct 22 2019, 10:35:10)  [Clang 10.0.1 (clang-1001.0.46.4)] (64-bit runtime)
Python platform: Darwin-21.5.0-x86_64-i386-64bit
Is CUDA available: N/A
CUDA runtime version: Could not collect
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

Versions of relevant libraries:
[pip3] No relevant packages
[conda] blas                      1.0                         mkl  
[conda] mkl                       2021.2.0           hecd8cb5_269  
[conda] mkl-include               2022.0.0           hecd8cb5_105  
[conda] mkl-service               2.4.0            py38h9ed2024_0  
[conda] mkl_fft                   1.3.0            py38h4a7008c_2  
[conda] mkl_random                1.2.2            py38hb2f4e1b_0  
[conda] numpy                     1.20.0                   pypi_0    pypi
[conda] numpy-base                1.20.2           py38he0bd621_0  
[conda] numpydoc                  1.4.0            py38hecd8cb5_0  
[conda] pytorch                   1.13.0.dev20220728         py3.8_0    pytorch-nightly
[conda] torch                     1.11.0                   pypi_0    pypi
[conda] torchaudio                0.13.0.dev20220728        py38_cpu    pytorch-nightly
[conda] torchvision               0.13.0                   pypi_0    pypi

Another way to trigger it is just run:
```
python3 test/mobile/model_test/gen_test_model.py dynamic_quant_ops
```
in the latest nightly build.

cc @jerryzh168 @jianyuh @raghuramank100 @jamesr66a @vkuzo @jgong5 @Xia-Weiwen @leslie-fang-intel