Using Model2Model with Albert
Author: mcemilg
Pull request: no
Labels: name: wontfix

Hi,

I am trying to use Albert model with Model2Model helper to build encoder decoder model. But it seems some variables missing in Albert implementation for language model fine tuning. I thought I could use the Albert just as I did with Bert.

Here is my script converted from `Model2Model` quickstart for Albert.

```python
lm_labels =  encoded_sentence2
labels_tensor = torch.tensor([lm_labels])

# Load pre-trained model (weights)
model = Model2Model.from_pretrained('albert-base-v2')

model.eval()
with torch.no_grad():
    outputs = model(sentence1_tensor, sentence2_tensor, decoder_lm_labels=labels_tensor)
    lm_loss = outputs[0]
```

Here is the error I encountered:

```python
~/venv/komun/lib/python3.6/site-packages/transformers/modeling_encoder_decoder.py in forward(self, encoder_input_ids, decoder_input_ids, **kwargs)
    229             "attention_mask", None
    230         )
--> 231         decoder_outputs = self.decoder(decoder_input_ids, **kwargs_decoder)
    232 
    233         return decoder_outputs + encoder_outputs

~/venv/komun/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    539             result = self._slow_forward(*input, **kwargs)
    540         else:
--> 541             result = self.forward(*input, **kwargs)
    542         for hook in self._forward_hooks.values():
    543             hook_result = hook(self, input, result)

TypeError: forward() got an unexpected keyword argument 'lm_labels'
```

So it seems the Albert doesn't have lm_labels argument. Is there any way to make it work `Model2Model` with Albert?

Or If I implement this code snippet (got from `BertForMaskedLM.forward`) to Albert can it be work?

```python
if lm_labels is not None:
        # we are doing next-token prediction; shift prediction scores and input ids by one
        prediction_scores = prediction_scores[:, :-1, :].contiguous()
        lm_labels = lm_labels[:, 1:].contiguous()
        loss_fct = CrossEntropyLoss()
        ltr_lm_loss = loss_fct(prediction_scores.view(-1, self.config.vocab_size), lm_labels.view(-1))
        outputs = (ltr_lm_loss,) + outputs
```

Edit: I add the above code snippet to `Albert.forward` it passed the current exception but code there are more issues because Bert models encoder has encoder specific arguments like `encoder_attention_mask` additional to `attention_mask`. But Albert's encoder has just `attention_mask`. I don't have deep knowledge about Albert specifically but is this just an implementation difference or the Albert's encoder does not get same inputs with Bert?

## Environment

* OS: Ubuntu 18.04.03 TLS
* PyTorch Transformers version (or branch): 2.3.0

Comments:
I met the same problem when I use `T5Model`. I think it could be some minor error in the source code.

I think it's not a minor error, at least in my case. It seems `Albert` does not support language model fine tuning and `Albert` did not have same API with `Bert`. 

I found this problem in `T5` model and I solve it. Please refer to #2525 if it helps.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.