Repository: pytorch
Issue: Doesn't work when register hook to torch.nn.MultiheadAttention.out_proj
Labels: triaged

### 🐛 Describe the bug

I am not sure whether this issue should be a bug or a new feature reques. The problem is: when you register a hook to out_proj under MultiheadAttention, it will never be called. Which may cause some abnormal behaviors when use tools implemented with hook, e.g. torch.nn.utils.prune (#69353). 

And this is because when you forward a MultiheadAttention, it directly call the out_proj.weight without forwarding it in torch._native_multi_head_attention or F.multi_head_attention_forward. (see [#L1113](https://github.com/pytorch/pytorch/blob/cac16e2ee293964033dffa6616f78b68603cd565/torch/nn/modules/activation.py#L1113), [#L1142](https://github.com/pytorch/pytorch/blob/cac16e2ee293964033dffa6616f78b68603cd565/torch/nn/modules/activation.py#L1142), and [#L1153](https://github.com/pytorch/pytorch/blob/cac16e2ee293964033dffa6616f78b68603cd565/torch/nn/modules/activation.py#L1153)) To maintain the consistency of hook behaviors, I suggest call those hooks at some proper places, maybe pass into F.multi_head_attention_forward?

Thanks!

### To Reproduce

```python
import torch
import torch.nn as nn
from functools import partial

test = {}

def hook(name, module, inputs):
    global test
    test[name] = test.get(name, 0) + 1

class net(nn.Module):
    def __init__(self):
        super().__init__()
        self.attn = nn.MultiheadAttention(100,2)
        self.proj = nn.Linear(100, 10)
        # register hook
        self.attn.register_forward_pre_hook(partial(hook, "attn"))
        self.attn.out_proj.register_forward_pre_hook(partial(hook, "attn.out_proj"))
        self.proj.register_forward_pre_hook(partial(hook, "proj"))

    def forward(self, x):
        attn_output, _ = self.attn(x, x, x)
        logits = self.proj(attn_output)
        return logits

model = net().eval()
x = torch.randn((16, 50, 100))
logits = model(x)

print(test)
```

### Expected behavior
```bash
{'attn': 1, 'attn_out': 1, 'proj': 1}
```

### Real behavior
```bash
{'attn': 1, 'proj': 1}
```


### Versions

Collecting environment information...
PyTorch version: 1.9.1+cu111
Is debug build: False
CUDA used to build PyTorch: 11.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.4 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.31

Python version: 3.8.11 (default, Aug  3 2021, 15:09:35)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.4.0-110-generic-x86_64-with-glibc2.17
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1080
Nvidia driver version: 470.129.06
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.20.3
[pip3] pytorch-lightning==1.5.9
[pip3] pytorch-ranger==0.1.1
[pip3] torch==1.9.1+cu111
[pip3] torch-optimizer==0.3.0
[pip3] torch-stoi==0.1.2
[pip3] torch-tb-profiler==0.2.1
[pip3] torchaudio==0.9.1
[pip3] torchmetrics==0.7.0
[pip3] torchvision==0.10.1+cu111
[conda] cudatoolkit               10.2.89              hfd86e86_1    defaults
[conda] numpy                     1.20.3           py38h9894fe3_1    conda-forge
[conda] pytorch-lightning         1.5.9                    pypi_0    pypi
[conda] pytorch-qrnn              0.2.1                    pypi_0    pypi
[conda] pytorch-ranger            0.1.1                    pypi_0    pypi
[conda] torch                     1.9.1+cu111              pypi_0    pypi
[conda] torch-optimizer           0.3.0                    pypi_0    pypi
[conda] torch-stoi                0.1.2                    pypi_0    pypi
[conda] torch-tb-profiler         0.2.1                    pypi_0    pypi
[conda] torchaudio                0.9.1                    pypi_0    pypi
[conda] torchmetrics              0.7.0                    pypi_0    pypi
[conda] torchvision               0.10.1+cu111             pypi_0    pypi

cc @jbschlosser @bhosmer @cpuhrsch