noamaanMulla-03/transformers-issues huggingface dataset:
Fixed incorrect error message on missing weight file.
Author: 123jimin
Pull request: yes

# What does this PR do?
I just started using Hugging Face Transformers for the first time, and encountered this error.

    OSError: Error no file named pytorch_model.bin found in directory (...) but there is a file for Flax weights. Use `from_flax=True` to load this model from those weights.

Indeed, I forgot to download `pytorch_model.bin`, but the model I tried to use was not using Flax, so I dug a little bit to see which file was the library looking for.

For me it seems that there was a simple mistake...

## 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.

<!-- 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._
Fix typo of variable names for key and query projection layer
Author: Kyeongpil
Pull request: yes

self.pos_proj and self.pos_q_proj should be changed to self.pos_key_proj and self.pos_query_proj as same as PyTorch implements.

# What does this PR do?
Fix typo of the variable names in DeBERTaV2


Comments:
_The documentation is not available anymore as the PR was closed or merged._
Fix wav2vec2 export onnx model with attention_mask error
Author: nilboy
Pull request: yes

# What does this PR do?
This PR fixes a problem with wav2vec2 when convert to onnx model with attention_mask. see: https://github.com/huggingface/transformers/issues/10004, https://github.com/pytorch/fairseq/issues/3010#issuecomment-999821804

@patrickvonplaten 



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

Looks good to me! cc @lewtun 

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.

Should this be merged?

Yes I think this can be merged since it's only touching the modelling code and the Wav2Vec2 ONNX export that I'm working on will anyway need this. 

I'll merge once the CI passes

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.

@patrickvonplaten @lewtun we probably still need to merge this, if there are no objections :sweat_smile: 

> Sorry just one question - why do we use `repeat` here instead of https://pytorch.org/docs/stable/generated/torch.broadcast_to.html ? Broadcasting should save some memory no?
> 
> Also could we please run all the Wav2Vec2 slow tests ones to make sure there is no unexpected numerical difference?

Yes @anton-l - I'm waiting for a reply to Patrick's comment above. Alternatively, if Patrick agrees we can merge this "as is" (looks good to me)

Good to merge for me if all Wav2Vec2 slow tests pass (including the pretraining ones). @anton-l could you check it maybe otherwise?

Slow+pretraining tests are OK, thanks for the fix @nilboy!
Refactor classes to inherit from nn.Module instead of nn.Sequential
Author: amyeroberts
Pull request: yes

# What does this PR do?

Refactors classes that inherit from `nn.Sequential` to inherit from `nn.Module` instead. This is to make the code easier to debug and inspect.

Changes: 
* Explicit `forward` method implemented for classes
* Iterating over layers and them registering to the module using `add_module(str_ind, layer)` in `__init__`. This provides backwards compatibility as the submodules will be named according to their position in the call stack, like in nn.Sequential, which is needed to load in the same checkpoints.  

Note: This does not include other possible `nn.Sequential` refactoring within modules e.g. [lxmert](https://github.com/huggingface/transformers/blob/6ee1474b67b088829555364a14ebfb45e661fac4/src/transformers/models/lxmert/modeling_lxmert.py#L721), or inheriting from `ModuleList` e.g. in [Beit](https://github.com/huggingface/transformers/blob/2ef09ecfb8afb6624aab87afdad9fe72030397af/src/transformers/models/beit/modeling_beit.py#L962). These are more involved changes and should be address in separate PRs.

## 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?

## Who can review?

Anyone in the community is free to review the PR once the tests have passed. 


Comments:
_The documentation is not available anymore as the PR was closed or merged._
Debug LukeForMaskedLM
Author: ryokan0123
Pull request: yes

# What does this PR do?
Fix some undesirable behaviors of `LukeForMaskedLM`.

#### 1. Make `LukeForMaskedLM` accept inputs without entity ids

**Before❌:**
```
>>> from transformers import LukeForMaskedLM, MLukeTokenizer
>>> import torch

>>> text = "test string"
>>> model = LukeForMaskedLM.from_pretrained('studio-ousia/luke-base')
>>> tokenizer = MLukeTokenizer.from_pretrained('studio-ousia/luke-base')
>>> encoding = tokenizer(text, return_tensors="pt")
>>> outputs = model(**encoding)
TypeError: linear(): argument 'input' (position 1) must be Tensor, not NoneType
```

I have fixed this by making entity inputs optional in the forward function.

#### 2. Make `LukeForMaskedLM` instantiable from `AutoModelForMaskedLM`

**Before❌:**
```
>>> from transformers import AutoModelForMaskedLM
>>> model = AutoModelForMaskedLM.from_pretrained("studio-ousia/luke-base")
ValueError: Unrecognized configuration class <class 'transformers.models.luke.configuration_luke.LukeConfig'> for this kind of AutoModel: AutoModelForMaskedLM.
```

I have fixed this by adding `("luke", "LukeForMaskedLM")` to `MODEL_FOR_MASKED_LM_MAPPING_NAMES`.

## Who can review?
@NielsRogge, could you check this PR? Thanks!

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

# What does this PR do?

Fix `LayoutXLMProcessorTest` test failure found in

https://github.com/huggingface/transformers/runs/6663596212?check_suite_focus=true

```
E               ValueError: Calling LayoutXLMTokenizerFast.from_pretrained() with the path to a single file or url is not supported for this tokenizer. Use a model identifier or the path to a directory instead.
```

I just use a tiny model's hub name to fix it.

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

# What does this PR do?

Fix ctrl tests failed due to GPU memory issue. The fix is the same as in #16881



Job page (failed test)
https://github.com/huggingface/transformers/runs/6682129553?check_suite_focus=true

Comments:
I verified the fix on GCP VM.

_The documentation is not available anymore as the PR was closed or merged._
push_to_hub on custom tokenizer causing a flood of "deadlock" messages
Author: cakiki
Pull request: no
Labels: name: bug

### System Info

```shell
- `transformers` version: 4.18.0
- Platform: Linux-4.15.0-176-generic-x86_64-with-glibc2.31
- Python version: 3.9.10
- Huggingface_hub version: 0.5.1
- PyTorch version (GPU?): 1.11.0 (False)
- Tensorflow version (GPU?): 2.8.0 (False)
- 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 @Narsil @n1t0 

### Information

- [ ] 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

Reproduction code available here: [slides.ipynb](https://github.com/cakiki/huggingface-intro/blob/11db121d492762362bc5e1637950e2e269571a0d/slides.ipynb) if you scroll down to `🤗 Tokenizers`

**TL;DR:** 

I'm training a custom rust `WordPiece` tokenizer, wrapping that into a `PreTrainedTokenizerFast` and calling `.push_to_hub` on that. The push succeeds but I get the `The current process just got forked, after parallelism has already been used.` message, even when I don't use the tokenizer.

I've tried: 
setting the `TOKENIZERS_PARALLELISM` to false -> all jupyter notebook cells that need the internet hang (including `push_to_hub`)
setting the `TOKENIZERS_PARALLELISM` to true -> only `push_to_hub` hangs.

### Expected behavior

```shell
N/A
```


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.
Simple way to convert a Python tokenizer to a fast tokenizer
Author: pommedeterresautee
Pull request: no
Labels: name: wontfix

# 🚀 Feature request

Tokenizer are provided with each model, some have a fast version of their tokenizer (Rust based), others like CamemBERT have only the slow version.

## Motivation

Fast tokenizer improves inference times drastically (in real time inference for instance).
Plus there is no reason it should not be possible

## Your contribution

If you provide me with basic guidelines on how to manually make a conversion, I can submit a PR to offer such feature.


Comments:
requires unigram algo implemented on tokenizers
https://github.com/huggingface/tokenizers/pull/292

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.


PR merged, closing the issue

Hi @pommedeterresautee, could you please refer me to how I can convert an existing Python tokenizer to a Fast tokenizer?

Sorry if I missed something, and thanks so much for your help!

Maybe @SaulLu or @Narsil can comment and link to an example!

Hi @varun-tandon ,

The code to change from slow to fast is included here: https://github.com/huggingface/transformers/blob/main/src/transformers/convert_slow_tokenizer.py

As you can see there are many variables, depending on the actual model and what you want to achieve.

Usually it involves understanding how a model actually does the tokenization (and all the bits like CLS, SEP etc..) and using the compponents of `tokenizers` to assemble them to make the output similar to what the python code does:
https://huggingface.co/docs/tokenizers/components

Sometimes we're missing a brick and we simply add it (although it becomes rarer with time)
Add warning when using older version of torch for ViltFeatureExtractor
Author: xhluca
Pull request: yes

Closes https://github.com/huggingface/transformers/issues/16637

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

I'd update to use `logging.warning` instead of `warnings.warn`, but other than that it looks like a sound approach.

Ok I made the change

Sorry should have been clearer, in this instance you should move the `logger` instantiation above, and use `logger.warning`. See an example here:

https://github.com/huggingface/transformers/blob/4975002df50c472cbb6f8ac3580e475f570606ab/src/transformers/pipelines/base.py#L234-L237

@LysandreJik Ok done

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.

Ah, before merging we'll need to update the code quality.

Could you just run the code quality tool to ensure that the code quality passes? You can install them with the following, from the root of your clone:
```
pip install -e ".[quality]"
```
And then run them with:
```
make fixup
```

@LysandreJik just updated it

@xhlulu it seems that the CI still isn't green, you can click on the check "check_code_quality" above to see why it's failing.

```
Traceback (most recent call last):
  File "/home/circleci/.local/bin/doc-builder", line 8, in <module>
    sys.exit(main())
  File "/home/circleci/.local/lib/python3.6/site-packages/doc_builder/commands/doc_builder_cli.py", line 43, in main
    args.func(args)
  File "/home/circleci/.local/lib/python3.6/site-packages/doc_builder/commands/style.py", line 28, in style_command
    raise ValueError(f"{len(changed)} files should be restyled!")
ValueError: 30 files should be restyled!

Exited with code exit status 1

CircleCI received exit code 1
```

@NielsRogge i just updated to match upstream, should work now

Hmm @xhlulu I checked and there's no `meshgrid` being used in `ViltFeatureExtractor`.

It's only the model that requires torch 1.10 or higher, right? Not the feature extractor?

It's in `ViltEmbeddings`:

https://github.com/huggingface/transformers/blob/39f8eafc1b6f00769240f714e2df5b2c5f111c32/src/transformers/models/vilt/modeling_vilt.py#L115-L151

I moved the error message, but when trying to run the make fixup, it gives this:
```
(venv) xhlu@XHL-Desktop:~/dev/transformers$ make fixup
make: execvp: /bin/sh: Argument list too long
make: *** [Makefile:10: modified_only_fixup] Error 127
```

Unrelated error, merging!
Adding LeViT Model by Facebook
Author: AnugunjNaman
Pull request: yes

Adds LeViT Model (a Vision Transformer) to HF Library. All the checkpoints are on my HF account hub.
Please review and suggest the required changes.
@NielsRogge 

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

Thanks for suggestion. I have done the requested changes. I need help here:
- I cannot figure rendering of warning problem. If I give `enter` or `space`. There is `style error` of `white space`.
- The image in `convnext.mdx` is added in HF Dataset repo in hub. I can give the image to add there.

The weights are also uploaded on hub correctly after change in `self.bn` -> `self.batch_norm`.
Please review and suggest the changes @NielsRogge 

CI error seems unrelated, thanks for your work, merging!
Fix flakey no-trainer test
Author: muellerzr
Pull request: yes

# What does this PR do?

This PR fixes an occasional fail in `test_accelerate_examples::test_run_squad_no_trainer` due to multi-gpu's sometimes showing a slight drop in accuracy.

## 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?


## 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._
CLI: tool to convert PT into TF weights and open hub PR
Author: gante
Pull request: yes

# What does this PR do?

This PR adds a CLI to convert PT weights into TF weights, validate them, and (optionally) open a PR. The open PR part depends on https://github.com/huggingface/huggingface_hub/pull/884, and is wrapped in a try/except for the time being.

Here are 3 PRs open with the tool (`transformers-cli pt-to-tf --model-name [model-name] --local-dir [local-dir] --open-pr`):
1. Text modality: https://huggingface.co/joaogante/test_text/discussions/1
2. Audio modality: https://huggingface.co/joaogante/test_audio/discussions/1
3. Image modality: https://huggingface.co/joaogante/test_img/discussions/1

This tool can also be used to check existing weights. Sadly, there is no programmatic way to check the weights in existing hub PRs, they have to be downloaded manually.

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Add OnnxConfig for SqueezeBert iss17314
Author: artemisep
Pull request: yes

# What does this PR do?

<!--
As part of #16308, this PR adds OnnxConfig for SqueezeBert.
-->

## Who can review?
@lewtun @LysandreJik 

Anyone in the community is free to review the PR once the tests have passed. 


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

I run pytest on those 4 failed tests in CircleCI shown above on my local dev, no error message was found, all says skipped except the following one says passed
tests/models/pegasus/test_modeling_pegasus.py::PegasusStandaloneDecoderModelTest::test_sample_generate




Hi @lewtun,
running the following test did not show any errors, it output the following; 6 skipped, 200 deselected, 7 warnings
RUN_SLOW=1 pytest tests/onnx/test_onnx_v2.py -s -k "squeezebert"
wavlm s3prl emotion recognition
Author: sciai-ai
Pull request: no

Hi

I have trained a downstream emotion recognition task using s3prl wavlm where a checkpoint has been saved `dev-best.ckpt`. The inference setup in s3prl is not ideal requiring batches of wav files split by session rather a single wav file which is useful in production endpoints. 

@anton-l can you please share how you ported the wav2vec2-er s3prl model to do inference below.

![image](https://user-images.githubusercontent.com/52277510/166095746-7970ef1b-bdb3-4db4-98f2-14395337b3d9.png)


Comments:
Hi @sciai-ai! You can find the rough model conversion script is here: https://github.com/huggingface/transformers/blob/main/src/transformers/models/wavlm/convert_wavlm_original_s3prl_checkpoint_to_pytorch.py

The command is:
```bash
python convert_wavlm_original_s3prl_checkpoint_to_pytorch.py \
    --base_model_name "microsoft/wavlm-base (depends on your base model)" \
    --config_path "hf_model/config.json (should be modified by hand, probably just add id2label and label2id fields to the base WavLM config.json)" \
    --checkpoint_path "path/to/s3prl/dev-best.ckpt" \
    --model_dump_path "hf_model/output/dir/"
```

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.
Print more library versions in CI
Author: ydshieh
Pull request: yes

# What does this PR do?

- Print more library versions in CI jobs
  - `transformers`, `PyTorch`, `TensorFlow`, `DeepSpeed`, etc.  
  - easier to access without the need to open several tabs


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

@stas00 OK for me to use a script, on it!

@stas00 

Just pushed a quick version. It is now named `utils/print_env.py`, which tries to print information if a library could be imported.
Probably need a better job name than `GPU visibility`, but it shows something like

<img width="512" alt="Screenshot 2022-05-24 215339" src="https://user-images.githubusercontent.com/2521628/170120952-2be2f4d4-9061-43a4-9d51-8ebdb92650b2.png">



Looks great, @ydshieh 

Perhaps let's just turn warnings off to keep the SNR high?
Clean README in post release job as well.
Author: sgugger
Pull request: yes

# What does this PR do?

The README cleanup (removing the main in the links to the doc) hasn't been done in the past releases because we do them on branches (so it has been done, but not on main). This PR redoes the cleanup in the `post-release` job (which is always done on main) and updates the instruction in the setup (no need to run `make post-patch` anymore but the post-release job will change the README so `make fix-copies` is necessary).

Comments:
Fix  when Accelerate is not installed
Author: sgugger
Pull request: yes

# What does this PR do?

As pointed out in #17516, the current `from_pretrained` on the main branch tries to use a function in Accelerate even if it's not necessary. This PR adds a check on the offloading (which requires Accelerate and is enforced at [this line](https://github.com/huggingface/transformers/blob/58fb3c9f98877bf76efb03e376a5c92cf80f7952/src/transformers/modeling_utils.py#L1847) since it requires a `device_map`) before using that function.

Fixes #17516

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