noamaanMulla-03/transformers-issues huggingface dataset:
Add ability to include additional model card info within Trainer
Author: nateraw
Pull request: no

# 🚀 Feature request

<!-- A clear and concise description of the feature proposal.
     Please provide a link to the paper and code in case they exist. -->

Allow users to optionally provide model description, intended use, ethical considerations, caveats and recommendations, etc. when calling `trainer.push_to_hub` and/or `trainer.create_model_card`. 

## 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. -->

Right now, when you do `trainer.push_to_hub`, it runs `trainer.create_model_card`, which calls `transformers.modelcard.TrainingSummary.to_model_card` behind the scenes to put together the model card's text. It does not allow you to pass the sections mentioned above. 

https://github.com/huggingface/transformers/blob/b1198a8440cc05f569b0bc22038993a1e5e707ab/src/transformers/trainer.py#L2479-L2502

Thus, whenever someone pushes to the hub with `Trainer`, there are a bunch of sections that say "More information needed".  

---

I see that `transformers.modelcard.ModelCard` has these options, but there's a note about it being deprecated. 

https://github.com/huggingface/transformers/blob/b1198a8440cc05f569b0bc22038993a1e5e707ab/src/transformers/modelcard.py#L74-L100

## 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 -->


Comments:
Yes the `ModelCard` is deprecated as it does not make any sense to deal with this programmatically (the class was there for more than a year and I haven't seen it used once).

The Trainer drafts the model card, it's then the responsibility of the user to edit it in a followup commit, but the easiest way to do this, is through the user's preferred text editor IMO.


> but the easiest way to do this, is through the user's preferred text editor IMO

or directly on the hub website 👍 

we should remove the current `ModelCard` implementation to make room for new helpers IMO (which will be in `huggingface_hub`)


It will disappear in v5 as it's a breaking change.

closing and will address in `huggingface_hub`
pip install transformers not downloading gpt2-xl
Author: samer-noureddine
Pull request: no

Following the release of 1.5 B parameter model, I attempted to upgrade my version using the following command:

pip install transformers --upgrade


The installed library does not have gpt2-xl, and throws this error when I try calling it:

OSError: Model name 'gpt2-xl' was not found in model name list (gpt2, gpt2-medium, gpt2-large, distilgpt2). We assumed 'gpt2-xl' was a path or url to a configuration file named config.json or a directory containing such a file but couldn't find any such file at this path or url.

Please update the pip installer to allow the easy installation of the latest model

Comments:
We haven't updated the pip version yet, we'll do so in the following weeks. Please install it from source in the meantime:

```
pip install git+https://github.com/huggingface/transformers
```

Traceback (most recent call last):
  File "run_pplm.py", line 936, in <module>
    run_pplm_example(**vars(args))
  File "run_pplm.py", line 738, in run_pplm_example
    tokenizer = GPT2Tokenizer.from_pretrained(pretrained_model)
  File "/home/xps/anaconda3/envs/nlg_entity/lib/python3.7/site-packages/transformers/tokenization_utils.py", line 911, in from_pretrained
    return cls._from_pr
etrained(*inputs, **kwargs)
  File "/home/xps/anaconda3/envs/nlg_entity/lib/python3.7/site-packages/transformers/tokenization_utils.py", line 1014, in _from_pretraine
    list(cls.vocab_files_names.values()),
OSError: Model name 'gpt2-medium' was not found in tokenizers model name list (gpt2, gpt2-medium, gpt2-large, gpt2-xl, distilgpt2). We asswas a path, a model identifier, or url to a directory containing vocabulary files named ['vocab.json', 'merges.txt'] but couldn't find sucat this path or url.




I also reported the same error....@LysandreJik


> 回溯（最近一次调用）：
> 文件“run_pplm.py”，第 936 行，在
> run_pplm_example(**vars(args))
> 文件“run_pplm.py”，第 738 行，在 run_pplm_example
> tokenizer = GPT2Tokenizer.from_pretrained(pretrained_model)
> 文件“ /home/xps/anaconda3/envs/nlg_entity/lib/python3.7/site-packages/transformers/tokenization_utils.py", line 911, in from_pretrained
> return
> cls._from_pretrained(*inputs, **kwargs)
> File "/home /xps/anaconda3/envs/nlg_entity/lib/python3.7/site-packages/transformers/tokenization_utils.py”，第 1014 行，在 _from_pretraine
> 列表（cls.vocab_files_names.values()）中，
> OSError：在标记器模型名称列表（gpt2、gpt2-medium、gpt2-large、gpt2-xl、distlgpt2）中找不到模型名称“gpt2-medium”。我们为包含名为 ['vocab.json', 'merges.txt'] 的词汇文件的目录添加了路径、模型标识符或 url，但找不到此路径或 url。
> 
> 我也报了同样的错误.... @LysandreJik

hi,you can run this model?
Hard time installing huggingface for python3.8 cuda10.1
Author: GTimothee
Pull request: no

## Environment info
- `transformers` version: 4.10.0
- Platform: linux (ubuntu)
- Python version: 3.8
- PyTorch version (GPU?): 1.7.1+cu101
- Tensorflow version (GPU?): 2.2.0 , tf-gpu : 2.2.0
- Using GPU in script?: not even using it for now
- Using distributed or parallel set-up in script?: no

## Assignees
- trainer: @sgugger

## Information
I am trying to fine tune the LayoutLMv2ForSequenceClassification model. 

When I test my installation inside a venv with the following command it crashes: 
```
python -c "import tensorflow as tf"
```

Output: 
```
env_3.8/lib/python3.8/site-packages/transformers/onnx/convert.py", line 23, in <module>
    from .. import PreTrainedModel, PreTrainedTokenizer, TensorType, TFPreTrainedModel, is_torch_available
ImportError: cannot import name 'TFPreTrainedModel' from 'transformers' 
```


Comments:
Can you try updating your TensorFlow version and letting us know if it fixes your issue? For example to tensorflow v2.5.0

Hello, finally I solved my issue : it was a tensorflow-related issue. In fact I was playing with a small script named code.py in which I was importing stuff from huggingface, and tensorflow was trying to import something else, also named code.py so there was a circular import or something. So in the end I just renamed my script file and it works !

Ah interesting! Thanks for updating us.
PreTrainedTokenizerFast to BertTokenizer
Author: sooftware
Pull request: no

Hi! I have a question about tokenizers.  
I made a unigram sentencepiece tokenizer using `tokenizers`.  
  
I use this tokenizer like following:  
  
```python
import json
from transformers import PreTrainedTokenizerFast
from tokenizers import SentencePieceUnigramTokenizer

tokens = list()
test_input = 'This is test input.'

# unigram.json is the file that saved by tokenizers library
# tokenizer.train()
# tokenizer.save_model()
with open('unigram.json', encoding='utf-8-sig') as f:
    json_file = json.load(f)
    vocab = json_file['vocab']
    for idx, v in enumerate(vocab):
        vocab[idx] = tuple(v)
        
tokenizer = SentencePieceUnigramTokenizer(vocab)
tokenizer = PreTrainedTokenizerFast(tokenizer_object=tokenizer)

print(tokenizer.tokenize(test_input))
```
  
- Output
```
['▁T', 'h', 'is', '▁', 'is', '▁', 't', 'e', 'st', '▁', 'in', 'p', 'u', 't', '.']
```
  
I think the tokenizer's working. But I want the following format. (bert format)  
```
['[CLS]', '▁T', 'h', 'is', '▁', 'is', '▁', 't', 'e', 'st', '▁', 'in', 'p', 'u', 't', '.', '[SEP]']
```
  
I want to convert it to be easy to use, what can I do?  
Thank you.

Comments:
I tried like this:  

```
from transformers import BertTokenizer

# Load my sentencepiece tokenizer
tokenizer = AutoTokenizer.from_pretrained('my_tokenizer_model')
tokenizer.build_inputs_with_special_tokens = BertTokenizer.build_inputs_with_special_tokens

print(tokenizer.tokenize('테스트 문장입니다.', add_special_tokens=True))
# ['▁테', '스트', '▁문', '장', '입니다']
```
  
I expected that if I change the `build_inputs_with_special_tokens` method, tokenizer would add [CLS] and [SEP].

You should be able to do so by adding a `post_processor` to your tokenizer: https://huggingface.co/docs/tokenizers/python/latest/quicktour.html#post-processing

@LysandreJik Thank you. But, this is not work for me.  
```
from tokenizers.processors import TemplateProcessing

tokenizer.post_processor = TemplateProcessing(
    single="[CLS] $A [SEP]",
    pair="[CLS] $A [SEP] $B:1 [SEP]:1",
    special_tokens=[
        ("[CLS]", tokenizer.vocab["[CLS]"]),
        ("[SEP]", tokenizer.vocab["[SEP]"]),
    ],
)
tokenizer.tokenize('Hi?')
# ['▁', 'H', 'i', '?']
```

The tokenizer is instance of `PreTrainedTokenizerFast `

Can you try doing it on the `SentencePieceUnigramTokenizer` instance (before it's converted to a `transformers` tokenizer?)

It works! Thank you! @LysandreJik
memory crash with large dataset
Author: randomgambit
Pull request: no

Hello,

I am using the basic `sentiment-classification` pipeline based on https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english/tree/main.

I was able to predict the sentiment of several hundreds of sentences but ran into trouble when I tried to predict the sentiment of about 9M short sentences stored in a Pandas dataframe. I have a `RTX 3090` and `150GB` of RAM so I think the prediction should work.

Specifically, I tried the create the sentiment labels by running

```
classifier = pipeline(task = 'sentiment-analysis')
df['mylabels'] = [o['label'] for o in classifier(df.text.tolist())]
```
(where `df.text` contains my headline) hoping to take advantage of the batch processing in `classifier` but after a while (1 hour or so) Python crashed after mentioning

```
successfully opened dynamic library cublas64_10.dll
memory allocation of 11976 bytes failed
```

Is this a bug? Is this the correct way to process large dataframes?
Thanks!



Thanks!

Comments:
on the task manager I see that the dedicated GPU memory usage is constant at 24GB while the shared GPU memory usage is at zero. CPU is at 20% and RAM fills entirely up to 160GB. I cannot share the data (proprietary) but maybe there is something obvious that I am missing here in terms of `pipeline` and processing tricks?

Thanks!

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

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.
Training Transformer XL from scratch for CLM
Author: shampp
Pull request: no

I am training Transformer XL using the **run_clm.py** script. I was able to train GPT2, XLNet, CTRL etc without any issue. But with Transformer XL, I get the error

  ```
File "../lib/python3.8/site-packages/transformers/trainer.py", line 1272, in train
    tr_loss += self.training_step(model, inputs)
  File "../lib/python3.8/site-packages/transformers/trainer.py", line 1734, in training_step
    loss = self.compute_loss(model, inputs)
  File "../lib/python3.8/site-packages/transformers/trainer.py", line 1776, in compute_loss
    loss = outputs["loss"] if isinstance(outputs, dict) else outputs[0]
  File "../lib/python3.8/site-packages/transformers/file_utils.py", line 1738, in __getitem__
    return inner_dict[k]
KeyError: 'loss'

```
I am using the same input format as in the other case of other models.  Can anyone tell me what is the issue here ?

Comments:
Transformer XL is not compatible with the Trainer API, and won't work with any of the example scripts. You should use another model, or a modified version of the `run_clm_no_trainer` script.

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

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.
Can't set attention_probs_dropout_prob in LEDConfig
Author: alceausu
Pull request: no

## Environment info

- `transformers` version: 4.9.0
- Python version: 3.8.10
- PyTorch version (GPU?): 1.9.0


### Who can help
@patrickvonplaten @beltagy 


## Information

Loading LEDForConditionalGeneration throws an error on line 314 of configuration_utils.py:
```
"Can't set attention_probs_dropout_prob with value 0.1 for LEDConfig"
```
but this parameter is required in line 149 of [modeling_led.py](https://github.com/huggingface/transformers/blob/master/src/transformers/models/led/modeling_led.py)
```
classLEDEncoderSelfAttention(nn.Module):
...
   self.dropout=config.attention_probs_dropout_prob
```
It works fine if I remove it from the config.


## To reproduce

I am trying to load a LEDForConditionalGeneration, converted from a Bart model.
See [convert_bart_to_longformerencoderdecoder.py](https://github.com/allenai/longformer/blob/master/scripts/convert_bart_to_longformerencoderdecoder.py) and some hints on how to [replace LongformerEncoderDecoderForConditionalGeneration with LEDForConditionalGeneration](https://github.com/allenai/longformer/issues/192)



Comments:
The reason you're getting this error is because `attention_probs_dropout_prob` is (as of now) only defined as a getter, not as a setter, as you can see [here](https://github.com/huggingface/transformers/blob/ba15fe7995a02357ecea6e7024918f6915564c36/src/transformers/models/led/configuration_led.py#L173-L175). The reason for this is that some models call this dropout value "attention_dropout", while others call it "attention_probs_dropout_prob". To ensure you can also access it with the different name, this property was defined. 

For now, you can get the attention dropout by calling `config.attention_probs_dropout_prob`, but not set it. You can only set it using `config.attention_dropout`.

However, @nreimers is currently working on adding setters (besides getters) for all attribute names and their aliases. Expect a fix for this in the near future.

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

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.
pipeline does not load a (local) model
Author: randomgambit
Pull request: no

Hello the great `huggingface` team!

I am using a computer behind a firewall so I cannot download files from python. I am simply trying to load a sentiment-analysis pipeline so I downloaded all the files available here https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english/tree/main in a local folder (I am using tensorflow)

- config.json
- tf_model.h5
- tokenizer_config.json
- vocab.txt

However, when I tried to use this path in a `pipeline`, I get a strange error:

```
from transformers import pipeline

classifier = pipeline(task= 'sentiment-analysis', 
                      model= "C:\\Users\\me\\mymodel",
                      tokenizer = "C:\\Users\\me\\mymodel")

ValueError: unable to parse C:\Users\me\mymodel\modelcard.json as a URL or as a local path
```

Is this a bug?
Thanks!

Comments:
As the error specifies, there's a problem with the path you are providing. Make sure the path can be parsed correctly.

thanks @NielsRogge, actually I was able to make it work indirectly: first load the model on another computer, then use `save_pretrained`, transfer the saved folder to the offline computer and use the path to the folder. This raises the fundamental question: can we download the files directly from the web? For instance, https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english/tree/main  does not contain a `model_card.json` whereas the folder after `save_pretrained` does. Thanks!

Yes you can download them directly from the web. On the [model page](https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english), there's a button "Use in Transformers" on the right. This shows how you either load the weights from the hub into your RAM using `.from_pretrained()`, or by git cloning the files using git-lfs.

Oh I see, so I can download all the files from the web, put them in a folder (as I did originally) and instead of doing `model = pipeline(model = "to/my/path", tokenizer ="to/my/path")` I should do `model = AutoModelForSequenceClassification.from_pretrained('to/my/path")`?

It depends on whether you want to use the pipeline, or the model right away. Both should work with the files stored locally.

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

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.
CANINE pre-training
Author: ArijRB
Pull request: no

# 🚀 Feature request
Thanks for the integration of the Canine model. I am interested in pre-training the model from scratch and I was wondering if you have a timeline for the release of a pre-training script using autoregressive character loss.

Thank you in advance.

@NielsRogge 

Comments:
Hi,

Google hasn't released any pre-training code yet. As stated on their [README](https://github.com/google-research/language/tree/master/language/canine#pre-training-code-coming-later):

> Pre-training Code (Coming later)
We've prioritized releasing the pre-trained checkpoints, modeling code, and TyDi QA evaluation code since we hope this will cover the most common use cases. The implementation of pre-training will be released in this repo in the future. If this is blocking you, feel free to send us a friendly ping to let us know that this is important to you.

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

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md) are likely to be ignored.
T5: relative position embeddings
Author: ghost
Pull request: no

Hello, 
In the paper [Exploring the limits of Transformer Learning with a Unified Text-to-Text Transformer](https://arxiv.org/pdf/1910.10683.pdf) it says that they share the position embedding parameters across all layers.
<img width="967" alt="Screen Shot 2021-09-03 at 12 35 38 PM" src="https://user-images.githubusercontent.com/19749157/131946859-b23e5ff6-a1ae-4295-8511-4dc8fe273f7f.png">


But as shown below, the current implementation seems to use relative position embedding in the first layer only.
https://github.com/huggingface/transformers/blob/c1c2d68d37d4d8372729038ca06246e31859beaa/src/transformers/models/t5/modeling_t5.py#L807

I'm not sure how it changes the performance, but are there any particular reason for such implementation?

Comments:
Hi @hyukyu ,

T5 implementation does share the relative embedddings. The `has_relative_attention_bias` specifies which layer should store the embedding, which is the first layer in T5. Then the `position_bias` is computed in the first layer and shared with all other layers. 

See
https://github.com/huggingface/transformers/blob/76c4d8bf26de3e4ab23b8afeed68479c2bbd9cbd/src/transformers/models/t5/modeling_t5.py#L487-L496

https://github.com/huggingface/transformers/blob/76c4d8bf26de3e4ab23b8afeed68479c2bbd9cbd/src/transformers/models/t5/modeling_t5.py#L1019-L1022

Hello @patil-suraj,

I misunderstood the code, but now it is very clear that they do use relative embeddings in the other layers too.

I really appreciate your help. Thank you!
Question about xla_spawn.py script and torch_xla.distributed.xla_multiprocessing
Author: quantitative-technologies
Pull request: no

I am able to fine-tune a large BERT model using your `examples/xla_spawn.py` script, by calling it from a colab notebook shell. 

However, when I try essentially the same thing in a colab notebook, putting the code in a cell and calling 

    torch_xla.distributed.xla_multiprocessing.spawn((_mp_fn, start_method="fork")

also in a colab cell, I get errors that the TPUs have run out of memory, when trying to train. 

Is this because the start_method `fork` is less memory efficient? Or should this also work with "native" colab code?

I can give a MRE colab if it's helpful. 

Comments:
I'm unaware of what might be causing this - maybe @sgugger has an answer for you!

I have confirmed that the issue is not with the `start_method="fork"`. 

Your `run_glue.py` script uses `HfArgumentParser` to set up the `training_args` parameter of the `Trainer`. If I instead set the `training_args` manually, I get the same errors on the TPUs as in the colab notebook, even though the script uses `start_method="spawn"`. 

I haven't attempted to figure out exactly what is being set in `training_args` to allow the large BERTSs to be trained on TPUs. 

The training arguments handle the initialization logic for the distributed setup, so they should only be initiliazed inside the `_mp_fn` you launch in parallel.

To launch your training from a colab, you should check the `notebook_launcher` from Accelerate.

Yes, right. I found out about the training arguments after spending some time experimenting. 

I am using a python script, which is called from colab via the shell, and everything is working fine. 

I did try `accelerate` once before but could not get it working, but I create an new issue if I go back to that route and still have problems.