noamaanMulla-03/transformers-issues huggingface dataset:
Make DETR `pixel_values` input optional
Author: qqaatw
Pull request: no

### Feature request

Currently the `pixel_values` input of `DetrModel` and `DetrForObjectDetection` is a required argument, which is nearly useless when `encoder_outputs` is specified. 

Therefore, I propose to make `pixel_values` optional and infer batch size for subsequent uses from the `encoder_outputs` when it is specified. We may also need to add a new optional `position_embeddings` argument for the decoder since the backbone is no longer used and no longer produces the embeddings in this case.

The same approach can be seen at many models, e.g. Bert, which also has its `input_ids` optional:
https://github.com/huggingface/transformers/blob/da47c264f9a881f5db5f6fbb59a30c95e428571f/src/transformers/models/bert/modeling_bert.py#L912-L914

The only issue is that in `DetrForSegmentation`, `pixel_values` is required for producing feature maps and reconstructing the predicted mask. So the proposal is not applicable for this model.

### Motivation

Described above.

### Your contribution

Can make a PR.

@NielsRogge What do you think :) ?

Comments:
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/main/CONTRIBUTING.md) are likely to be ignored.
Training a tokenizer - add argument for preprocessing the input
Author: pepi99
Pull request: no

### Feature request

I am training my huggingface tokenizer on my own corpora, and I want to save it with a preprocessing step. That is, if I pass some text to it, I want it to apply the preprocessing and then tokenize the text, instead of explicitly preprocessing it before that. A good example is BERTweet: https://github.com/VinAIResearch/BERTweet and their `tokenizer = AutoTokenizer.from_pretrained("vinai/bertweet-base", normalization=True)` (here normalization=True indicates that the input will be preprocessed according to some function). I want the same to apply when I train a tokenizer with a custom preprocessing function. My code is:

    from pathlib import Path
    from tokenizers import ByteLevelBPETokenizer
    
    def preprocess(text):
        return text
    
    paths = [str(x) for x in Path('data').glob('*.txt')]
    
    tokenizer = ByteLevelBPETokenizer()
    
    tokenizer.train(files=paths, vocab_size=50_000, min_frequency=2,
                    special_tokens=['
', '<pad>', '
', '<unk>', '<mask>'])
    
    tokenizer.save_model('CustomBertTokenizer')


Now, when I load the tokenizer: 

    from transformers import RobertaTokenizerFast
    sentence = 'Hey'
    tokenizer = RobertaTokenizerFast.from_pretrained('CustomBertTokenizer')
    tokenizer(sentence)

I want `sentence` to be preprocessed with the `preprocess` function, and then tokenized. So I want to pass like an argument : preprocessing=True, or something like that. How can I do it?

How can I achieve this?


### Motivation

.

### Your contribution

.

Comments:
I have also posted my question in  the huggingface forum: https://discuss.huggingface.co/t/save-tokenizer-with-argument/17389

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/main/CONTRIBUTING.md) are likely to be ignored.
Replace assertion with exception
Author: anmolsjoshi
Pull request: yes

# What does this PR do?

Replaces assert with Exceptions as per https://github.com/huggingface/transformers/issues/12789.

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@sgugger 

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_16739). All of your documentation changes will be reflected on that endpoint.

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/main/CONTRIBUTING.md) are likely to be ignored.
fix typo from emtpy to empty on decoding error messages
Author: domenicrosati
Pull request: yes

# What does this PR do?

I am working with constrained generation a lot and a I keep seeing this error typo.
This PR fixes it in order for the error message to be a little freindlier.

cc @patrickvonplaten 


Comments:
_The documentation is not available anymore as the PR was closed or merged._

The test failures don't appear to be related to my PR BTW - I ran all the lints in the CONTRIBUTING guide...

test failures are unrelated
Avoid GPU OOM for a TF Rag test
Author: ydshieh
Pull request: yes

# What does this PR do?

After changing torch from `cu102` to `cu113`, the test `test_rag_token_generate_batch` on TF side causes GPU OOM.
This PR splits the batch into 2 batches to avoid this issue.

I can just run only 1 batch if you think it's better.

Comments:
_The documentation is not available anymore as the PR was closed or merged._

Merged as the change is quite obvious and small + being approved by 1 maintainer.
Bug with .from_pretrained in distributed mode on high-ram Colab instances + Accelerate
Author: muellerzr
Pull request: no
Labels: name: Core: Modeling

name: Distributed Training / Models

name: bug

### System Info

```shell
- `transformers` version: 4.19.3
- `accelerate` version: 0.10.0.dev0
- Platform: Linux-5.4.188+-x86_64-with-Ubuntu-18.04-biotic
- Python version: 3.713
- Huggingface_hub version: 0.7.0
- PyTorch version (GPU?): 1.9.0+cu102 (False)
- Tensorflow version (GPU?): 2.8.2 (False)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script? No (notebook_launcher)
- Using distributed or parallel set-up in script? Accelerate
```


### Who can help?

@sgugger + others related to `.from_pretrained`

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [X] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

On either a high-ram TPU Colab instance or Titan RTX/bad** machine, load the [Simple NLP Example](https://github.com/huggingface/notebooks/blob/main/examples/accelerate/simple_nlp_example.ipynb) and attempt to run it top-down. 

I modified the launch part to be:

```python
notebook_launcher(training_function, (model,))
```
And changed the training function to accept a model arg for it to work

### Expected behavior

It should just run and train fine, but instead it will get a `SIGSEGV` error. We've pinpointed it due to `model = AutoModelFromPretrained...` being inside of the loop that gets launched in the distributed process. If instead we use the already downloaded + instantiated one, the code runs just fine. 

`from_pretrained` should guarantee that a single process is being loaded at a time, but instead we get a SIGSEV. 

Here's two open issues in Accelerate that have detailed stack traces:

- [On TPU](https://github.com/huggingface/accelerate/issues/440)
- [On bad***](https://github.com/huggingface/accelerate/issues/434)


Comments:
cc @pacman100 

The crux of this issue is Google Colab, and its inability to clear out the old model architecture from RAM. So instead of loading 8x model weights, then our new dict, plus the potential to do a gc.collect(), the other model weights are hanging indefinitely in colab space, unable to be freed. Gist here: https://gist.github.com/muellerzr/763feb654fc0446ed4ebf1813e0cb05e
AttributeError: 'TFBertForQuestionAnswering' object has no attribute 'save_pretrained
Author: sangtaik
Pull request: no
Labels: name: bug

### System Info

```shell
I coding in Colab
```


### Who can help?

AttributeError                            Traceback (most recent call last)
<ipython-input-64-1a5b1a678c55> in <module>()
----> 4 model.save_pretrained('model_bert_20220609.pt')

AttributeError: 'TFBertForQuestionAnswering' object has no attribute 'save_pretrained

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [X] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

from transformers import BertTokenizerFast
 
model = TFBertModel.from_pretrained("klue/bert-base",  from_pt = True)
optimizer = tf.keras.optimizers.Adam(learning_rate=5e-5)
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False)
model.compile(optimizer=optimizer, loss=loss)

history = model.fit(
    x_train,
    y_train,
    epochs = 5,
    verbose = 1,
    batch_size = 16,
)

model.save_pretrained('model_bert_20220609.pt')

### Expected behavior

```shell
I want to save my trainned models step by steps but it is not saved.
How can I load and save?
Thank you.
```


Comments:
I am sorry, I am new for git bug issue menu.
but I have no idea about [save_pretrained]

I saw https://huggingface.co/blog/tf-serving

this guide was used save_pretrained function.
`from transformers import TFBertForSequenceClassification

model = TFBertForSequenceClassification.from_pretrained("nateraw/bert-base-uncased-imdb", from_pt=True)

model.save_pretrained("my_model", saved_model=True)`

and I check the code about class
`https://github.com/huggingface/transformers/blob/3f936df66287f557c6528912a9a68d7850913b9b/src/transformers/models/bert/modeling_tf_bert.py`

I really really thinking about it.no problem for save_pretrained.

Why save_pretrained is not no attribute? I think it is bugs.

After 2 days of analysis, I found that there is a difference between the original file on github and the library I received.

The hugging face lib I received was the wrong file, and the class was a completely different model with the same name.


I deleted the file and got a clone of github again to solve it.
RobertaTokenizer fails to do_lower_case, different behavior between version 2 and 3
Author: jingtaozhan
Pull request: no

## Environment info
     
- `transformers` version: 3.4.0 / 2.8.0
- Platform: linux
- Python version: 3.8

### Who can help
@mfuntowicz 

## Information

Tokenizer I am using: RobertaTokenizer
The tokenizer do not lower case the text even if I explicitly set do_lower_case=True. The behavior is different between version 2.8.0 and 3.4.0

## To reproduce

Steps to reproduce the behavior:

```python
from transformers import RobertaTokenizer
tokenizer = RobertaTokenizer.from_pretrained("roberta-base", do_lower_case=True)
print(tokenizer.tokenize("Huggingface"))
```

## Expected behavior

Version 3.4.0 prints: ['Hug', 'ging', 'face']
Version 2.8.0 prints: ['h', 'ug', 'ging', 'face']


Comments:
Could you please also try with the most recent transformers release and report what happens?

Version 4.0.1 prints: ['Hug', 'ging', 'face'] 

Explicitly setting the attribute 'do_lower_case' to True solves the problem.

```python
from transformers import RobertaTokenizer
tokenizer = RobertaTokenizer.from_pretrained("roberta-base", do_lower_case=True)
tokenizer.do_lower_case = True
print(tokenizer.tokenize("Huggingface"))
```



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.

If we use the AutoTokenizer library, this still does not work. 

```
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("roberta-base", do_lower_case=True)
tokenizer.do_lower_case = True
print(tokenizer.tokenize("Huggingface"))
```
comet ml integration - add option to continue training
Author: wolhandlerdeb
Pull request: no

### Feature request

when continuing training, it would be great to be able to also continue to log the training metrics to the comet ml experiment. comet_ml has a feature for it : it uses the class ExistingExperiment ( see https://www.comet.ml/docs/python-sdk/ExistingExperiment/ )
Thanks

### Motivation

It would be much more clear and organized if I could continue to log the loss in the same graph when I continue the training of a model.

### Your contribution

No contribution

Comments:
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/main/CONTRIBUTING.md) are likely to be ignored.
Save huggingface checkpoint as artifact in mlflow callback
Author: swethmandava
Pull request: yes

# What does this PR do?

1. Store model checkpoints including tokenizers that are needed to reload the model from mlflow as artifacts
2. Allow model to register-able. (they are not if log_artifacts is used to log the model)

Fixes # (issue)
https://github.com/huggingface/transformers/issues/15495
https://github.com/huggingface/transformers/issues/10881
https://github.com/huggingface/transformers/issues/7698

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

@sgugger 


Comments:
Opened #17686 from branch. closing this

_The documentation is not available anymore as the PR was closed or merged._
Typo in adding_a_new_model README
Author: ayushtues
Pull request: no

There's a typo in the adding_a_new_model README [file](https://github.com/huggingface/transformers/blob/main/templates/adding_a_new_model/README.md), 

It would be `make fix-copies`, not `maxke fix-copies` here
![image](https://user-images.githubusercontent.com/43698245/173199900-0489726e-3373-4567-ac41-96240c41b230.png)
 

Comments:
Sent a PR to fix this [here](https://github.com/huggingface/transformers/pull/17679)
Fix typo in adding_a_new_model README
Author: ayushtues
Pull request: yes

# What does this PR do?



Fixes #17678 


## Before submitting
- [X] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

Documentation: @sgugger

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Move Clip image utils to image_utils.py
Author: alaradirik
Pull request: yes

- Use image_utils functions instead of duplicate functions in clip/feature_extraction_clip.py
- Move convert_rgb to image_utils.py


Comments:
_The documentation is not available anymore as the PR was closed or merged._

Isn't this a breaking change? The CLIP method uses resize with `default_to_square=False`, right?

Yes, my mistake. Will fix it shortly!
Performance of T5
Author: zzasdf
Pull request: no

I'm testing the performance of T5, and want to reproduce the result on WMT  English to German newstest2014 in the table 14. But the results I got were always 1 or 2 points lower. Are there any scripts that can reproduce the result with pytorch?

Comments:
I have found that

> I have found that

Hi, could you please share how you get to reproduce to results?

It's impossible, because the model hasn't been finetune on the translation. The details are on https://github.com/huggingface/transformers/tree/v2.9.0/examples/translation/t5

@zzasdf Thanks a lot!
Fixed documentation typo, parameter name is evaluation_strategy, not eval_strategy
Author: sainttttt
Pull request: yes

Noticed that there was a typo in the documentation here:
https://huggingface.co/docs/transformers/v4.19.4/en/main_classes/trainer#transformers.TrainingArguments

I believe the parameter name should be `evaluation_strategy` and not `eval_strategy`

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Fix dtype getter
Author: sgugger
Pull request: yes

# What does this PR do?

This PR is a better fix for #17656 as I've had time to dive deeper into this issue. The problem does appear when the model is wrapped in a `DataParallel` object, and not just for PyTorch 1.5. 

Comments:
_The documentation is not available anymore as the PR was closed or merged._

Errors seem all related to the current Hub failure, still, will wait for the site to be back online to relaunch them since this is not urgent :-)
Update eli5_app.py
Author: cyai
Pull request: yes

# What does this PR do?



Fixes # (issue)
Updated the string format style for a cleaner understanding of the code.

## Before submitting
- [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR 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.

Models:

- albert, bert, xlm: @LysandreJik
- blenderbot, bart, marian, pegasus, encoderdecoder,  t5: @patrickvonplaten, @patil-suraj
- longformer, reformer, transfoxl, xlnet: @patrickvonplaten
- fsmt: @stas00
- funnel: @sgugger
- gpt2: @patrickvonplaten, @LysandreJik
- rag: @patrickvonplaten, @lhoestq
- tensorflow: @LysandreJik

Library:

- benchmarks: @patrickvonplaten
- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam
- text generation: @patrickvonplaten
- tokenizers: @n1t0, @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

Documentation: @sgugger

HF projects:

- datasets: [different repo](https://github.com/huggingface/datasets)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Examples:

- maintained examples (not research project or legacy): @sgugger, @patil-suraj
- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_17683). All of your documentation changes will be reflected on that endpoint.
Explicitly set utf-8 for Windows in utils required for make fixup
Author: BramVanroy
Pull request: yes

# What does this PR do?

Had a little issue that I could not successfully run `make fixup` due to encoding issues. Windows still does not use UTF-8 by default unfortunately.

When looking through the whole codebase, I found other occurrences where the encoding has not been specified. These are _not_ fixed in this PR. This PR focuses on just the changes needed to at least allow the make commands to work.



## Before submitting
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests), Pull Request section?


## Who can review?

Tagging @LysandreJik who hinted me to use `make fixup` (here https://github.com/huggingface/transformers/pull/17629#issuecomment-1152359001)



Comments:
_The documentation is not available anymore as the PR was closed or merged._