noamaanMulla-03/transformers-issues huggingface dataset:
AutoTokenizer behavior changing when enable_full_determinism is set to zero
Author: clefourrier
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.20.1
- Platform: Linux-5.14.0-1045-oem-x86_64-with-glibc2.29
- Python version: 3.8.10
- Huggingface_hub version: 0.8.1
- PyTorch version (GPU?): 1.11.0+cu102 (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

### Who can help?

@SaulLu 
However, I am quite sure this is a problem with `enable_full_determinism` rather than with tokenizers, but I don't know who to tag on that @LysandreJik 

### Reproduction

MWE:
```python
from datasets import load_dataset
from transformers import AutoTokenizer
from transformers import enable_full_determinism

# Loading tokenizer
tk = AutoTokenizer.from_pretrained("prajjwal1/bert-tiny");
tk.model_max_length = 512
def tokenize_function(examples):
    return tk(examples["text"], truncation=True, max_length=512)

# Loading dataset 
data = load_dataset('yelp_review_full')["train"].select(range(2000))
data = data.train_test_split(0.2)

data_tk = data.map(tokenize_function)  
print(max([len(b) for b in data_tk["test"]["input_ids"]])) # 512
enable_full_determinism(0)
data_tk = data.map(tokenize_function)  
print(max([len(b) for b in data_tk["test"]["input_ids"]])) # 965 !!!!!!!
enable_full_determinism(1)
data_tk = data.map(tokenize_function)  
print(max([len(b) for b in data_tk["test"]["input_ids"]])) # 512
enable_full_determinism(2)
data_tk = data.map(tokenize_function)  
print(max([len(b) for b in data_tk["test"]["input_ids"]])) # 512
```

### Expected behavior

The AutoTokenizer should systematically apply truncation, even when the seed of `enable_full_determinism` is set to 0. 
Seeds different than 0 do not seem to create problems.
 
(I suspect the seed is cast to a boolean somewhere, since the boolean of an integer is always True, except when the integer is 0).

Comments:
Hi @clefourrier ,

From your description, I agree with you that the output should always be 512. However, I can't reproduce your problem (I tried with the same version of `transformers` and `torch`), I let you see my attempt to reproduce your error in this [google colab notebook](https://colab.research.google.com/drive/1R_b8u6envps2yKFrPykVunfwF8NFrzkd?usp=sharing).

I wonder if this could be caused by a cache problem for you, could you try again with:
```python
enable_full_determinism(0)
data_tk = data.map(tokenize_function, load_from_cache_file=False)  
print(max([len(b) for b in data_tk["test"]["input_ids"]]))
```



@SaulLu 

It's not happening with `load_from_chache=False`, nor after restarting my kernel. I agree with you, must have been a cache problem (> closing). Thank you for having taken a look :hugs:
fixed _toctree.yml
Author: nickprock
Pull request: yes

# What does this PR do?

I update the _toctree.yml after the [last fixes and review on training.mdx](https://github.com/huggingface/transformers/pull/18333#event-7080871662)

![immagine](https://user-images.githubusercontent.com/11136646/181508592-a7336f29-52de-4f01-baf9-e8b0a8b70741.png)


See issue: [#17459](https://github.com/huggingface/transformers/issues/17459)

## 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?
- [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.
- [X] 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).


## 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.

@omarespejel @sgugger

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Numpy arrays used instead of jax array in example
Author: sunitharavi9
Pull request: no
Labels: name: bug

### System Info

The example[ here](https://github.com/huggingface/transformers/blob/main/examples/flax/text-classification/run_flax_glue.py#L286) should yield jax device arrays instead of numpy arrays. 

@patil-suraj

### Who can help?

_No response_

### 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

https://github.com/huggingface/transformers/blob/main/examples/flax/text-classification/run_flax_glue.py#L286

### Expected behavior

Should return batches with jax device arrays

Comments:
Answered in https://github.com/huggingface/transformers/issues/18289#issuecomment-1198216304
DETR: Add comment regarding backbones
Author: LysandreJik
Pull request: yes

Adds an informative message in DETR to mention that the backbone gets initialized for its architecture and not necessarily for its weights.

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_17572). 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 the wrong sample-rate of random tokens
Author: kamenrider002
Pull request: yes

# What does this PR do?
Fix the wrong sample-rate of random tokens from `0.1` to `0.5` in the `DataCollatorForLanguageModeling` and `DataCollatorForWholeWordMask`.

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

Hello! Why is it wrong?

> Hello! Why is it wrong?

Sorry for late! we should replace 10% masked input tokens with random word, but the code means replacing 10% from the remaining tokens not replaced with [MASK] token. So, we only replace 0.2 * 0.1 tokens, it should be 0.2 * 0.5 ?!

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.
tensorflow-aarch64 is not a viable candidate tensorflow version
Author: ankrgyl
Pull request: no
Labels: name: bug

### System Info

On ARM64 machines, the official tensorflow package is named `tensorflow-aarch64`. On transformers==4.20.1, in `utils/import_utils.py`, there is a list of `candidates` for tensorflow packages which does not include this package. As a result, you cannot use TF+transformers on arm64 machines that have installed tensorflow via this package.

### Who can help?

_No response_

### Information

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

### Tasks

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

### Reproduction

On an ARM64 machine `pip install tensorflow-aarch64 transformers` and then try using a tensorflow transformer.

### Expected behavior

If you've installed `tensorflow-aarch64` you should be able to use tensorflow with transformers.

Comments:
Hey @ankrgyl, would you like to open a PR to enable that candidate?

Happy to! I am a bit rusty on the PR process but here it is: https://github.com/huggingface/transformers/pull/18345

Closed in https://github.com/huggingface/transformers/pull/18345

Thanks for your contribution!
Include tensorflow-aarch64 as a candidate
Author: ankrgyl
Pull request: yes

# Include tensorflow-aarch64 as a candidate

Fixes # 18323
@LysandreJik


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

(I'm waiting for the tests to pass before merging)

Thank you! What is the next step -- do I close it or merge it somehow? Apologies for my unfamiliarity with the process.

I'll merge it as soon as everything is green :)

Okay great! Thank you for your responsiveness.

Done! Thanks for your contribution @ankrgyl!
Migrate metric to Evaluate library for tensorflow examples 
Author: VijayKalmath
Pull request: yes

# What does this PR do?
Currently, tensorflow examples use the `load_metric` function from Datasets library, commit migrates function call to `load` function to Evaluate library.

Fix for #18306

## 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 documentation is not available anymore as the PR was closed or merged._

@sgugger, Working on the other examples. 

In contrast to pytorch examples, in the tensorflow examples, some of the different tasks  (summarization, translation token-classification ) are missing requirements.txt. 


Should I add a requirements.txt to these folders? I believe this will aid in the future when we are building tests for these examples.

Yes please, that would be great!

@sgugger, all the examples have now been migrated. Will make PR open for review/merge
[Docs] Fix Speech Encoder Decoder doc sample
Author: sanchit-gandhi
Pull request: yes

# What does this PR do?

Fixes #18343


## 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.

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Fix OwlViT torchscript tests
Author: ydshieh
Pull request: yes

# What does this PR do?

Fix `OwlViTForObjectDetection` torchscript tests. The main problem comes from the fact that we provide

```python
traced_model = torch.jit.trace(model, (input_ids, pixel_values))
```
but `OwlViTForObjectDetection` has different order of arguments.

I could simply change the order in the test method, but probably it is better to have `OwlViTForObjectDetection` and `OwlViTModel` have the same argument order .

[current failed job run](https://github.com/huggingface/transformers/runs/7552486052?check_suite_focus=true)

Comments:
_The documentation is not available anymore as the PR was closed or merged._
TF element-wise equals requires tf.equals() instead of == 
Author: ekayen
Pull request: no
Labels: name: bug

### System Info

```shell
Running in a Google Colab with GPU backend.
```


### Who can help?

@Narsil 

### 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

Running the 'fill-mask' pipeline:

```
import tensorflow.compat.v1 as tf
import tensorflow_datasets
import transformers
from transformers import pipeline, set_seed

# Load tokenizer and model from presaved locations:

tokenizer = transformers.GPT2Tokenizer.from_pretrained('/path/to/pretrained/GPT2/')
tokenizer.add_special_tokens({'pad_token': '[PAD]'})
model = transformers.TFGPT2LMHeadModel.from_pretrained('/path/to/pretrained/GPT2/')

# Create pipeline with this model and tokenizer:
unmasker = pipeline('fill-mask', model=model, tokenizer=tokenizer)
print(unmasker("Hello I'm a [MASK] model"))
```

This produces the following error: 

`{{function_node __wrapped__Where_device_/job:localhost/replica:0/task:0/device:GPU:0}} WhereOp: Unhandled input dimensions: 0 [Op:Where] `

My best guess is that this is because of line 56 of fill_mask.py:

`masked_index = tf.where(input_ids == self.tokenizer.mask_token_id).numpy()`

TF requires `tf.equals(tensor1, tensor2)` instead of `==`. This bug may occur elsewhere as well -- I haven't checked exhaustively. 


### Expected behavior

```shell
A dictionary object with the keys `sequence`, `score`, and `token` is printed.
```


Comments:
Hi @ekayen 👋 

`self.tokenizer.mask_token_id` (on [L56 in fill_mask.py](https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/fill_mask.py#L56)) should be a single integer, and `tf.where(tensor == integer)` works well in TF1 and TF2 (see the examples below)

```python
import tensorflow as tf
a = tf.range(10)
b = tf.where(a == 5)
print(b)
```

```python
import tensorflow.compat.v1 as tf
a = tf.range(10)
b = tf.where(a == 5)
print(b)
```

From the error message, we can read "... Unhandled input dimensions: 0". Can you confirm that your tokenizer has `tokenizer.mask_token_id` set? That would be my biggest suspicion :)

P.S.:
1 - `transformers` does not support TF1 behavior -- it is possible that things break, and we won't be able to provide help in that situation :( I'd highly recommend updating your project to TF2, if you have the resources to do so.
2 - Our bandwidth as maintainers of a large project is very limited. When opening an issue, if you can provide an example that can run on any machine (and that does not depend on local files), the odds of getting a useful response are much higher 🙌 


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.
Dataset Format for training RAG on custom Dataset
Author: mdshah930
Pull request: no
Labels: name: bug

### System Info

```shell
- `transformers` version: 4.19.2
- Platform: Linux-4.14.219-164.354.amzn2.x86_64-x86_64-with-glibc2.2.5
- Python version: 3.7.9
- Huggingface_hub version: 0.4.0
- PyTorch version (GPU?): 1.10.1+cu102 (True)
- Tensorflow version (GPU?): 2.3.0 (False)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: yes
- Using distributed or parallel set-up in script?: no
```


### Who can help?

_No response_

### Information

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

### Tasks

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

### Reproduction

Steps to reproduce error -  No format mentioned for data preparation for training RAG on custom dataset.
[link to script](https://github.com/huggingface/transformers/blob/main/examples/research_projects/rag/finetune_rag.py)
[broken link to format in which data needs to be prepared](https://github.com/huggingface/transformers/tree/main/examples/research_projects/rag#:~:text=Our%20finetuning%20logic%20is%20based%20on%20scripts%20from%20examples/seq2seq.%20We%20accept%20training%20data%20in%20the%20same%20format%20as%20specified%20there%20%2D%20we%20expect%20a%20directory%20consisting%20of%206%20text%20files%3A)

### Expected behavior

```shell
https://github.com/huggingface/transformers/blob/main/examples/research_projects/rag/finetune_rag.py
This is a script to fine tune rag on a custom dataset, however the link mentioned on github (format in which data needs to be prepared if training on custom dataset) is broken. Please let me know in what format do I have to prepare my training data if I want to train RAG on a custom dataset

https://github.com/huggingface/transformers/tree/main/examples/research_projects/rag#:~:text=Our%20finetuning%20logic%20is%20based%20on%20scripts%20from%20examples/seq2seq.%20We%20accept%20training%20data%20in%20the%20same%20format%20as%20specified%20there%20%2D%20we%20expect%20a%20directory%20consisting%20of%206%20text%20files%3A
```


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.
Global/local import with replicated name in the Trainer leading to UnboundLocalError
Author: JingyaHuang
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.21.0
- Platform: Linux-5.4.0-121-generic-x86_64-with-glibc2.29
- Python version: 3.8.10
- Huggingface_hub version: 0.8.1
- PyTorch version (GPU?): 1.11.0+cu113 (True)

### Who can help?

@pacman100  @sgugger 

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

Running the `run_glue`([optimum version](https://github.com/huggingface/optimum/blob/main/examples/onnxruntime/training/text-classification/run_glue.py)) with the distributed launcher
```
python -m torch.distributed.run --nproc_per_node=2 run_glue.py --model_name_or_path microsoft/deberta-v2-xxlarge --task_name MRPC --do_train --output_dir /tmp/deberta_res --fp16 --sharded_ddp simple --num_train_epochs 1
```
Error message:
```
Traceback (most recent call last):
  File "run_glue.py", line 610, in <module>
    main()
  File "run_glue.py", line 503, in main
    trainer = ORTTrainer(
  File "/workspace/optimum/onnxruntime/trainer.py", line 144, in __init__
    super().__init__(
  File "/usr/local/lib/python3.8/dist-packages/transformers/trainer.py", line 569, in __init__
    self.scaler = ShardedGradScaler()
UnboundLocalError: local variable 'ShardedGradScaler' referenced before assignment
```

### Expected behavior

`ShardedGradScaler` was firstly imported as global variable
https://github.com/huggingface/transformers/blob/da503ea02f7623542bd588b509d0fc31aff92735/src/transformers/trainer.py#L190
Then it was imported as a local variable for fsdp with the same name
https://github.com/huggingface/transformers/blob/da503ea02f7623542bd588b509d0fc31aff92735/src/transformers/trainer.py#L568
And it won't fall back to the global `ShardedGradScaler`, even when the local one is not imported leading, to an UnboundLocalError.

P.S. However I don't have problem running the `run_glue.py` in transformers, the problem seems to occur when using classes inherited from `Trainer`. 

Possible solution: use different name / both import locally

*REF:*
*https://docs.python.org/3/faq/programming.html#why-am-i-getting-an-unboundlocalerror-when-the-variable-has-a-value*
*https://stackoverflow.com/questions/58750517/why-unboundlocalerror-occurs-when-importing-inside-function*

Comments:
Hello @JingyaHuang, thank you for bringing this to the notice with detailed steps and possible solutions 🤗. Can you try the above draft PR and see if that fixes the issue?
fix FSDP ShardedGradScaler
Author: pacman100
Pull request: yes

# What does this PR do?

1. Fixes #18350 by renaming the import for FSDP ShardedGradScaler so that it doesn't change the scope of globally imported Fairscale ShardedGradScaler
2. Another minor change of raising error when transformer auto wrap class name is not found in the model.

## 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?
- [ ] 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?


Comments:
_The documentation is not available anymore as the PR was closed or merged._
Raise a TF-specific error when importing Torch classes
Author: Rocketknight1
Pull request: yes

We've had a couple of reports from users that the class naming is confusing - they import `AutoModel` but don't realize that it's a PyTorch-only class, and the error message doesn't give them any guidance except to tell them to install PyTorch.

This PR adds a check to `requires_backends`, so that if the user tries to import a class that requires PyTorch when they don't have it installed, but they do have TF installed instead, it will raise an error that explains the situation and directs them to the TF classes.

Fixes #18220.

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

@LysandreJik I'm not sure! I think it's more obvious that "TFAutoModel" is TF-specific, and it's only the PyTorch classes that don't specify the framework in their names. But I guess it's okay to add the inverse error too, one sec!

@Rocketknight1 NICE! -- Thanks for implementing this.  You rock!