RuntimeError: Error while creating shape using tf-xlm-roberta-large

I get the following runtime error after the 2nd fold.

this is my model:
maxlen = 50
`with strategy.scope():
        #bert_encoder = TFBertModel.from_pretrained(model_name)
        base_model = TFAutoModel.from_pretrained(model_name)
        input_word_ids = tf.keras.Input(shape = (maxlen, ), dtype = tf.int32, name = "input_word_ids")
        input_mask = tf.keras.Input(shape = (maxlen, ), dtype = tf.int32, name = "input_mask")
        input_type_ids = tf.keras.Input(shape = (maxlen, ), dtype = tf.int32, name = "input_type_ids")

        embedding = base_model([input_word_ids, input_mask, input_type_ids])[0]
        output = tf.keras.layers.Dense(3, activation = 'softmax')(embedding[:, 0, :])

        model = tf.keras.Model(inputs = [input_word_ids, input_mask, input_type_ids], outputs = output)
        model.compile(tf.keras.optimizers.Adam(lr = 1e-5), loss = 'sparse_categorical_crossentropy', metrics = ['accuracy'])

`
And the traceback below:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-27-a45ce90453f2> in <module>
     22
     23     K.clear_session()
---> 24     model = build_model(maxlen, model_name)
     25     checkpoint = tf.keras.callbacks.ModelCheckpoint(
     26                 'XLMRoberta_fold-%i.h5'%fold, monitor = 'val_loss', verbose = 1, save_best_only = True,

<ipython-input-23-9faa2e5f1d9b> in build_model(maxlen, model_name)
      2     with strategy.scope():
      3         #bert_encoder = TFBertModel.from_pretrained(model_name)
----> 4         base_model = TFAutoModel.from_pretrained(model_name)
      5         input_word_ids = tf.keras.Input(shape = (maxlen, ), dtype = tf.int32, name = "input_word_ids")
      6         input_mask = tf.keras.Input(shape = (maxlen, ), dtype = tf.int32, name = "input_mask")

/opt/conda/lib/python3.7/site-packages/transformers/modeling_tf_auto.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    421         for config_class, model_class in TF_MODEL_MAPPING.items():
    422             if isinstance(config, config_class):
--> 423                 return model_class.from_pretrained(pretrained_model_name_or_path, *model_args, config=config, **kwargs)
    424         raise ValueError(
    425             "Unrecognized configuration class {} for this kind of TFAutoModel: {}.\n"

/opt/conda/lib/python3.7/site-packages/transformers/modeling_tf_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    482             return load_pytorch_checkpoint_in_tf2_model(model, resolved_archive_file, allow_missing_keys=True)
    483
--> 484         model(model.dummy_inputs, training=False)  # build the network with dummy inputs
    485
    486         assert os.path.isfile(resolved_archive_file), "Error retrieving file {}".format(resolved_archive_file)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
    966           with base_layer_utils.autocast_context_manager(
    967               self._compute_dtype):
--> 968             outputs = self.call(cast_inputs, *args, **kwargs)
    969           self._handle_activity_regularization(inputs, outputs)
    970           self._set_mask_metadata(inputs, outputs, input_masks)

/opt/conda/lib/python3.7/site-packages/transformers/modeling_tf_roberta.py in call(self, inputs, **kwargs)
    229             heads.
    230         """
--> 231         outputs = self.roberta(inputs, **kwargs)
    232         return outputs
    233

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
    966           with base_layer_utils.autocast_context_manager(
    967               self._compute_dtype):
--> 968             outputs = self.call(cast_inputs, *args, **kwargs)
    969           self._handle_activity_regularization(inputs, outputs)
    970           self._set_mask_metadata(inputs, outputs, input_masks)

/opt/conda/lib/python3.7/site-packages/transformers/modeling_tf_bert.py in call(self, inputs, attention_mask, token_type_ids, position_ids, head_mask, inputs_embeds, output_attentions, output_hidden_states, training)
    604             # head_mask = tf.constant([0] * self.num_hidden_layers)
    605
--> 606         embedding_output = self.embeddings([input_ids, position_ids, token_type_ids, inputs_embeds], training=training)
    607         encoder_outputs = self.encoder(
    608             [embedding_output, extended_attention_mask, head_mask, output_attentions, output_hidden_states],

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
    962         # Eager execution on data tensors.
    963         with backend.name_scope(self._name_scope()):
--> 964           self._maybe_build(inputs)
    965           cast_inputs = self._maybe_cast_inputs(inputs)
    966           with base_layer_utils.autocast_context_manager(

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _maybe_build(self, inputs)
   2414         # operations.
   2415         with tf_utils.maybe_init_scope(self):
-> 2416           self.build(input_shapes)  # pylint:disable=not-callable
   2417       # We must set also ensure that the layer is marked as built, and the build
   2418       # shape is stored since user defined build functions may not be calling

/opt/conda/lib/python3.7/site-packages/transformers/modeling_tf_bert.py in build(self, input_shape)
    144                 "weight",
    145                 shape=[self.vocab_size, self.hidden_size],
--> 146                 initializer=get_initializer(self.initializer_range),
    147             )
    148         super().build(input_shape)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in add_weight(self, name, shape, dtype, initializer, regularizer, trainable, constraint, partitioner, use_resource, synchronization, aggregation, **kwargs)
    575         synchronization=synchronization,
    576         aggregation=aggregation,
--> 577         caching_device=caching_device)
    578     if regularizer is not None:
    579       # TODO(fchollet): in the future, this should be handled at the

/opt/conda/lib/python3.7/site-packages/tensorflow/python/training/tracking/base.py in _add_variable_with_custom_getter(self, name, shape, dtype, initializer, getter, overwrite, **kwargs_for_getter)
    741         dtype=dtype,
    742         initializer=initializer,
--> 743         **kwargs_for_getter)
    744
    745     # If we set an initializer and the variable processed it, tracking will not

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer_utils.py in make_variable(name, shape, dtype, initializer, trainable, caching_device, validate_shape, constraint, use_resource, collections, synchronization, aggregation, partitioner)
    139       synchronization=synchronization,
    140       aggregation=aggregation,
--> 141       shape=variable_shape if variable_shape else None)
    142
    143

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/variables.py in __call__(cls, *args, **kwargs)
    257   def __call__(cls, *args, **kwargs):
    258     if cls is VariableV1:
--> 259       return cls._variable_v1_call(*args, **kwargs)
    260     elif cls is Variable:
    261       return cls._variable_v2_call(*args, **kwargs)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/variables.py in _variable_v1_call(cls, initial_value, trainable, collections, validate_shape, caching_device, name, variable_def, dtype, expected_shape, import_scope, constraint, use_resource, synchronization, aggregation, shape)
    218         synchronization=synchronization,
    219         aggregation=aggregation,
--> 220         shape=shape)
    221
    222   def _variable_v2_call(cls,

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/variables.py in getter(**kwargs)
     64
     65   def getter(**kwargs):
---> 66     return captured_getter(captured_previous, **kwargs)
     67
     68   return getter

/opt/conda/lib/python3.7/site-packages/tensorflow/python/distribute/distribute_lib.py in creator_with_resource_vars(next_creator, **kwargs)
   1765         kwargs["initial_value"] = kwargs["initial_value"].wrapped_value
   1766
-> 1767       return self._create_variable(next_creator, **kwargs)
   1768
   1769     def distributed_getter(getter, *args, **kwargs):

/opt/conda/lib/python3.7/site-packages/tensorflow/python/distribute/tpu_strategy.py in _create_variable(self, next_creator, **kwargs)
    670                                            tpu_values.TPUMirroredVariable,
    671                                            tpu_values.TPUSyncOnReadVariable,
--> 672                                            **kwargs)
    673
    674   def _reduce_to(self, reduce_op, value, destinations, experimental_hints):

/opt/conda/lib/python3.7/site-packages/tensorflow/python/distribute/values.py in create_mirrored_variable(strategy, real_mirrored_creator, mirrored_cls, sync_on_read_cls, **kwargs)
    692   # here.
    693   with tape.stop_recording():
--> 694     value_list = real_mirrored_creator(**kwargs)
    695     var_cls = sync_on_read_cls if is_sync_on_read else mirrored_cls
    696     result = var_cls(strategy, value_list, aggregation)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/distribute/tpu_strategy.py in _real_mirrored_creator(**kwargs)
    660
    661           with context.device_policy(context.DEVICE_PLACEMENT_SILENT):
--> 662             v = next_creator(**kwargs)
    663
    664           assert not isinstance(v, tpu_values.TPUMirroredVariable)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/variables.py in <lambda>(**kwargs)
    196                         shape=None):
    197     """Call on Variable class. Useful to force the signature."""
--> 198     previous_getter = lambda **kwargs: default_variable_creator(None, **kwargs)
    199     for _, getter in ops.get_default_graph()._variable_creator_stack:  # pylint: disable=protected-access
    200       previous_getter = _make_getter(getter, previous_getter)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/variable_scope.py in default_variable_creator(next_creator, **kwargs)
   2596         synchronization=synchronization,
   2597         aggregation=aggregation,
-> 2598         shape=shape)
   2599   else:
   2600     return variables.RefVariable(

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/variables.py in __call__(cls, *args, **kwargs)
    261       return cls._variable_v2_call(*args, **kwargs)
    262     else:
--> 263       return super(VariableMetaclass, cls).__call__(*args, **kwargs)
    264
    265

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/resource_variable_ops.py in __init__(self, initial_value, trainable, collections, validate_shape, caching_device, name, dtype, variable_def, import_scope, constraint, distribute_strategy, synchronization, aggregation, shape)
   1432           aggregation=aggregation,
   1433           shape=shape,
-> 1434           distribute_strategy=distribute_strategy)
   1435
   1436   def _init_from_args(self,

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/resource_variable_ops.py in _init_from_args(self, initial_value, trainable, collections, caching_device, name, dtype, constraint, synchronization, aggregation, distribute_strategy, shape)
   1568                 name="initial_value", dtype=dtype)
   1569           if shape is not None:
-> 1570             if not initial_value.shape.is_compatible_with(shape):
   1571               raise ValueError(
1572                   "The initial value's shape (%s) is not compatible with "

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in shape(self)
   1063         # `_tensor_shape` is declared and defined in the definition of
   1064         # `EagerTensor`, in C.
-> 1065         self._tensor_shape = tensor_shape.TensorShape(self._shape_tuple())
   1066       except core._NotOkStatusException as e:
   1067         six.raise_from(core._status_to_exception(e.code, e.message), None)

RuntimeError: Error while creating shape


[s2s] wmt download script use less ram

a few enhancement to https://github.com/huggingface/transformers/pull/6403

the main change:
- rewrite not to load 100GB into RAM - wmt19 is huge!

and then a few small things:
- replaced the default dataset to wmt16 as it's much much smaller than wmt19 to experiment with (also it seems that at least wmt19-ru-en is missing a test dataset, while wmt16-run-en has it)
- added lang defaults so it's easy to start experimenting with
- moved tqdm to where a detailed progress can be seen
- added some extra notes

@sshleifer


[lightning_base] fix s2s logging, only make train_loader once

setup is called many times (incl twice by trainer.test), creating a dataloader each time. Will only creating a train_loader on the first call cause bad side effects that I don't understand @nateraw @williamFalcon ?

I read docs [https://pytorch-lightning.readthedocs.io/en/latest/introduction_guide.html], so I think I'm fine, but not sure.

cc @stas00

Also:
- add a fast test for run_ner
- [pl] centralize `data_dir` argument to `add_generic_args` cause rule of 3

Checks:
- verified xsum distillation trains well, has good LR logs. (warmup+linear decay are honored.)


[s2s] Script to save wmt data to disk


remove lr_scheduler redundancy

This PR solves https://github.com/huggingface/transformers/issues/6374
by removing a hardcoded `lr_scheduler` and switching to using the new method.


[TF Longformer] Add Multiple Choice, Seq Classification Model

# 🚀 Feature request

`modeling_longformer.py` has the classes `LongformerForSequenceClassification`, `LongformerForMultipleChoice` and `LongformerForTokenClassification` which are not present  in `modeling_tf_longformer.py` at the moment.
Those classes should be equally added to `modeling_tf_longformer.py`.

## Motivation

The pretrained weights for TFLongformer are available so that these classes could be used for finetuning.

## Your contribution

This issue is a good first issue because it is not too complicated to add these models. One should take a look at `modeling_tf_roberta.py` to see how these models are implemented for `TFRoberta` and implement them analogous for `TFLongformer`. Please make sure that the docstring is correct and that test are added for each class (again Roberta can serve as an example here, check out `test_modeling_tf_roberta.py`).

I am happy to guide interested community contributors through the PR and help them get it merged.


ZeroDivisionError with Reformer

## 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: 3.0.0
- Platform: Linux-5.4.0-42-generic-x86_64-with-Ubuntu-18.04-bionic
- Python version: 3.6.9
- PyTorch version (GPU?): 1.6.0 (True)
- Tensorflow version (GPU?): not installed (NA)
- Using GPU in script?: Yes
- Using distributed or parallel set-up in script?: No

## Information

Model I am using (Bert, XLNet ...): **Reformer**

The problem arises when using:
* [ ] the official example scripts: (give details below)
* [X] my own modified scripts: (give details below) (well, actually, not my own, but @patrickvonplaten 's)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [x] my own task or dataset: (give details below)

## To reproduce

Steps to reproduce the behavior:

1. Execute @patrickvonplaten 's notebook available at https://colab.research.google.com/github/patrickvonplaten/notebooks/blob/master/Reformer_For_Masked_LM.ipynb
2. I've tried to run it on google colab and works fine. The problem appears when I try to run on my machine.
3. I've tried it with two different clean virtual environments (python 3.6 and 3.7), but they've both failed.
4. I haven't change the dataset, nor any model config/training args.
4. After calling trainer.train() I get the following error

```
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-13-02431faf649a> in <module>
      8
      9 # train
---> 10 trainer.train()

/data/venv36/lib/python3.6/site-packages/transformers/trainer.py in train(self, model_path)
    394             t_total = self.args.max_steps
    395             num_train_epochs = (
--> 396                 self.args.max_steps // (len(train_dataloader) // self.args.gradient_accumulation_steps) + 1
    397             )
    398         else:

ZeroDivisionError: integer division or modulo by zero

```
## Expected behavior

The model should begin to train

Thanks!


DPR retriever module

I see https://github.com/huggingface/transformers/pull/5279 that describes the DPR flow.

Just checking to see when the retriever module will be available.
Many thanks for making DPR available !


Data collator with padding

Add a data collator to dynamically pad samples during batching. This is necessary for the training set since padding can't be applied beforehand if we use shuffling (unless with pad to a fixed `max_length`).
This should make it more straightforward to plug nlp into the Trainer.


Create README.md

model card

Related to pretrained model cards

For GPT-2 Arabic Poetry - https://huggingface.co/akhooli/gpt2-small-arabic-poetry


switch Hindi-BERT to S3 README

Related to pretrained model cards

The Markdown parser currently cuts off the CoLab URL (the last char is an underscore) on https://huggingface.co/monsoon-nlp/hindi-bert

There are some other necessary updates, and I'd rather update this model card by pushing to S3 in the future


Bug in the question answering pipeline

## 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: 3.0.2
- Platform: Linux-4.19.112+-x86_64-with-Ubuntu-18.04-bionic
- Python version: 3.6.9
- PyTorch version (GPU?): 1.6.0+cu101 (False)
- Tensorflow version (GPU?): 2.3.0 (False)
- Using GPU in script?: no
- Using distributed or parallel set-up in script?: no

## Information
The bug appears since transformers 3.0.1 but not before.

Model I am using distilbert-base-cased-distilled-squad:

The problem arises when using:
* [ ] my own modified scripts:
```

from transformers import pipeline
model = "distilbert-base-cased-distilled-squad"
qa_pipeline = pipeline(
    "question-answering",
    model=model,
    tokenizer=model,
)

instance = {
  "question": "what is your product?",
  "context": " is an amazing new platform that help businesses of students from BarIlan University that are enthusiastic about conversational AI. The difference between our Sprybot platform and other chat bots is that constructing chat bot is a long and hard process and with Sprybot you can do it quickly and eaily. You can construct chatbot using our platform just by feeding textual description of you business that contain any details important for costumers. The time it takes to create a bot using our platform is the time takes you to describe your business. In order to create Sprybot we used natural language processing and state of the art deep learning artificial intelligence. At the moment you cant buy our product because its still under construction. Sprybot can answer questions about your business but it can not talk about anything else other than the information was fed to it."
}
qa_pipeline(instance)

```

Notice: little changes in the context text make the bug to not show up
## To reproduce

Steps to reproduce the behavior:

1. [fully reproduced on google colab](https://colab.research.google.com/drive/1YqamXA6qq8xxWXhq6VqEA9clHsEVW7sh?usp=sharing)

```
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-5-a5f26c48556d> in <module>()
      4 }
      5
----> 6 qa_pipeline(instance)

1 frames
/usr/local/lib/python3.6/dist-packages/transformers/pipelines.py in __call__(self, *args, **kwargs)
   1314                         ),
   1315                     }
-> 1316                     for s, e, score in zip(starts, ends, scores)
   1317                 ]
   1318

/usr/local/lib/python3.6/dist-packages/transformers/pipelines.py in <listcomp>(.0)
   1314                         ),
   1315                     }
-> 1316                     for s, e, score in zip(starts, ends, scores)
   1317                 ]
   1318

KeyError: 0
```

## Expected behavior

get the qa pipline output with no errors


Error while loading albert for token classification

## Environment info
- `transformers` version: 3.0.2
- Platform: Windows-10-10.0.18362-SP0
- Python version: 3.6.10
- PyTorch version (GPU?): not installed (NA)
- Tensorflow version (GPU?): 2.2.0 (False)
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

### Who can help
@LysandreJik
@jplu

## Information

Model I am using albert-base-v2 or albert-base-v1:

The tasks I am working on is:
token classification using albert-base-v2 or v1

## To reproduce
```

>>> from transformers import AlbertTokenizer, TFAlbertForTokenClassification
>>> import tensorflow as tf

>>> tokenizer = AlbertTokenizer.from_pretrained('albert-base-v2', cache_dir = 'cache')
>>> model = TFAlbertForTokenClassification.from_pretrained('albert-base-v2', cache_dir = 'cache')
```

When I run above script I get error:

```

Traceback (most recent call last):
  File "C:\Users\703235761\AppData\Local\Continuum\anaconda3\envs\slot\lib\site-packages\transformers\modeling_tf_utils.py", line 581, in from_pretrained
    raise EnvironmentError
OSError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "model_utils.py", line 7, in <module>
    model = TFAlbertForTokenClassification.from_pretrained('albert-base-v1', cache_dir = 'cache')
  File "C:\Users\703235761\AppData\Local\Continuum\anaconda3\envs\slot\lib\site-packages\transformers\modeling_tf_utils.py", line 588, in from_pretrained
    raise EnvironmentError(msg)
OSError: Can't load weights for 'albert-base-v1'. Make sure that:

- 'albert-base-v1' is a correct model identifier listed on 'https://huggingface.co/models'

- or 'albert-base-v1' is the correct path to a directory containing a file named one of tf_model.h5, pytorch_model.bin.
```

## Expected behavior

I think this model was supposed to work with TFAlbertModel as well.
Thanks in advance! :-)


Add missing docker arg for TPU CI.

Fixes `"docker build" requires exactly 1 argument.` for the path where `$CIRCLE_PR_NUMBER` is unset.


seq2seq examples require pytest

## 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: 3.0.2
- Platform: Linux-5.4.0-42-generic-x86_64-with-glibc2.29
- Python version: 3.8.2
- PyTorch version (GPU?): 1.6.0 (True)
- Tensorflow version (GPU?): not installed (NA)
- Using GPU in script?: n/a
- Using distributed or parallel set-up in script?: n/a

### Who can help
 examples/seq2seq: @sshleifer
documentation: @sgugger

## To reproduce

Steps to reproduce the behavior:

1. Create a new virtual environment and set it up to run the examples tests. Do _not_ install `pytest` and `pytest-xdist`.
2. Run the tests with `unittest` as [described in the docs](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md#tests)

## Expected behavior
The examples tests pass. Actual behavior:

```sh
======================================================================
ERROR: seq2seq.test_bash_script (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: seq2seq.test_bash_script
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/dmlap/projects/transformers/examples/seq2seq/test_bash_script.py", line 8, in <module>
    import pytest
ModuleNotFoundError: No module named 'pytest'

======================================================================
ERROR: seq2seq.test_seq2seq_examples (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: seq2seq.test_seq2seq_examples
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/dmlap/projects/transformers/examples/seq2seq/test_seq2seq_examples.py", line 10, in <module>
    import pytest
ModuleNotFoundError: No module named 'pytest'

----------------------------------------------------------------------
Ran 16 tests in 179.454s

FAILED (errors=2)
```

Perhaps the documentation should be updated to require `pytest`?


Fix links for open in colab

This commit was supposed to be in #6389 but I didn't push hard enough.


Warn if debug requested without TPU fixes (#6308)

Check whether a PyTorch compatible TPU is available before attempting to print TPU metrics after training has completed. This way, users who apply `--debug` without reading the documentation aren't suprised by a stacktrace.


Colab button

This PR adds a "open in colab" button on the tutorials of our documentation. For each of those tutorials, three notebooks are available: mixed version (with cells PyTorch and TensorFlow), PyTorch-only and TensorFlow only, so hovering on the button makes a dropdown appear with the three different links.

Those notebooks are generated automatically from the docs rst files and the script in the [notebooks repo](https://github.com/huggingface/notebooks/blob/master/utils/convert_doc_to_notebooks.py).


[T5 3B Covid 19] Adapt T5 TF conversion script to handle covid-19 3b t5

This PR shows which changes were necessary to convert the 3B (and 11B) T5 model from this issue: https://github.com/huggingface/transformers/tree/adapt_t5_for_covid_19_3b to PyTorch.

It might be possible that the official T5 library has changed in which case this code might be useful again.
For now, this PR stays a draft though, but can be cleaned and merged if more T5 Conversion issues arise.

Pinging @sshleifer @thomwolf for notification.


Fix docs and bad word tokens generation_utils.py

This PR fixes two issues:

1.
The codes
https://github.com/huggingface/transformers/blob/6028ed92bd9e5471e6f8a1d23cfd95a3a63018fb/src/transformers/generation_utils.py#L224-L228
throw an exception
`AssertionError: Greedy decoding will always produce the same output for num_beams == 1 and num_return_sequences > 1. Please set num_return_sequences = 1`

2.
The codes
```python
from transformers.generation_utils import calc_banned_bad_words_ids
prev_input_ids = torch.tensor([[1, 2, 3, 4, 5]])
bad_words_ids = [[4, 5, 9]]
banned_tokens = calc_banned_bad_words_ids(prev_input_ids, bad_words_ids)
print(banned_tokens)
```
output `[[]]`，but we expect to output  `[[9]]`.


Create README.md

Related to pretrained model cards


[POC] Notebooks cron

Setting up a cron job to create the notebooks on the documentation


AttributeError: type object "BartTokenizer" has no attribute 'name'

## 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: 3.0.2
- Platform: Google Colab
- Python version: 3.7
- PyTorch version (GPU?):
- Tensorflow version (GPU?):
- Using GPU in script?:  Yes
- Using distributed or parallel set-up in script?: don't know

### Who can help
<!-- Your issue will be replied to more quickly if you can figure out the right person to tag with @
 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

 albert, bert, GPT2, XLM: @LysandreJik
 tokenizers: @mfuntowicz
 Trainer: @sgugger
 Speed and Memory Benchmarks: @patrickvonplaten
 Model Cards: @julien-c
 Translation: @sshleifer
 Summarization: @sshleifer
 TextGeneration: @TevenLeScao
 examples/distillation: @VictorSanh
 nlp datasets: [different repo](https://github.com/huggingface/nlp)
 rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)
 Text Generation: @TevenLeScao
 blenderbot: @mariamabarham
 Bart: @sshleifer
 Marian: @sshleifer
 T5: @patrickvonplaten
 Longformer/Reformer: @patrickvonplaten
 TransfoXL/XLNet: @TevenLeScao
 examples/seq2seq: @sshleifer
 tensorflow: @jplu
documentation: @sgugger
 -->

## Information

Model I am using (Bert, XLNet ...):

The problem arises when using:
* [x] the official example scripts: (give details below)
* [ ] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [ ] my own task or dataset: (give details below)

## To reproduce

Steps to reproduce the behavior:

1. Using the script provided on Hugging face library
 : https://github.com/ohmeow/ohmeow_website/blob/master/_notebooks/2020-05-23-text-generation-with-blurr.ipynb

<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->

## Expected behavior

<!-- A clear and concise description of what you would expect to happen. -->


hi

## 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:
- Platform:
- Python version:
- PyTorch version (GPU?):
- Tensorflow version (GPU?):
- Using GPU in script?:
- Using distributed or parallel set-up in script?:

### Who can help
<!-- Your issue will be replied to more quickly if you can figure out the right person to tag with @
 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

 albert, bert, GPT2, XLM: @LysandreJik
 tokenizers: @mfuntowicz
 Trainer: @sgugger
 Speed and Memory Benchmarks: @patrickvonplaten
 Model Cards: @julien-c
 Translation: @sshleifer
 Summarization: @sshleifer
 TextGeneration: @TevenLeScao
 examples/distillation: @VictorSanh
 nlp datasets: [different repo](https://github.com/huggingface/nlp)
 rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)
 Text Generation: @TevenLeScao
 blenderbot: @mariamabarham
 Bart: @sshleifer
 Marian: @sshleifer
 T5: @patrickvonplaten
 Longformer/Reformer: @patrickvonplaten
 TransfoXL/XLNet: @TevenLeScao
 examples/seq2seq: @sshleifer
 tensorflow: @jplu
documentation: @sgugger
 -->

## Information

Model I am using (Bert, XLNet ...):

The problem arises when using:
* [ ] the official example scripts: (give details below)
* [ ] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [ ] my own task or dataset: (give details below)

## To reproduce

Steps to reproduce the behavior:

1.
2.
3.

<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->

## Expected behavior

<!-- A clear and concise description of what you would expect to happen. -->


Ci GitHub caching

Same as https://github.com/huggingface/transformers/pull/6287 but for Github Actions


Add metadata to be indexed properly

Related to pretrained model cards


Change metadata to be indexed correctly

Related to pretrained model cards


[EncoderDecoderModel] add a `add_cross_attention` boolean to config

The `EncoderDecoderModel` uses models from `AUTO_MODEL_FOR_CAUSAL_LM` as their decoder models. The problem is that these models can be used in two ways:

1) As a stand-alone decoder model (GPT2) like **without** cross-attention layers
2) As part of a `EncoderDecoderModel` **with** cross-attention layers.

Currently it is decided via the parameter `config.is_decoder` whether cross-attention layers should be added. The problem is that `config.is_decoder` is `True` for both 1) and 2), which is correct since both 1) and 2) should use a causal mask, but means that for 1) cross-attention layers are added without ever being used.

This PR solves this problem by introducing a new config param called `add_cross_attention` which is only relevant for models in `AUTO_MODEL_FOR_CAUSAL_LM`.

I also played around with the idea of not having the flag in the config, but just passing it along the `init` function, such as:
```python
        super().__init__(config, add_cross_attention=False)
```
in

and then calling setting this param to `True` for all encoder-decoder models. I decided to put the param in the config instead because:
a) The init signature does not have to change and
b) EncoderDecoderModels make extensive use of `AutoModelForCausalLM.from_pretrained(...)` which would have meant that all models that are part of `MODEL_FOR_CAUSAL_LM_MAPPING` have to have this signature.

Taking all this into account I think the first solution (putting `add_cross_attenion` into the config) is the better way to go here.

# IMPORTANT: This PR introduces a breaking change. All `EncoderDecoderModel` models have to be updated with `add_cross_attention=True`.
=> All "bert2bert" models were updated: https://huggingface.co/models?search=bert2bert

## TODO:
After this, I think the framework is flexible enough to handle all other models and I can extend `EncoderDecoderModel` to GPT2, Roberta, Longformer and maybe Reformer as well.
EncoderDecoder is not yet officially released, I think, so this slightly backwards compatibility breaking change is OK. I will updated all Bert2Bert models on the model hub with `add_cross_attention=True` and add a bigger message in this PR when merged.


Introduce dataset and data collator for Bert pretrain NSP

Follow up from discussion in https://github.com/huggingface/transformers/issues/6330

This PR introduces changes to allow both the LMML and NSP objectives to be run using ```BertForPretraining```.


CUDA Out of Memory

# ❓ Questions & Help

<!-- The GitHub issue tracker is primarly intended for bugs, feature requests,
     new models and benchmarks, and migration questions. For all other questions,
     we direct you to the Hugging Face forum: https://discuss.huggingface.co/ .
     You can also try Stack Overflow (SO) where a whole community of PyTorch and
     Tensorflow enthusiast can help you out. In this case, make sure to tag your
     question with the right deep learning framework as well as the
     huggingface-transformers tag:
     https://stackoverflow.com/questions/tagged/huggingface-transformers
     https://stackoverflow.com/questions/63335442/how-do-i-deal-with-cuda-out-of-memory-while-finetuning-bart
     -->

## Details
<!-- Description of your issue -->
I was trying to finetune BART on google collab using the xsum dataset and the finetuning script and I got this:
RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 14.73 GiB total capacity; 13.67 GiB already allocated; 15.88 MiB free; 13.72 GiB reserved in total by PyTorch)
Does this mean I have to use a smaller model?

<!-- You should first ask your question on the forum or SO, and only if
     you didn't get an answer ask it here on GitHub. -->
**A link to original question on the forum/Stack Overflow**:
https://stackoverflow.com/questions/63335442/how-do-i-deal-with-cuda-out-of-memory-while-finetuning-bart


[s2s] remove lr_scheduler redundancy

in `get_train_dataloader`


Pegasus finetuning diary

Best score so far .2065 Rouge, much worse than paper. Generations appear to start lower case/be missing words at the beginning.

Clues:
- adding `<pad>` as prefix (like for generation) makes loss nan for at least 1000 steps (I killed it).
- Without prefix, loss is nan for 5 steps, them improves.
- distillation with teacher produces huge hidden state MSE losses. This is probably unrelated and caused by the same large activations that break fp16.

Suspects:
- different causal mask than tf?
- tf doesn't shift labels or add a decoder prefix token. We shift labels but don't add a prefix token. there is a suraj issue where this appears to be suboptimal for t5 (which also has no bos token).
- bug in label smoothing

Best run:

![image](https://user-images.githubusercontent.com/6045025/89748679-5c7d0900-da92-11ea-9505-59ee413193d9.png)

![image](https://user-images.githubusercontent.com/6045025/89748681-5dae3600-da92-11ea-94bd-5043c586bd9c.png)


Update modeling_tf_utils.py

fix typo: ckeckpoint->checkpoint


the test now works again

`test_finetune_lr_shedulers` can now run after https://github.com/huggingface/transformers/pull/6358 was merged


FastTokenizer not returning batch_size for offset_mapping for short texts

## Environment info
- `transformers` version: 3.0.2
- Platform: Linux-5.4.0-42-generic-x86_64-with-glibc2.10
- Python version: 3.8.2
- PyTorch version (GPU?): 1.6.0 (True)
- Tensorflow version (GPU?): not installed (NA)
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

# Who can help
 tokenizers: @mfuntowicz

## Information
When working with `padding` and `truncation` on short texts (smaller than `max_len`),
the FastTokenizer will return the batch_size dimension if `return_tensors=None`.
However, when `return_tensors="pt"` or `return_tensors="np"` are enabled (I haven't tested it on Tensorflow), they **won't return the batch dimension**.

## To reproduce

Loading fast tokenizer:
```python3
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased", use_fast=True)
```

Behavior on "short" texts without `return_tensors`:
```python3

out = tokenizer("test text",
                padding='max_length',
                truncation=True,
                return_overflowing_tokens=True,
                return_offsets_mapping=True,
                )

# Convert to tensor outside the tokenizer
print(torch.tensor(out["offset_mapping"]).shape)
>>> torch.Size([1, 512, 2])
```

Behavior with `return_tensors`:
```python3

out = tokenizer("test text",
                padding='max_length',
                truncation=True,
                return_overflowing_tokens=True,
                return_offsets_mapping=True,
                return_tensors="pt"  # Similarly with "np"
                )

print(out["offset_mapping"].shape)
>>> torch.Size([512, 2])
```

## Expected behavior
```python3

out = tokenizer("test text",
                padding='max_length',
                truncation=True,
                return_overflowing_tokens=True,
                return_offsets_mapping=True,
                return_tensors="pt"
                )

print(out["offset_mapping"].shape)
>>> torch.Size([1, 512, 2])
```


trainer/lightning_base: Arbitrary config updates through command line

this issue [https://github.com/huggingface/transformers/issues/6367], and a recent one to add dropout to the command line, as well as the usage of task_specific_params during finetuning, are all one off solutions to address a larger problem. During finetuning/training, it is very difficult to arbitrarily set config attributes. For `examples/lightning_base.py`, you need to save a whole new config to json and put it in a directory, which is fairly annoying method for changing hyperparameters, so we add lots of them, like `--dropout --attention_dropout --encoder_layerdrop --decoder_layerdrop` through `argparse.add_argument`.
It would be a better user experience if I could just pass any kwarg without editing the code.

This seems possible with the `fire` package. But I would prefer an `argparse` solution as there is another issue open to delete the `fire` dependency, I also asked a similar question on
[stackoverflow](https://stackoverflow.com/questions/63329044/python-argparse-allow-unregistered-arguments)


Can't load a saved tokenizer with AutoTokenizer.from_pretrained without saving Config as well

### Environment info
- `transformers` version: master (https://github.com/huggingface/transformers/commit/6e8a38568eb874f31eb49c42285c3a634fca12e7)

### Who can help
 tokenizers: @mfuntowicz

### Information
When saving a tokenizer with .save_pretrained, it can be loaded with the class it was saved with but not with AutoTokenizer:
```
from transformers import BertTokenizer, AutoTokenizer
BertTokenizer.from_pretrained("bert-base-cased").save_pretrained(".")

BertTokenizer.from_pretrained(".") # works

AutoTokenizer.from_pretrained(".") # throws exception
```
The error is:
```
Traceback (most recent call last):
  File "/home/transformers/src/transformers/configuration_utils.py", line 333, in get_config_dict
    local_files_only=local_files_only,
  File "/home/transformers/src/transformers/file_utils.py", line 684, in cached_path
    raise EnvironmentError("file {} not found".format(url_or_filename))
OSError: file ./config.json not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/transformers/src/transformers/tokenization_auto.py", line 205, in from_pretrained
    config = AutoConfig.from_pretrained(pretrained_model_name_or_path, **kwargs)
  File "/home/transformers/src/transformers/configuration_auto.py", line 203, in from_pretrained
    config_dict, _ = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
  File "/home/transformers/src/transformers/configuration_utils.py", line 346, in get_config_dict
    raise EnvironmentError(msg)
OSError: Can't load config for '.'. Make sure that:

- '.' is a correct model identifier listed on 'https://huggingface.co/models'

- or '.' is the correct path to a directory containing a config.json file
```

If a configuration is saved as well, then loading with AutoTokenizer does work:
```
from transformers import BertTokenizer, BertConfig, AutoTokenizer
BertConfig.from_pretrained("bert-base-cased").save_pretrained(".")
BertTokenizer.from_pretrained("bert-base-cased").save_pretrained(".")

AutoTokenizer.from_pretrained(".") # works
```

### Expected behavior
I'd expect that loading a tokenizer with AutoTokenizer would require the same files as a dedicated tokenizer class (e.g. BertTokenizer) requires.


[s2s] pass max_length to config through command line

Problem:
In summarization, ideal beam search params vary between finetuning datasets. If you are finetuning pegasus-large on xsum, you want config.max_length=56, if you are finetuning pegasus-large on cnn-dailymail you want config.max_length=128.

### Solutions
- the command line arg should be called `max_generate_length`

- This could also be addressed through adding `task_specific_params` for every dataset. Then you could pass `--task summarize_xsum` to finetune.py and things would work. Kinda lame though.


[WIP] Lm loss feed forward chunking

Final word embedding layer in LM loss calculation presents a bottleneck as the entire time dim - can be chunked similar to feed forward layers.


Feed forward chunking others

Adding feed forward chunking to other models. Based on #6024


correct pl link in readme


[s2s] add BartTranslationDistiller for distilling mBART

New class `BartTranslationDistiller` does the same distillation method as `SummarizationDistiller`, but computes BLEU scores instead of ROUGE scores. It also accepts `--src_lang` and `--tgt_lang` arguments from the command line.

There is one strong checkpoint already posted at `sshleifer/distillmbart-12-6/`. I will post more in the coming days.


[TFTrainer] Error "iterating over `tf.Tensor` is not allowed"

## 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: 3.0.2 (from pip)
- Platform: Linux-4.15.0-91-generic-x86_64-with-Ubuntu-18.04-bionic
- Python version: 3.7.6
- PyTorch version (GPU?): not installed (NA)
- Tensorflow version (GPU?): 2.3.0 (True) (Same error on TF2.2 and TF2.1)
- Using GPU in script?: Yes - GeForce GTX 1080 Ti
- Using distributed or parallel set-up in script?: No

### Who can help
 Trainer: @sgugger  tensorflow: @jplu
<!-- Your issue will be replied to more quickly if you can figure out the right person to tag with @
 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

 albert, bert, GPT2, XLM: @LysandreJik
 tokenizers: @mfuntowicz
 Trainer: @sgugger
 Speed and Memory Benchmarks: @patrickvonplaten
 Model Cards: @julien-c
 Translation: @sshleifer
 Summarization: @sshleifer
 TextGeneration: @TevenLeScao
 examples/distillation: @VictorSanh
 nlp datasets: [different repo](https://github.com/huggingface/nlp)
 rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)
 Text Generation: @TevenLeScao
 blenderbot: @mariamabarham
 Bart: @sshleifer
 Marian: @sshleifer
 T5: @patrickvonplaten
 Longformer/Reformer: @patrickvonplaten
 TransfoXL/XLNet: @TevenLeScao
 examples/seq2seq: @sshleifer
 tensorflow: @jplu
documentation: @sgugger
 -->

## Information

Model I am using (Bert, XLNet ...): GPT2

The problem arises when using:
* [ ] the official example scripts: (give details below)
* [X] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [X] my own task or dataset: (give details below)

## To reproduce

Steps to reproduce the behavior:
1.  Install Tensorflow 2.3.0, Transformers 3.0.2

1. Run the following code:

```python3
from transformers import TFGPT2LMHeadModel, TFTrainer, TFTrainingArguments
import tensorflow as tf

tfds_train_dataset = tf.data.Dataset.from_tensor_slices(
    tf.random.uniform([4000, 1024], minval=1, maxval=10, dtype=tf.int32))

model = TFGPT2LMHeadModel.from_pretrained("gpt2")

training_args = TFTrainingArguments(
    output_dir='./results',
    num_train_epochs=3,
    per_device_train_batch_size=16,
    per_device_eval_batch_size=64,
    warmup_steps=500,
    weight_decay=0.01,
    logging_dir='./logs',
)

trainer = TFTrainer(
    model=model,
    args=training_args,
    train_dataset=tfds_train_dataset,
)

trainer.train()
```

2. Results in the following output + error:
```
2020-08-09 01:41:28.331697: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
2020-08-09 01:41:30.461375: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcuda.so.1
2020-08-09 01:41:30.466239: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce GTX 1080 Ti computeCapability: 6.1
coreClock: 1.582GHz coreCount: 28 deviceMemorySize: 10.92GiB deviceMemoryBandwidth: 451.17GiB/s
2020-08-09 01:41:30.466271: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
2020-08-09 01:41:30.468575: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcublas.so.10
2020-08-09 01:41:30.470629: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcufft.so.10
2020-08-09 01:41:30.471013: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcurand.so.10
2020-08-09 01:41:30.473522: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcusolver.so.10
2020-08-09 01:41:30.474947: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcusparse.so.10
2020-08-09 01:41:30.481193: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudnn.so.7
2020-08-09 01:41:30.482710: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858] Adding visible gpu devices: 0
2020-08-09 01:41:30.483080: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-08-09 01:41:30.512602: I tensorflow/core/platform/profile_utils/cpu_utils.cc:104] CPU Frequency: 3210790000 Hz
2020-08-09 01:41:30.514335: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x4c678f0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-08-09 01:41:30.514408: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-08-09 01:41:30.648534: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x4c92000 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-08-09 01:41:30.648597: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce GTX 1080 Ti, Compute Capability 6.1
2020-08-09 01:41:30.650365: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce GTX 1080 Ti computeCapability: 6.1
coreClock: 1.582GHz coreCount: 28 deviceMemorySize: 10.92GiB deviceMemoryBandwidth: 451.17GiB/s
2020-08-09 01:41:30.650446: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
2020-08-09 01:41:30.650523: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcublas.so.10
2020-08-09 01:41:30.650586: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcufft.so.10
2020-08-09 01:41:30.650646: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcurand.so.10
2020-08-09 01:41:30.650708: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcusolver.so.10
2020-08-09 01:41:30.650767: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcusparse.so.10
2020-08-09 01:41:30.650829: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudnn.so.7
2020-08-09 01:41:30.653179: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858] Adding visible gpu devices: 0
2020-08-09 01:41:30.653232: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
2020-08-09 01:41:31.392168: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-08-09 01:41:31.392212: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]      0
2020-08-09 01:41:31.392225: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1276] 0:   N
2020-08-09 01:41:31.393566: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1402] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7389 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
2020-08-09 01:41:34.003855: W tensorflow/python/util/util.cc:348] Sets are not currently considered sequences, but this may change in the future, so consider avoiding using them.
2020-08-09 01:41:34.145974: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcublas.so.10
All model checkpoint weights were used when initializing TFGPT2LMHeadModel.

All the weights of TFGPT2LMHeadModel were initialized from the model checkpoint at gpt2.
If your task is similar to the task the model of the ckeckpoint was trained on, you can already use TFGPT2LMHeadModel for predictions without further training.
Traceback (most recent call last):
  File "gpt2-training_bug.py", line 26, in <module>
    trainer.train()
  File "/home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/transformers/trainer_tf.py", line 412, in train
    for step, training_loss in enumerate(self._training_steps(train_ds, optimizer)):
  File "/home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/transformers/trainer_tf.py", line 459, in _training_steps
    for i, loss in enumerate(self._accumulate_next_gradients(ds)):
  File "/home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/transformers/trainer_tf.py", line 492, in _accumulate_next_gradients
    yield _accumulate_next()
  File "/home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 780, in __call__
    result = self._call(*args, **kwds)
  File "/home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 823, in _call
    self._initialize(args, kwds, add_initializers_to=initializers)
  File "/home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 697, in _initialize
    *args, **kwds))
  File "/home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 2855, in _get_concrete_function_internal_garbage_collected
    graph_function, _, _ = self._maybe_define_function(args, kwargs)
  File "/home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 3213, in _maybe_define_function
    graph_function = self._create_graph_function(args, kwargs)
  File "/home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 3075, in _create_graph_function
    capture_by_value=self._capture_by_value),
  File "/home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/tensorflow/python/framework/func_graph.py", line 986, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 600, in wrapped_fn
    return weak_wrapped_fn().__wrapped__(*args, **kwds)
  File "/home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/tensorflow/python/framework/func_graph.py", line 973, in wrapper
    raise e.ag_error_metadata.to_exception(e)
tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: in user code:

    /home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/transformers/trainer_tf.py:486 _accumulate_next  *
        per_replica_features, per_replica_labels = next(iterator)
    /home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/tensorflow/python/framework/ops.py:503 __iter__
        self._disallow_iteration()
    /home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/tensorflow/python/framework/ops.py:496 _disallow_iteration
        self._disallow_when_autograph_enabled("iterating over `tf.Tensor`")
    /home/gabriel/venv/GPT-Hug/lib/python3.7/site-packages/tensorflow/python/framework/ops.py:474 _disallow_when_autograph_enabled
        " indicate you are trying to use an unsupported feature.".format(task))

    OperatorNotAllowedInGraphError: iterating over `tf.Tensor` is not allowed: AutoGraph did convert this function. This might indicate you are trying to use an unsupported feature.
```

<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->

## Expected behavior

Start Training

<!-- A clear and concise description of what you would expect to happen. -->


lr_schedulers: add get_polynomial_decay_schedule_with_warmup

Related to pretrained model cards

this PR adds a new scheduler plus test, code is based on amalgamation of a few different implementations

I'm not sure it's 100% correct - needs more experimenting - but feedback is welcome.

For reference here are 3 different implementations of this scheduler:
1. https://github.com/pyprob/pyprob/blob/master/pyprob/nn/inference_network.py#L357
2. https://github.com/cmpark0126/pytorch-polynomial-lr-decay/blob/master/torch_poly_lr_decay/torch_poly_lr_decay.py#L5
3. https://github.com/pytorch/fairseq/blob/master/fairseq/optim/lr_scheduler/polynomial_decay_schedule.py - this one has an extra feature `--force-anneal`

@sshleifer


Bug in squad example with XLNet

## 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: 3.0.2
- Platform: Linux-3.10.0-957.21.2.el7.x86_64-x86_64-with-centos-7.6.1810-Core
- Python version: 3.7.4
- PyTorch version (GPU?): 1.4.0 (False)
- Tensorflow version (GPU?): 2.0.0 (False)
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>

### Who can help
<!-- Your issue will be replied to more quickly if you can figure out the right person to tag with @
 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

 examples/distillation: @VictorSanh

 -->

## Information

Model I am using (Bert, XLNet ...):
XLNet

The problem arises when using:
the official example scripts: (give details below)

The tasks I am working on is:
an official GLUE/SQUaD task: (give the name)

## To reproduce

Steps to reproduce the behavior:

1. run_squad.py with xlnet as the mode type
2. I think because the AutoModelForQuestionAnswering is mapping xlnet to XLNetForQuestionAnsweringSimple, it will have input error. Since XLNetForQuestionAnsweringSimple does not require cls_index, it will throw an error
3. https://github.com/huggingface/transformers/blob/d9149f00d1a4650bafa7e1cd73e10398193c852c/examples/question-answering/run_squad.py#L194

<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->

## Expected behavior

<!-- A clear and concise description of what you would expect to happen. -->


Mult rouge by 100: standard units


[s2s] fix --gpus clarg collision

### Problem
finetune.py adds all the default pl args with this line

```
parser = pl.Trainer.add_argparse_args(parser)
```
and all the generic args from `add_generic_args`.

### Solution
This moves the overlapping arg from lightning_base.py to the 2 pl examples that need it.

CC @stas00  @patil-suraj


Create Model Card File

Related to pretrained model cards


Create Model Card

Related to pretrained model cards


GPU memory consumption increases while training

## 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: 3.0.2
- Platform: Google Colab
- Python version: 3.6
- PyTorch version (GPU?):  1.6
- Tensorflow version (GPU?):
- Using GPU in script?:
- Using distributed or parallel set-up in script?: No

### Who can help
<!-- Your issue will be replied to more quickly if you can figure out the right person to tag with @
 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.
 @LysandreJik @sgugger

 albert, bert, GPT2, XLM: @LysandreJik
 tokenizers: @mfuntowicz
 Trainer: @sgugger
 Speed and Memory Benchmarks: @patrickvonplaten
 Model Cards: @julien-c
 Translation: @sshleifer
 Summarization: @sshleifer
 TextGeneration: @TevenLeScao
 examples/distillation: @VictorSanh
 nlp datasets: [different repo](https://github.com/huggingface/nlp)
 rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)
 Text Generation: @TevenLeScao
 blenderbot: @mariamabarham
 Bart: @sshleifer
 Marian: @sshleifer
 T5: @patrickvonplaten
 Longformer/Reformer: @patrickvonplaten
 TransfoXL/XLNet: @TevenLeScao
 examples/seq2seq: @sshleifer
 tensorflow: @jplu
documentation: @sgugger
 -->

## Information

Model I am using (Bert, XLNet ...): XLM Multi-lingual

The problem arises when using:
* [ ] the official example scripts: (give details below)
* [ ] my own modified scripts: (give details below)
Please see below steps to reproduce

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [ ] my own task or dataset: (give details below)

## To reproduce

Steps to reproduce the behavior:

1. Importing Python Libraries and preparing the environment
```python
!pip install git+https://github.com/huggingface/transformers
from transformers import (
    AutoTokenizer,
    AutoConfig,
    AutoModelForSequenceClassification
)
from torch import cuda
device = 'cuda' if cuda.is_available() else 'cpu'
```
2. Loading a pretrained model "xlm-mlm-tlm-xnli15-1024"

```python

MODEL_NAME_OR_PATH = 'xlm-mlm-tlm-xnli15-1024'
CACHE_DIR='cache'
config = AutoConfig.from_pretrained(
    MODEL_NAME_OR_PATH,
    num_labels=7,
    cache_dir=CACHE_DIR,
)
tokenizer = AutoTokenizer.from_pretrained(
    MODEL_NAME_OR_PATH,
    cache_dir=CACHE_DIR,
)
model = AutoModelForSequenceClassification.from_pretrained(
    MODEL_NAME_OR_PATH,
    from_tf=bool(".ckpt" in MODEL_NAME_OR_PATH),
    config=config,
    cache_dir=CACHE_DIR
)
```
3. Check GPU usage

```
!nvidia-smi
```

4. Moving the model to CUDA

```
model.to(device)
```

then check GPU usage again

```
!nvidia-smi
```

5. Creating test inputs

```python
texts = [
         "aloe vera , wassernabelkrautextrakt , ackerschachtelhalm extrakt , geranium extract , dandelion extract , natriummethyl two sulfolaurate dinatrium two sulfolaurate , sodium cocoyl isethionat , cocamidopropylbetain , cocamidopropylhydroxysultain , kokosglucoside , natrium chlorid , glyceryl oleat , natriumenzoat , guar hydroxypropyltrimonium chloride , tetrasodium glutamat diacetat , decyl glucoside , sodium levulinate , hydroxamsäure , sodium pca , caprylyl glycol , zitronensäure , als koscher zertifizierte pflanzliches glycerin , eukalyptusöl , pfefferminzöl , zitronengrassöl . zertifiziert als organisch . wir verwenden nur die besten natürlichen zutaten . wenn möglich , verwenden wir onezerozero percent zertifizierte organische zutaten und niemals : petrochemikalien , sulfate , parabene , phthalate oder synthetische duftstoffe oder farben , tea , dea , glycol , silikon oder pegs . nur an menschen getested . in anderen worten : wir stellen nur absolut reine produkte her und garantieren mit onezerozero percent sicherheit , dass sie ihrem körper keine chemikalien zuführen .",
         "was es bewirkt das waschgel auf kokosnussbasis entfernt überschüssiges hautfett , während das darin enthaltene aloe vera gel die haut erneuert . das gesichtspflege gel für eine tiefenwirksame porenreinigung . "
         "stimmungsaufhellendes orangenöl für die massage ( kein ätherisches öl für duftlampen ) . ohne paraffin ohne mineralöl , ohne parabene , ohne konservierungsmittel , selbstverständlich ohne tierversuche , vegan",
         "onezerozero percent natives kaltgepresstes biomandelöl aus one . kaltpressung . sanfte und schonende mechanische verarbeitung in deutschland . ",
         "aloe vera , wassernabelkrautextrakt , ackerschachtelhalm extrakt , geranium extract , dandelion extract , natriummethyl two sulfolaurate dinatrium two sulfolaurate , sodium cocoyl isethionat , cocamidopropylbetain , cocamidopropylhydroxysultain , kokosglucoside , natrium chlorid , glyceryl oleat , natriumenzoat , guar hydroxypropyltrimonium chloride , tetrasodium glutamat diacetat , decyl glucoside , sodium levulinate , hydroxamsäure , sodium pca , caprylyl glycol , zitronensäure , als koscher zertifizierte pflanzliches glycerin , eukalyptusöl , pfefferminzöl , zitronengrassöl . zertifiziert als organisch . wir verwenden nur die besten natürlichen zutaten . wenn möglich , verwenden wir onezerozero percent zertifizierte organische zutaten und niemals : petrochemikalien , sulfate , parabene , phthalate oder synthetische duftstoffe oder farben , tea , dea , glycol , silikon oder pegs . nur an menschen getested . in anderen worten : wir stellen nur absolut reine produkte her und garantieren mit onezerozero percent sicherheit , dass sie ihrem körper keine chemikalien zuführen .",
         "was es bewirkt das waschgel auf kokosnussbasis entfernt überschüssiges hautfett , während das darin enthaltene aloe vera gel die haut erneuert . das gesichtspflege gel für eine tiefenwirksame porenreinigung . "
         "stimmungsaufhellendes orangenöl für die massage ( kein ätherisches öl für duftlampen ) . ohne paraffin ohne mineralöl , ohne parabene , ohne konservierungsmittel , selbstverständlich ohne tierversuche , vegan",
         "onezerozero percent natives kaltgepresstes biomandelöl aus one . kaltpressung . sanfte und schonende mechanische verarbeitung in deutschland . ",

]

encode = tokenizer(texts, padding='max_length', max_length=200, truncation=True, return_tensors='pt')
for k in encode:
  encode[k] = encode[k].to(device)
```

6. Re-run steps below to see the GPU usage increases every time we run

```python
model.train()
model(**encode)
!nvidia-smi
```

Got error as below:

```
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-242-decae3a1d2bf> in <module>()
      1 model.train()
----> 2 model(**encode)

8 frames
/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in linear(input, weight, bias)
   1674         ret = torch.addmm(bias, input, weight.t())
   1675     else:
-> 1676         output = input.matmul(weight.t())
   1677         if bias is not None:
   1678             output += bias

RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 11.17 GiB total capacity; 10.10 GiB already allocated; 13.81 MiB free; 10.74 GiB reserved in total by PyTorch)

```

However, if you modify the code in the step 6 as follow:

```
model.train()
output = model(**encode)
print(output)
del output
!nvidia-smi
```
The GPU usage will be stable and the same as every run.

When I'm using batch_size >= 16 with Trainer class I have been facing this issue

<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->

## Expected behavior

The GPU usage should stay the same for every run. So that we can run a much bigger batch size.

Right now, I can only use per_device_batch_size <=12 with Trainer class.

Looking forward to learning from you and thank you so much!

<!-- A clear and concise description of what you would expect to happen. -->


BartModel decodes sequence of incorrect length when decoder_input_ids is specified / Output shape mismatch due to when `use_cache` True/False

From the [Bart docs](https://huggingface.co/transformers/model_doc/bart.html#bartmodel), the `decoder_input_ids` attribute should be a tensor of shape `(batch_size, target_sequence_length)`. If we call a `BartModel` without specifying `decoder_input_ids`, the decoded sequence length correctly matches that of `input_ids`. When it is specified, the output sequence is not of shape `target_sequence_length`.

## Environment

Name: torch
Version: 1.6.0+cu101

Name: transformers
Version: 3.0.2

Name: tokenizers
Version: 0.8.1rc1

The error can be reproduced in Colab or Kaggle. See [this notebook ](https://colab.research.google.com/gist/xhlulu/dd989fc7f96b777c01c083762375dfbe/bart-sequence-problems.ipynb)for example.

## Example

```python
import transformers as tfm

model = tfm.BartModel.from_pretrained('facebook/bart-base')
tokenizer = tfm.BartTokenizer.from_pretrained('facebook/bart-base')

input_seq = [
    "What's the capital of Canada?",
    "What's the capital of USA?"
]

output_seq = [
    "It's Ottawa",
    "It's Washington"
]

input_tokens = tokenizer.batch_encode_plus(input_seq, return_tensors='pt', padding=True)
input_ids = input_tokens['input_ids']

output_tokens = tokenizer.batch_encode_plus(output_seq, return_tensors='pt', padding=True)
output_ids = output_tokens['input_ids']

print(input_ids.size(), output_ids.size())  # Returns torch.Size([2, 9]) torch.Size([2, 5])

# Okay
outputs = model.forward(input_ids)
outputs[0].size()  # Returns `torch.Size([2, 9, 768])`

# Incorrect
outputs = model.forward(input_ids, decoder_input_ids=output_ids)
outputs[0].size()  # Returns torch.Size([2, 1, 768])
```


[GPT2] Correct typo in docs


Why is distillbart-cnn done with no teacher and distilbart-xsum has a teacher?

Discussion

Discussion on a topic (keep it focused or open a new issue though)

@sshleifer Can you expand on why distillbart-xsum is done with a teacher and distillbart-cnn is not?


Add model card for electra-base-turkish-cased-ner

model card

Related to pretrained model cards


[testing] USE_CUDA default and intuitive skip decorators

This library's primarily use is for gpu work, and currently many tests won't run even if gpu is available, since the current setup wants env var `USE_CUDA` to be true for anything to happen.  It's easy to forget to manually add this env var to pytest command line.

To maximize the testing potential I propose that only if `USE_CUDA=False` then the test is skipped (for CI jobs that need to test library's work on cpu), otherwise if `if torch.cuda.is_available()` cuda tests can be run.

In a brief discussion @julien-c suggested that:

> The original thinking was that we wanted to make sure that when we wanted to run on GPU it actually ran on GPU. i.e. it should even fail if you do `USE_CUDA`  and there's no GPU, to prevent silent failures on GPU

and the discussion stopped there. This ticket was opened to complete this discussion.

@julien-c, could you please share a specific scenario based on the design intention you shared?

also `CUDA_VISIBLE_DEVICES=""` could be used to easily emulate a non-gpu environment if need be, w/o introducing new env vars. i.e. it'd be a built-in equivalent of `USE_CUDA=False`.

Further, `USE_CUDA` is currently only used for skip decorators. This setting cannot currently be respected from within a test. e.g. in a test I'm currently working on I have:

```
        if torch.cuda.is_available():
            testargs += ['--fp16', '--gpus=1']
```
so it'll ignore  `USE_CUDA`, as the test must always run whether there is a gpu or not, so no skip decorator was used. This ignoring conceptually won't do the right thing then as it'll run the test on gpu even if `USE_CUDA==False` (or unset). So if `USE_CUDA`-functionalty remains, there is a need for an accessor that is not a [skip decorator](https://github.com/huggingface/transformers/blob/master/src/transformers/testing_utils.py#L126).

`require_multigpu` also currently ignores `USE_CUDA`


[Bart] Cannot use Bart decoder cache with torchscript

## 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: 3.0.2
- Platform: Linux-4.15.0-111-generic-x86_64-with-Ubuntu-18.04-bionic
- Python version: 3.7.5
- PyTorch version (GPU?): 1.6.0+cpu (False)
- Tensorflow version (GPU?): 2.2.0 (False)
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

### Who can help

 Bart: @sshleifer

## Information

Model I am using (Bert, XLNet ...): Bart

The problem arises when using:
* [ ] the official example scripts: (give details below)
* [x] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [x] my own task or dataset: (give details below)

## To reproduce

When trying to use torchscript for Bart while passing `decoder_input_ids`:

```python
from transformers import BartModel
import torch

model = BartModel.from_pretrained("sshleifer/bart-tiny-random")
input_ids = decoder_input_ids = torch.tensor([19 * [1] + [model.config.eos_token_id]])
traced_model = torch.jit.trace(model, (input_ids, decoder_input_ids))
```

the following error occurs:
```
RuntimeError: Only tensors, lists, tuples of tensors, or dictionary of tensors can be output from traced functions
```

On the other hand if one disables the past via `model.config.use_cache = False`, then no
error occurs. This could mean that the cache data structure should be updated to correctly work with Torchscript.

## Expected behavior

No error should occur when using Bart + Torchscript  in the way explained above.


ModuleNotFoundError: No module named 'transformers' on Google Colab

I installed **transformers** using the command `!pip install transformers` on **Google Colab Notebook**
But then I try to `import transformers` it throws an error.

This is the output of the pip install command:

Requirement already satisfied: transformers in /usr/local/lib/python3.6/dist-packages/transformers-3.0.2-py3.6.egg (3.0.2)
Requirement already satisfied: dataclasses in /usr/local/lib/python3.6/dist-packages (from transformers) (0.7)
Requirement already satisfied: filelock in /usr/local/lib/python3.6/dist-packages (from transformers) (3.0.12)
Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from transformers) (1.18.5)
Requirement already satisfied: packaging in /usr/local/lib/python3.6/dist-packages (from transformers) (20.4)
Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.6/dist-packages (from transformers) (2019.12.20)
Requirement already satisfied: requests in /usr/local/lib/python3.6/dist-packages (from transformers) (2.23.0)
Requirement already satisfied: sacremoses in /usr/local/lib/python3.6/dist-packages/sacremoses-0.0.43-py3.6.egg (from transformers) (0.0.43)
Requirement already satisfied: sentencepiece!=0.1.92 in /usr/local/lib/python3.6/dist-packages/sentencepiece-0.1.91-py3.6-linux-x86_64.egg (from transformers) (0.1.91)
Requirement already satisfied: tokenizers==0.8.1.rc1 in /usr/local/lib/python3.6/dist-packages/tokenizers-0.8.1rc1-py3.6-linux-x86_64.egg (from transformers) (0.8.1rc1)
Requirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.6/dist-packages (from transformers) (4.41.1)
Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from packaging->transformers) (1.15.0)
Requirement already satisfied: pyparsing>=2.0.2 in /usr/local/lib/python3.6/dist-packages (from packaging->transformers) (2.4.7)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests->transformers) (2.10)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests->transformers) (1.24.3)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests->transformers) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests->transformers) (2020.6.20)
Requirement already satisfied: click in /usr/local/lib/python3.6/dist-packages (from sacremoses->transformers) (7.1.2)
Requirement already satisfied: joblib in /usr/local/lib/python3.6/dist-packages (from sacremoses->transformers) (0.16.0)


Create README.md

Related to pretrained model cards


Is it necessary to provide attention_mask, or model will calculate itself?


[s2s] fix label_smoothed_nll_loss

Regarding issue #4576

Regarding reduction, fairseq does reduce using 'sum' for both [cross_entropy](https://fairseq.readthedocs.io/en/latest/_modules/fairseq/criterions/cross_entropy.html#CrossEntropyCriterion) and [label_smoothed_cross_entropy](https://fairseq.readthedocs.io/en/latest/_modules/fairseq/criterions/label_smoothed_cross_entropy.html) . In transformers, `CrossEntropy` does the default `mean` reduction.  Should we do `mean` or `sum` here ?

@sshleifer


The default cache directory is lack of disk capacity, I need change the configure of the default cache directory.

# 🚀 Feature request

<!-- A clear and concise description of the feature proposal.
     Please provide a link to the paper and code in case they exist. -->

## Motivation

<!-- Please outline the motivation for the proposal. Is your feature request
     related to a problem? e.g., I'm always frustrated when [...]. If this is related
     to another GitHub issue, please link here too. -->

## Your contribution

<!-- Is there any way that you could help, e.g. by submitting a PR?
     Make sure to read the CONTRIBUTING.MD readme:
     https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md -->


[marian] converter supports models from new Tatoeba project

- no state dict change, just need to read model metadata from a new path
- we only accept models with 7 letter names... like `ara-eng`. This is the new format.
- added integration test for `ara-eng`

Done:
- [x] upload 300 models: all new ones that were not "dominated" by a model we already have, where dominated means same langpair but the first model has a higher BLEU score.

Todo:
- [ ] switch integration test for `ara-eng` -> `ar-en`.
- [ ] automated model cards with correct `tags`, more info on all possible language codes.
- [ ] automated conflict resolution: Don't convert models that are worse than predecessors.
- [ ] decide what to do about naming: move all to 3 letter/all to 2 letter?
- [ ] notebook -> pyfile
- [ ] tweet

cc @julien-c

Dict where keys are old names, and values are new names, filtered to situations where new name has higher BLEU than old name:
```
{'bg-es': 'bul-spa',
 'es-eu': 'spa-eus',
 'eu-es': 'eus-spa',
 'es-bg': 'spa-bul',
 'ilo-en': 'ilo-eng',
 'es-mk': 'spa-mkd',
 'es-ca': 'spa-cat',
 'es-af': 'spa-afr',
 'lt-es': 'lit-spa',
 'bn-en': 'ben-eng',
 'th-en': 'tha-eng',
 'fr-ca': 'fra-cat',
 'ga-en': 'gle-eng',
 'en-ga': 'eng-gle',
 'ko-fi': 'kor-fin',
 'es-uk': 'spa-ukr',
 'gl-es': 'glg-spa',
 'eo-sv': 'epo-swe',
 'ca-de': 'cat-deu',
 'az-en': 'aze-eng',
 'sv-eo': 'swe-epo',
 'de-is': 'deu-isl',
 'ceb-en': 'ceb-eng',
 'ca-fr': 'cat-fra',
 'tl-en': 'tgl-eng',
 'is-de': 'isl-deu',
 'ko-en': 'kor-eng',
 'is-es': 'isl-spa',
 'es-gl': 'spa-glg',
 'bg-fr': 'bul-fra',
 'de-af': 'deu-afr',
 'ko-es': 'kor-spa',
 'es-is': 'spa-isl',
 'af-es': 'afr-spa',
 'gl-en': 'glg-eng',
 'fi-en': 'fin-eng',
 'en-bg': 'eng-bul',
 'mk-es': 'mkd-spa',
 'ka-en': 'kat-eng',
 'en-eu': 'eng-eus',
 'de-ca': 'deu-cat',
 'ar-de': 'ara-deu'}

```


[s2s] tiny QOL improvement: run_eval prints scores

its annoying to have to cat a file to see the scores after calling run_eval.py


PegasusForConditionalGeneration (torch version)

This PR adds, [pegasus](https://arxiv.org/abs/1912.08777), a SOTA summarization model ported from [tf1] (https://github.com/google-research/pegasus) in collaboration with @JingqingZ .

More info on the model can be found in `pegasus.rst` under Files changed.
Config: [here](https://s3.amazonaws.com/models.huggingface.co/bert/google/pegasus-xsum/config.json)

#### TODO This PR:
- [x] convert to bart state dict format
- [x] working sentencepiece to
- [x] integration test with good summary on xsum data. (Haven't checked parity).
- [x] beam_alpha -> length_penalty approximation.
- [x] check xsum rouge with length penalty 1. 24.34 vs 24.56 Rouge 2 in paper (very good, no bug). Gap likely from different length penalty.
- [x] convert other checkpoints besides xsum
- [x] tokenizer must know max_source_length (`tokenizer_config.json`)
- [x] `model_doc/pegasus.rst` (document known fp16 issue)
- [x] move all checkpoints to `google/pegasus/{dataset}/`
- [ ] model_cards (S3)

#### Future PR(s):
- [ ] TF 2.0
- [ ] `tokenizer.add_tokens` doesn't work.
- [ ] support for finetuning pegasus-large  (WIP see `finetune_pegasus.sh`)
- [ ] potentially add pegasus's `length_normalization` logic if it helps metrics substantially (over equivalent length_penalty).
- [ ] faster tokenizer tests (with smaller sentencepiece model.)
- [ ] try to find a clean way to add the pegasus length penalty.
- [ ] pick checkpoint for summarization pipeline default -- probably cnndm.

#### Known FP16 Issue
fp16 generation doesn't work for most sequences. We have an activation that is 101,610 in both fp32 and fp16 (the limit is 65,504).
In `#pegasus-collab`, the authors responded that they never used fp16 during pretraining/finetuning.
Things I tried that didn't help:
- never use `FusedLayerNorm`
- increase `layernorm_eps` to 1 (from 1e-5)

Things I haven't tried:
- change all softmaxes to dtype=torch.float32
- manually divide by 100 and finetune more with some loss that discourages large activations.

#### Implementation Choices

- I inherited from Bart with 0 change to bart, but added a new config/modeling file for namespace consistency/control.
- `PegasusTokenizer` inherits from `ReformerTokenizer` -- both just use a single `spiece.model`.
- added common test coverage for the tokenizer, not the model since it is 0 LOC.
- added integration tests for xsum.

###  Inference API

datasets will vary between checkpoints, but otherwise, I think these are almost correct front matter
```
---
language: en
datasets:
- xsum
tags:
- summarization
---
```
This doesn't seem to be helping since [xsum](https://huggingface.co/google/pegasus-xsum) still thinks its for mask filling.


refactor almost identical tests

in preparation for adding more schedulers this PR refactors these almost identical tests.

Unfortunately [can't use `pytest.mark.parametrize`](https://docs.pytest.org/en/latest/unittest.html#pytest-features-in-unittest-testcase-subclasses), so the only drawback that it makes them all into a single test. It'd have been nice to parametrize instead.


remove a TODO item to use a tiny model

as discussed with @sshleifer, removing this TODO to switch to a tiny model, since it won't be able to test the qualitative results of the evaluation (i.e. the results are meaningless).


[CI] add manual workflow dispatch option to github actions runners


broken ONNX slow test

Tests

Related to tests

```
    def test_quantize_pytorch(self):
        for model in OnnxExportTestCase.MODEL_TO_TEST:
            path = self._test_export(model, "pt", 12)
>           quantized_path = quantize(Path(path))
```
tests/test_onnx.py:75:  `path` is None

https://github.com/huggingface/transformers/runs/960368281?check_suite_focus=true


delete unused tiny models

```
                           [ok] bart-tiny-random/
                           [ok] tiny-marian-en-de/
                           [ok] tiny-mbart/
                           [deleted] distilbert_tiny_random/
                           [ok] tiny-ctrl/
                           PRE tiny-dbmdz-bert-large-cased-finetuned-conll03-english/
                           [ok] tiny-distilbert-base-cased-distilled-squad/
                           [ok] tiny-distilbert-base-cased/
                           [ok] tiny-distilbert-base-uncased-finetuned-sst-2-english/
                           [ok] tiny-distilroberta-base/
                           [ok] tiny-gpt2/
                           [ok] tiny-xlnet-base-cased/
```
and make sure the ones that remain are usable/have tokenizer files.


[WIP] Avoid call to torch.triu


add tests/test_tokenization_reformer.py

Help wanted

Extra attention is needed, help appreciated

Tests

Related to tests

I don't think there is any common test coverage for ReformerTokenizer. besides through integration tests.
Good source for copy/modification is `XLMRobertaTokenizationTest`


[CI] Self-scheduled runner also pins torch

```bash
pip install torch!=1.6.0 --no-cache-dir
```


Delete this line in label_smoothed_nll_loss

```python
bs = pad_mask.long().sum()
```


BertForPreTraining with NSP

# ❓ Questions & Help

## Details
I am trying to train BERT from scratch following a modification of https://huggingface.co/blog/how-to-train, where I use a BertTokenizer and BertForPreTraining. The [documentation for BertForPreTraining](https://huggingface.co/transformers/model_doc/bert.html#transformers.BertForPreTraining) states that it has two heads on top for both pre-training processes (MLM and NSP), but [the example provided](https://github.com/huggingface/transformers/blob/master/src/transformers/modeling_bert.py#L874-L884) only provides an example of MLM.

Based on [a comment](https://github.com/huggingface/transformers/issues/2693#issuecomment-580870278) provided by @LysandreJik in a previous issue, it seems that none of the provided datasets (i.e. LineByLineTextDataset) will handle the NSP objective and this objective is excluded because the RoBERTa paper has proven that the NSP objective was not particularly helpful.

@LysandreJik additionally noted that anyone who wants to implement the NSP objective can do so by changing the dataset/training loop, and I was wondering if there were any plans to add support for NSP for the sake of completeness?

It seems that something similar to what is going on in a PR (https://github.com/huggingface/transformers/pull/6168) for Albert SOP can be done. Is this correct and can anyone provide me with some guidance moving forward?


my code:

from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("lonePatient/albert_chinese_small")
model = AutoModel.from_pretrained("lonePatient/albert_chinese_small")
model.save_pretrained("lonePatient+albert_chinese_small")

+++++++++++

Downloading: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 633/633 [00:00<00:00, 113kB/s]
Traceback (most recent call last):
  File "hg_download.py", line 30, in <module>
    tokenizer = AutoTokenizer.from_pretrained("lonePatient/albert_chinese_small")
  File "/usr/local/lib/python3.8/site-packages/transformers/tokenization_auto.py", line 217, in from_pretrained
    return tokenizer_class_py.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/transformers/tokenization_utils_base.py", line 1140, in from_pretrained
    return cls._from_pretrained(*inputs, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/transformers/tokenization_utils_base.py", line 1239, in _from_pretrained
    raise EnvironmentError(
OSError: Model name 'lonePatient/albert_chinese_small' was not found in tokenizers model name list (albert-base-v1, albert-large-v1, albert-xlarge-v1, albert-xxlarge-v1, albert-base-v2, albert-large-v2, albert-xlarge-v2, albert-xxlarge-v2). We assumed 'lonePatient/albert_chinese_small' was a path, a model identifier, or url to a directory containing vocabulary files named ['spiece.model'] but couldn't find such vocabulary files at this path or url.
~/ub16_prj %


Small docfile fixes

Nothing major, just a few fixes to make the files work with the coming notebook conversion.


Batched pipeline

Hi,

Is there a way to run batches with QuestionAnsweringPipeline rather than just one example?

Thanks.


Patch models


Text-to-SQL Query

# ❓ Questions & Help

Hello everyone, I got a task that I want to use NLP for convert text into a SQL query. Anyone knows how to do this or got any suggestion? Thanks.


Create README.md

model card

Related to pretrained model cards


Hi , I am having trouble locating the transformers/examples/summarization/bart/ file. I was wondering if it has been renamed or changed?

# ❓ Questions & Help

<!-- The GitHub issue tracker is primarly intended for bugs, feature requests,
     new models and benchmarks, and migration questions. For all other questions,
     we direct you to the Hugging Face forum: https://discuss.huggingface.co/ .
     You can also try Stack Overflow (SO) where a whole community of PyTorch and
     Tensorflow enthusiast can help you out. In this case, make sure to tag your
     question with the right deep learning framework as well as the
     huggingface-transformers tag:
     https://stackoverflow.com/questions/tagged/huggingface-transformers
     -->

## Details
<!-- Description of your issue -->

<!-- You should first ask your question on the forum or SO, and only if
     you didn't get an answer ask it here on GitHub. -->
**A link to original question on the forum/Stack Overflow**:


Transformer-XL: Improved tokenization with sacremoses

Fixes #5136

As explained in the above issue, this PR fixes the tokenization of the TransfoXLTokenizer by using the sacremoses library with an extended feature of tokenizing comma-separated and floating point numbers. That way the input text is tokenized the same way as in the WikiText-103 dateset used for pretraining.

Changes in a nutshell:
 * The TransfoXLTokenizer is now using sacremoses for tokenization
 * Added tokenization of comma-separated and floating point numbers.
 * Removed prepare_for_tokenization() from tokenization_transfo_xl.py because punctuation is handled by sacremoses
 * Added corresponding tests
 * Removed test comapring TransfoXLTokenizer and TransfoXLTokenizerFast (as discussed in #5302)
 * Added deprecation warning to TransfoXLTokenizerFast (as discussed in #5302)

@TevenLeScao


[Community notebooks] Add notebook on fine-tuning Electra and interpreting with IG

Adding a link to a community notebook containing an example of:
- fine-tuning Electra on GLUE SST-2 with Trainer,
- running Captum Integrated Gradients token importance attribution on the results ,
- visualizing attribution with captum.attr.visualization.


Multi-gpu LM finetuning

Hello,

how can I run LM finetuning with more than one gpu (specifically I want to train gpt2-medium on Google Cloud with four nvidia T4, 64GB).

What are the arguments to pass to `run_language_modeling.py` script?

Thanks


num_beams error in GPT2DoubleHead model

## 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: 2.9.1
- Platform: Linux
- Python version: 3.6
- PyTorch version (GPU?): 1.5
- Tensorflow version (GPU?):
- Using GPU in script?: Yes
- Using distributed or parallel set-up in script?: Yes

### Who can help
@LysandreJik @patil-suraj
<!-- Your issue will be replied to more quickly if you can figure out the right person to tag with @
 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

 albert, bert, GPT2, XLM: @LysandreJik
 tokenizers: @mfuntowicz
 Trainer: @sgugger
 Speed and Memory Benchmarks: @patrickvonplaten
 Model Cards: @julien-c
 Translation: @sshleifer
 Summarization: @sshleifer
 TextGeneration: @TevenLeScao
 examples/distillation: @VictorSanh
 nlp datasets: [different repo](https://github.com/huggingface/nlp)
 rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)
 Text Generation: @TevenLeScao
 blenderbot: @mariamabarham
 Bart: @sshleifer
 Marian: @sshleifer
 T5: @patrickvonplaten
 Longformer/Reformer: @patrickvonplaten
 TransfoXL/XLNet: @TevenLeScao
 examples/seq2seq: @sshleifer
 tensorflow: @jplu
documentation: @sgugger
 -->

## Information

I am trying to use `model.generate()` for the GPT2DoubleHeadModel but the beam search is giving an error.
Setting the `num_beams > 1` results in the following error:
```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/hdd1/vibhav/anaconda3/envs/vesnli/lib/python3.7/site-packages/torch/autograd/grad_mode.py", line 15, in decorate_context
    return func(*args, **kwargs)
  File "/home/hdd1/vibhav/anaconda3/envs/vesnli/lib/python3.7/site-packages/transformers/modeling_utils.py", line 1125, in generate
    model_specific_kwargs=model_specific_kwargs,
  File "/home/hdd1/vibhav/anaconda3/envs/vesnli/lib/python3.7/site-packages/transformers/modeling_utils.py", line 1481, in _generate_beam_search
    past = self._reorder_cache(past, beam_idx)
  File "/home/hdd1/vibhav/anaconda3/envs/vesnli/lib/python3.7/site-packages/transformers/modeling_utils.py", line 1551, in _reorder_cache
    return tuple(layer_past.index_select(1, beam_idx) for layer_past in past)
  File "/home/hdd1/vibhav/anaconda3/envs/vesnli/lib/python3.7/site-packages/transformers/modeling_utils.py", line 1551, in <genexpr>
    return tuple(layer_past.index_select(1, beam_idx) for layer_past in past)
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)
```

However, things are working fine for `num_beams=1` and for GPT2LMHeadModel(both beam search and non beam search)


TFBert runs slower than keras-bert， any plan to speed up？

classification task run with keras-bert using 7ms, but run with TFBert using 50+ms, both of them runing on GPU, detail arguments:
hidden layers: 6
max_seq_length: 64
cuda: 2080ti

As I see, most of time using cost by bert encoder, average 6 ms per encoder layer, while keras-bert encoder per layer use less than 1ms

do we have any plan to solve this problem？
ths！


codecov invalid reports due to inconsistent code coverage outputs (non-idempotent test-suite)

Currently PRs get a codecov report

1. Observing various commits - especially pure doc commits - It's either not working right or it needs to be configured.

e.g., this PR has 0.00% change to the code:
https://github.com/huggingface/transformers/pull/6315/files
yet, codecov found  -0.51%  decrease in coverage - this makes no sense. (edit: it updates itself with other commits to master, now it shows -0.31%)

2. Does it have to send a notification and not just comment on the PR?

It appears that it can be finetuned, and notifications sent only if a desired threshold is passed: https://docs.codecov.io/docs/notifications#standard-notification-fields - so that it actually flags an issue when there is one.
Here is a ready conf file from a random project: https://github.com/zulip/zulip/blob/master/.codecov.yml
except perhaps adjusting threshold to 1%? (edited) and not sure whether we want it to comment by default.


Dataloader number of workers in Trainer

https://github.com/huggingface/transformers/blob/175cd45e13b2e33d1efec9e2ac217cba99f6ae58/src/transformers/trainer.py#L252

If you want to use the Trainer from trainer.py, you only have the option to use only 0 number of workers for your dataloader.

However, even if I change the source code to have 10 number or workers for the data loader, the model still uses the same thread.


[examples] consistently use --gpus, instead of --n_gpu

- some docs were wrongly suggesting to use `--n_gpu`, when the code is `--gpus`
- `examples/distillation/` had  `--n_gpu`, in the code - switched it and the doc to `--gpus`


[pl] restore lr logging behavior for glue, ner examples

2 more fixes for https://github.com/huggingface/transformers/pull/6027

1. restore the original code and add what was there already, instead of a complex line of code.

2. restore removed `rate` field - solve the missing bit


Error trying to import SquadDataset

## Environment info

- `transformers` version: 3.0.2
- Platform: Linux-4.15.0-108-generic-x86_64-with-glibc2.10
- Python version: 3.8.2
- PyTorch version (GPU?): 1.4.0 (True)
- Tensorflow version (GPU?): not installed (NA)
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>

### Who can help
@sgugger @julien-c

## Information

I am trying to follow the run_squad_trainer example. However I am unable to import the SquadDataset from transformers. I tried updating to 3.0.2 but got the same error.
https://github.com/huggingface/transformers/blob/master/examples/question-answering/run_squad_trainer.py

```
from transformers import SquadDataset
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-6-13f8e9ce9352> in <module>
----> 1 from transformers import SquadDataset

ImportError: cannot import name 'SquadDataset' from 'transformers' (/home/brian/miniconda3/envs/ML38/lib/python3.8/site-packages/transformers/__init__.py)
```

## Expected behavior

Import runs without error.


clarify shuffle


modify ``val_loss_mean``

revised by this warning
***/lib/python3.*/site-packages/pytorch_lightning/utilities/distributed.py:25: RuntimeWarning: The metric you returned 1.234 must be a `torch.Tensor` instance, checkpoint not saved HINT: what is the value of val_loss in validation_epoch_end()?


collision between different cl arg definitions in examples

 The `examples` have an incosistency of how the cl args are defined and parsed. Some rely on PL's main args as `finetune.py` does: https://github.com/huggingface/transformers/blob/master/examples/seq2seq/finetune.py#L410

```
    parser = argparse.ArgumentParser()
    parser = pl.Trainer.add_argparse_args(parser)
```

others like `run_pl_glue.py` rely on `lightening_base.py`'s main args: https://github.com/huggingface/transformers/blob/master/examples/text-classification/run_pl_glue.py#L176

```
    parser = argparse.ArgumentParser()
    add_generic_args(parser, os.getcwd())
```
now that we pushed `--gpus` into  `lightening_base.py`'s main args the scripts that run PL's main args collide and we have:

```
fail.argparse.ArgumentError: argument --gpus: conflicting option string: --gpus
```

i.e. PL already supplies `--gpus` and many other args that some of the scripts in `examples` re-define.

So either the example scripts need to stop using `pl.Trainer.add_argparse_args(parser)` and rely exclusively on `lightning_base.add_generic_args`, or we need a different clean approach. It appears that different scripts have different needs arg-wise. But they all use `lightning_base`.

The problem got exposed in: https://github.com/huggingface/transformers/pull/6027 and https://github.com/huggingface/transformers/pull/6307