noamaanMulla-03/transformers-issues huggingface dataset:
Unable to Import KeyDataset for Pipeline Iterator in 4.16.2
Author: ncoop57
Pull request: no

## Environment info
- `transformers` version: 4.16.2
- Platform: Linux-5.4.144+-x86_64-with-Ubuntu-18.04-bionic
- Python version: 3.7.12
- PyTorch version (GPU?): 1.10.0+cu111 (False)
- Tensorflow version (GPU?): 2.7.0 (False)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: NA
- Using distributed or parallel set-up in script?: NA

### Who can help

- Pipelines: @Narsil
- Documentation: @sgugger

## To reproduce

Steps to reproduce the behavior:

Follow the commands in this google colab: https://colab.research.google.com/drive/1BkvrzISZbt_N0S6ntgG7_fN3LdfJE2DH?usp=sharing

Attempting to import KeyDataset
```
from transformers.pipelines.base import KeyDataset
```

Produces the following error:
```
ImportError: cannot import name 'KeyDataset' from 'transformers.pipelines.base'
```

## Expected behavior

Successfully import KeyDataset to perform the example in the documentation for batch processing pipeline predictions (https://huggingface.co/docs/transformers/v4.16.2/en/main_classes/pipelines#pipeline-batching):
```
from transformers import pipeline
from transformers.pipelines.base import KeyDataset
import datasets

dataset = datasets.load_dataset("imdb", name="plain_text", split="unsupervised")
pipe = pipeline("text-classification", device=0)
for out in pipe(KeyDataset(dataset, "text"), batch_size=8, truncation="only_first"):
    print(out)
```

Comments:
Everything works fine in 4.15.0, so not sure if this was deprecated/removed on purpose and the documentation is outdated or what, but any help is greatly appreciated!

Hi, thanks for reporting! 🤗 

The KeyDataset class is now in `transformers.pipelines.pt_utils` and #15607 should update this part of the docs.

We should do the re-export from within `transformers.pipelines.__init__.py` this is a breaking change which shouldn't be there.

We should also fix the doc example to show the proper import path.

Mostly, if it's an object we expect users to import in common cases, it should be in the main init, so it can be accessible at the root level, and we can change our internals without worry of breaking changes.

Update the doc too (kept the re-export for now)
Fix TFSequenceSummary's activation
Author: ydshieh
Pull request: yes

[TFSequenceSummary](https://github.com/huggingface/transformers/blob/52d2e6f6e904ef9b75c78716ce77b98196ed837a/src/transformers/modeling_tf_utils.py#L1910) set its `activation` only when `config.summary_activation == "tanh"`.

https://github.com/huggingface/transformers/blob/52d2e6f6e904ef9b75c78716ce77b98196ed837a/src/transformers/modeling_tf_utils.py#L1960

However, [ElectraConfig](https://github.com/huggingface/transformers/blob/52d2e6f6e904ef9b75c78716ce77b98196ed837a/src/transformers/models/electra/configuration_electra.py#L137) has default value `"gelu"` for `summary_activation`, and therefore [TFElectraForMultipleChoice](https://github.com/huggingface/transformers/blob/52d2e6f6e904ef9b75c78716ce77b98196ed837a/src/transformers/models/electra/modeling_tf_electra.py#L1427) doesn't use activation at all for `self.sequence_summary`.

This is different from PyTorch version: [SequenceSummary](https://github.com/huggingface/transformers/blob/52d2e6f6e904ef9b75c78716ce77b98196ed837a/src/transformers/modeling_utils.py#L2198)
https://github.com/huggingface/transformers/blob/52d2e6f6e904ef9b75c78716ce77b98196ed837a/src/transformers/modeling_utils.py#L2242
(which has no condition on `tanh`).

This inconsistency also makes the extended pt/tf equivalence fail for `electra` model.

This PR fixes the above issue.


TF: @gante @Rocketknight1

cc @patil-suraj for his somehow related work on adding `ElectraForMultipleChoice` (#4954) with `gelu` for `summary_activation`

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

LGTM too - @ydshieh are you ready for me to merge this?

> LGTM too - @ydshieh are you ready for me to merge this?

Yes, go ahead :-) Thanks!
Updated the RAG training with latest Pytorch Lightning library and the RAY
Author: shamanez
Pull request: yes

# What does this PR do?
Updated the RAG script with the latest libraries.


## 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/master/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/master/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/master/docs#writing-source-documentation).
- [x] Did you write any new necessary tests? not applicable


## Who can review?
@patrickvonplaten 



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

@shamanez are you planning to also update the end2end rag example? 

> @shamanez are you planning to also update the end2end rag example?

Yes soon. I am also thinking of merging RAG with [Retro-like](https://deepmind.com/research/publications/2021/improving-language-models-by-retrieving-from-trillions-of-tokens) training.
Usage examples for logger
Author: FrancescoSaverioZuppichini
Pull request: yes

# What does this PR do?

This PR adds a couple of usage examples in the `logging` doc


Fixes # (issue)

## Before submitting
- [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).



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

Thanks for the comments!
how can i write tensorboard when i train model with the script "run_speech_recognition_ctc.py" 
Author: JucyCherry
Pull request: no

I found that there was no "outputdir/runs/" directory created  during training ，is there any params to write tensorboard？
 @sgugger @patrickvonplaten @anton-l 

## Environment info
transformers 4.16.0.dev0


Comments:
Hey @JucyCherry,

Thanks for the issue! I think all you need to do is the following:

1. Install `tensorboard`: https://pypi.org/project/tensorboard/
2. Run training. The Trainer in the `run_speech_recognition_ctc.py` script automatically correctly uses the `tensorboard`.

You could try out the explanation to check if it works: https://github.com/huggingface/transformers/tree/master/examples/research_projects/robust-speech-event#how-to-finetune-an-acoustic-model

thanks a lot !
Warn if using a CTC+LM model with no decoder (asr pipeline)
Author: FremyCompany
Pull request: yes

When feeding a model to the automatic-speech-recognition pipeline, if the decoder is forgotten, the model is used as normal ctc without language model applied. This is likely to be accidental, and might go unnoticed. To address this, I propose to add a warning.

cc @LysandreJik 

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

It would be nice to document the `decoder` parameter, because I did not include it because it is not documented anywhere, but this is a separate issue I guess. Closing this pull request based on review feedback.
🔥 Remove build_doc_test github action
Author: coyotte508
Pull request: yes

# What does this PR do?

The build_dev_documentation already builds the doc on every PR. I don't think that build_doc_test is needed

## 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/master/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/master/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/master/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 documentation is not available anymore as the PR was closed or merged._
Output ragged tensors from TF predict()
Author: Rocketknight1
Pull request: yes

This is a very simple and dumb PR right now, but I think it's a lot less broken than our current implementation! Obviously don't merge it yet, I'm going to poke around to try to find edge cases and see if it resolves our memory leak issues.

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

Closing this as we're going to fix this with an upstream PR to Keras instead
[Benchmark]
Author: MannanRajib
Pull request: no

# 🖥 Benchmarking `transformers`

## Benchmark

Which part of `transformers` did you benchmark?

## Set-up

What did you run your benchmarks on? Please include details, such as: CPU, GPU? If using multiple GPUs, which parallelization did you use?

## Results

Put your results here!


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/master/CONTRIBUTING.md) are likely to be ignored.
Fix Funnel configuration doc
Author: ydshieh
Pull request: yes

# What does this PR do?

The part `standard deviation` should be `upper bound` in

https://github.com/huggingface/transformers/blob/cdc51ffd27f8f5a3151da161ae2b5dbb410d2803/src/transformers/models/funnel/configuration_funnel.py#L79-L80

as it is used for `nn.init.uniform_`:

https://github.com/huggingface/transformers/blob/cdc51ffd27f8f5a3151da161ae2b5dbb410d2803/src/transformers/models/funnel/modeling_funnel.py#L774-L778

@sgugger 

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

Sorry, messed up with another PR. I will open another one
Fix Funnel configuration doc
Author: ydshieh
Pull request: yes

# What does this PR do?

The part `standard deviation` should be `upper bound` in

https://github.com/huggingface/transformers/blob/cdc51ffd27f8f5a3151da161ae2b5dbb410d2803/src/transformers/models/funnel/configuration_funnel.py#L79-L80

as it is used for `nn.init.uniform_`:

https://github.com/huggingface/transformers/blob/cdc51ffd27f8f5a3151da161ae2b5dbb410d2803/src/transformers/models/funnel/modeling_funnel.py#L774-L778

@sgugger 

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

Can you run `make style` on your brnach to fix the quality issue?

> Can you run `make style` on your brnach to fix the quality issue?

Sure - I forget doing so quite often (will try to be more careful!).

Thanks a lot!
cannot import name 'CONFIG_MAPPING' from 'transformers' (unknown location)
Author: OmarMohammed88
Pull request: no

trying using the Run_MLM.py script but got an error in importing modules
I installed the transformers package from the source 
```
!git clone https://github.com/huggingface/transformers.git
%cd transformers
!pip install -e .
!pip install -r 'examples/pytorch/language-modeling/requirements.txt
```
any solutions ?
thanks in advance


Comments:
Add PoolFormer
Author: tanaymeh
Pull request: yes

# What does this PR do?

This PR adds the PoolFormer model to the 🤗 repository.

I also opened an Issue for adding the model https://github.com/huggingface/transformers/issues/14584

# Who can review?
@NielsRogge 

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

Thanks for all your work on this, merging!
Minor fix on README.md
Author: ydshieh
Pull request: yes

# What does this PR do?

Minor fix on README.md, including
- Think we want to provide links to arXiv paper info. pages, not the direct PDF file links (?).
- Paper title for `RoBERTa`
- Remove ending `)` in `ViTMAE` and `ViLT`.

@LysandreJik @NielsRogge @sgugger 

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Incorrect information in "Getting started" regarding API tokens
Author: ToonTalk
Pull request: no

https://api-inference.huggingface.co/docs/curl/html/quicktour.html#get-your-api-token states

You should see a token api_XXXXXXXX or api_org_XXXXXXX.

But the keys start with hf_

Also https://huggingface.co/docs/hub/security#user-access-tokens describes the read and write tokens without mention of API tokens

Comments:
The `hf_` tokens will work. 

Will update the doc which is out of date (well the old tokenizer `api_` `api_org` still work, we just don't generate new ones anymore).

Updated ! closing this issue, feel free to reopen.
explicitly load local file
Author: sipie800
Pull request: no

The from_pretrained() pipline is making me very confusing.
Sometime it requires a model_id, sometime it want a local path, and the path can't be similar to the id. Why must I know if the dir I put the download files would conflicts to any model id?what's the point here?
Why don't go for the simplest pipeline, just down files and specify the file path of weight, config.json and so on!
And if url is need, just specify the urls!
And besides there is a cache_dir parameter also messes with the model_name_or_path.
Don't like make everything cloud-based, it's not making thing better but more complicated.
Time to time when I tried to init a model with pretrained, the program seems to walk around between 3 places, the huggingface website, the cache path local and the path where I put download files, and that often cause troubles if we want to use a specified version or we just need the one of the 3 ways to work. It should not be forced to use 3 palces in one parameter, which is just not good for most of the users.

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/master/CONTRIBUTING.md) are likely to be ignored.
Add SimMIM
Author: NielsRogge
Pull request: yes

# What does this PR do?

This PR adds an `AutoModelForMaskedImageModeling` API to the library with a corresponding `run_mim.py` script. 

It allows to pre-train the following Transformer-based vision models:

* ViT
* DeiT
* BEiT
* Swin Transformer

based on Microsoft's cool (and simple) [SimMIM](https://arxiv.org/abs/2111.09886) paper (note that this won't work for convolution based models such as ConvNeXT).

This requires a tiny tweak in each modeling file, unfortunately. However, it's quite minimal, namely I added the ability to add a `mask_token` trainable parameter. This is a bit different compared to NLP models, which have the mask token inside their embedding layer (`nn.Embedding`).

The `run_mim.py` script is directly inspired by `run_mlm.py`, but adapted to work for vision.



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

Updated the PR to not include BEiT.
Add `with torch.no_grad()` to DistilBERT integration test forward pass
Author: jaketae
Pull request: yes

# What does this PR do?

This PR encapsulates forward passes in DistilBERT unit tests with `with torch.no_grad():` as per #14642.

Also, a unit test seemed to terminate early due to a `return` in a loop; this was replaced with `continue`. (If this was not what was intended, I will rollback the modification.)

## 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/master/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/master/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/master/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

@NielsRogge @LysandreJik @sgugger 

Comments:
Thank you for the feedback and confirmation! I've reverted the change. 

Hello @jaketae, were your last changes committed? I still see a lot of non-integration tests with `torch.no_grad`

@LysandreJik Apologies for the delay! I thought I had properly committed and pushed the changes but seems like that wasn't the case. Reverted most of the `no_grad` context and modified only the integration test. Thank you!
Adding a model, more doc for pushing to the hub
Author: FrancescoSaverioZuppichini
Pull request: yes

# What does this PR do?

This PR adds a usage example for pushing to the hub, a useful link to our hub page and a couple of comments.

## Before submitting
- [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).


Comments:
_The documentation is not available anymore as the PR was closed or merged._
UserWarning: __floordiv__ is deprecated
Author: ypirkani
Pull request: no

Dear All, 

I am trying to Fine-tune XLSR for Speech Recognition "facebook/wav2vec2-base" model for Urdu Language.

However when I run the trainer, I am getting the following warning:
```
/home/e-team/anaconda3/lib/python3.9/site-packages/transformers/models/wav2vec2/modeling_wav2vec2.py:704: UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').
  return (input_length - kernel_size) // stride + 1
```
Also Consequently my WER is 1.00 which means training is not being done correctly.
 Can anyone guide ? What changes to make and where? 

Torch Version: 1.10.1+cu102
Python Version: 3.9.7
CUDA Version: 11.2 
Tensorflow Version: 2.7.0


![image](https://user-images.githubusercontent.com/42676982/148747322-aee21356-a4ee-4b11-a81d-8176ccf214ae.png)

Best regards,
Yasir
 

Comments:
The same warning is shown for LayoutLMv2, see #14577 

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.

Fixed by https://github.com/huggingface/transformers/pull/15180

Running in the same issue for the `DetrModel` model: https://github.com/huggingface/transformers/blob/c962c2adbff678ae6d2e98378bed5b8d1a9831d9/src/transformers/models/detr/modeling_detr.py#L422

Happy to submit a quick PR using the `torch_int_div` function added in https://github.com/huggingface/transformers/pull/15180:

```python
dim_t = self.temperature ** (2 * torch_int_div(dim_t, 2) / self.embedding_dim)
```

EDIT: I've submitted the PR (#15702) since it was a quick fix.
Fix LongformerModel hidden states
Author: ydshieh
Pull request: yes

# What does this PR do?

`LongformerModel` currently returns `hidden_states` that is padded, while `TFLongformerModel` and `LEDEncoder` return un-padded version.

This PR makes `LongformerModel` return the un-padded `hidden_states` .

----

`LEDEncoder` also returns  un-padded `attentions`. Maybe the same logic should be applied to `LongformerModel` too.

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

The test needs to be adjusted due to the change. But I would like to have some feedback first before proceeding.

@patrickvonplaten could you take a look here ?

Thanks for reviewing! I will finalize this PR by adjusting the test.

@patrickvonplaten @patil-suraj 

(update)
- unpad `attentions` too for both `LongformerModel` / `TFLongformerModel`. (see below for the reasons)
- move unpadding logic in `(TF)LongformerModel` to `(TF)LongformerEncoder`
- update the tests

----

# unpad `attentions`

Current  `LongformerModel` / `TFLongformerModel` don't unpad `attentions`. I am going to unpad the `attentions` just like what have been done for `LEDModel` & `TFLEDModel`. 

This is required to make `TFLongformerModelTest` pass (in an easy way).

(I don't think there is particular reason not to unpad `attentions` in `LongformerModel` / `TFLongformerModel`, but want to make sure)

## More details

In `LEDModel` & `TFLEDModel`, the `attentions` are also un-padded:

https://github.com/huggingface/transformers/blob/57882177becb85560f1ff931abb1b0b75d67e70d/src/transformers/models/led/modeling_led.py#L1871-L1872

https://github.com/huggingface/transformers/blob/57882177becb85560f1ff931abb1b0b75d67e70d/src/transformers/models/led/modeling_tf_led.py#L1814-L1819



However, `LongformerModel` / `TFLongformerModel` don't perform unpadding for `attentions` (but do unpadding for `hidden_states`). This causes a problem for `TFLongformerModelTester`:

https://github.com/huggingface/transformers/blob/57882177becb85560f1ff931abb1b0b75d67e70d/tests/test_modeling_tf_longformer.py#L77-L81

The testings for both `attentions` and `hidden_states` are controlled by `self.encoder_seq_length` => so we need to unpad `attentions` too (because `hidden_states` are unpadded).
Typo in https://api-inference.huggingface.co/docs/curl/html/detailed_parameters.html#summarization-task
Author: ToonTalk
Pull request: no

It says "0 mens top_k=1, 100.0 is getting closer to uniform probability."

mens should be means

Comments:
Thank you for noticing the typo, @ToonTalk! `api-inference` is an internal repository, and I've submitted the fix.

Thank you for reporting this ! @ToonTalk 

(Fixed in the docs)