MayBe There is a bug with class DebertaV2PredictionHeadTransform
Author: startnew
Pull request: no

I got an **error** like this:
`RuntimeError: mat1 dim 1 must match mat2 dim` when Use official Debertav2 mlm . 
## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->

- `transformers` version:4.5.0.dev0
- Platform: Ubuntu 18.04.3 LTS
- Python version: 3.6
- PyTorch version (GPU?):   1.7.1+cu101
- Tensorflow version (GPU?):
- Using GPU in script?:yes
- Using distributed or parallel set-up in script?: NO

### Who can help
@LysandreJik @sgugger  @patrickvonplaten 



## Information

Model I am using DebertaV2 For MLM :

The problem arises when code  using :
* [ ] the official example scripts: [transformers/models/deberta_v2/modeling_deberta_v2.py](https://github.com/huggingface/transformers/blob/9f72e8f4e1e767c5f608dd135199e592255b8a69/src/transformers/models/deberta_v2/modeling_deberta_v2.py#L1178) line at 1178 to 1213
* [x] official scripts  like This:
```python
# copied from transformers.models.bert.BertPredictionHeadTransform with bert -> deberta
class DebertaV2PredictionHeadTransform(nn.Module):
    def __init__(self, config):
        super().__init__()
        self.dense = nn.Linear(config.hidden_size, config.hidden_size)
        if isinstance(config.hidden_act, str):
            self.transform_act_fn = ACT2FN[config.hidden_act]
        else:
            self.transform_act_fn = config.hidden_act
        self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)

    def forward(self, hidden_states):
        hidden_states = self.dense(hidden_states)
        hidden_states = self.transform_act_fn(hidden_states)
        hidden_states = self.LayerNorm(hidden_states)
        return hidden_states


# copied from transformers.models.bert.BertLMPredictionHead with bert -> deberta
class DebertaV2LMPredictionHead(nn.Module):
    def __init__(self, config):
        super().__init__()
        self.transform = DebertaV2PredictionHeadTransform(config)

        # The output weights are the same as the input embeddings, but there is
        # an output-only bias for each token.
        self.decoder = nn.Linear(config.hidden_size, config.vocab_size, bias=False)

        self.bias = nn.Parameter(torch.zeros(config.vocab_size))

        # Need a link between the two variables so that the bias is correctly resized with `resize_token_embeddings`
        self.decoder.bias = self.bias

    def forward(self, hidden_states):
        hidden_states = self.transform(hidden_states)
        hidden_states = self.decoder(hidden_states)
        return hidden_states
```


I got an **error** like this:
`RuntimeError: mat1 dim 1 must match mat2 dim`

> Traceback (most recent call last):
  File "train_pre_model.py", line 257, in <module>
    trainer.train(resume_from_checkpoint=last_checkpoint)
  File "/usr/local/lib/python3.6/dist-packages/transformers/trainer.py", line 1120, in train
    tr_loss += self.training_step(model, inputs)
  File "/usr/local/lib/python3.6/dist-packages/transformers/trainer.py", line 1524, in training_step
    loss = self.compute_loss(model, inputs)
  File "/usr/local/lib/python3.6/dist-packages/transformers/trainer.py", line 1556, in compute_loss
    outputs = model(**inputs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/parallel/data_parallel.py", line 161, in forward
    outputs = self.parallel_apply(replicas, inputs, kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/parallel/data_parallel.py", line 171, in parallel_apply
    return parallel_apply(replicas, inputs, kwargs, self.device_ids[:len(replicas)])
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/parallel/parallel_apply.py", line 86, in parallel_apply
    output.reraise()
  File "/usr/local/lib/python3.6/dist-packages/torch/_utils.py", line 428, in reraise
    raise self.exc_type(msg)
RuntimeError: Caught RuntimeError in replica 0 on device 0.
Original Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/parallel/parallel_apply.py", line 61, in _worker
    output = module(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/transformers/models/deberta_v2/modeling_deberta_v2.py", line 1159, in forward
    prediction_scores = self.cls(sequence_output)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/transformers/models/deberta_v2/modeling_deberta_v2.py", line 1224, in forward
    prediction_scores = self.predictions(sequence_output)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/transformers/models/deberta_v2/modeling_deberta_v2.py", line 1213, in forward
    hidden_states = self.decoder(hidden_states)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/linear.py", line 93, in forward
    return F.linear(input, self.weight, self.bias)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py", line 1692, in linear
    output = input.matmul(weight.t())
RuntimeError: mat1 dim 1 must match mat2 dim 0


* [ ] my own modified scripts:
* when I refer from https://github.com/microsoft/DeBERTa/blob/master/DeBERTa/deberta/mlm.py ,change [transformers/models/deberta_v2/modeling_deberta_v2.py] TO 
```python
class DebertaV2PredictionHeadTransform(nn.Module):
    def __init__(self, config):
        super().__init__()
        self.dense = nn.Linear(config.hidden_size, config.embedding_size)
        if isinstance(config.hidden_act, str):
            self.transform_act_fn = ACT2FN[config.hidden_act]
        else:
            self.transform_act_fn = config.hidden_act
        self.LayerNorm = nn.LayerNorm(config.embedding_size, eps=config.layer_norm_eps)

    def forward(self, hidden_states):
        hidden_states = self.dense(hidden_states)
        hidden_states = self.transform_act_fn(hidden_states)
        hidden_states = self.LayerNorm(hidden_states)
        return hidden_states


# copied from transformers.models.bert.BertLMPredictionHead with bert -> deberta
class DebertaV2LMPredictionHead(nn.Module):
    def __init__(self, config):
        super().__init__()
        self.transform = DebertaV2PredictionHeadTransform(config)

        # The output weights are the same as the input embeddings, but there is
        # an output-only bias for each token.
        self.decoder = nn.Linear(config.embedding_size, config.vocab_size, bias=False)

        self.bias = nn.Parameter(torch.zeros(config.vocab_size))

        # Need a link between the two variables so that the bias is correctly resized with `resize_token_embeddings`
        self.decoder.bias = self.bias

    def forward(self, hidden_states):
        hidden_states = self.transform(hidden_states)
        #print(hidden_states.size())
        #print(self.decoder)
        hidden_states = self.decoder(hidden_states)
        return hidden_states
```
The code it  can works well,but I can't undestand why it can work when the official can not 


Comments:
Hey @startnew,

Sorry could you add some code that we could copy-paste into a terminal to reproduce the error? :-) I don't quite follow here - is it the official code (in `src/transformes`) that doesn't work or specific adapted code?

Thank you for your reply, @patrickvonplaten , you can reproduce the error I encountered by opening the colab link below
[https://colab.research.google.com/drive/1DiMkU0lEeZqj2AT9DrafP_X-PDZMzxuK#scrollTo=GeOz-1Ix-5HE](https://colab.research.google.com/drive/1DiMkU0lEeZqj2AT9DrafP_X-PDZMzxuK#scrollTo=GeOz-1Ix-5HE)

refer from offical config ,the difference is I give an custum "embedding_size"  and the "embeddding_size" is not equal to "hidden_size",the official use "hidden_size” as "embedding_size", I guess this is the cause of the error

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.

Hey @startnew,

It's sadly a bit too time consuming to dive into another repo - could you maybe post a short code snippet that shows your error without using any external github repos or code? 

Usually, you should be able to customize the `"embedding_size"` configuration parameter