noamaanMulla-03/transformers-issues huggingface dataset:
Only call get_output_embeddings when tie_word_embeddings is set
Author: smelm
Pull request: yes


# What does this PR do?

This PR just changes the order in which two conditions in `tie_weights` in the `PreTrainedModel` class are checked. This would allow us (and probably others) to avoid problems when initializing child classes of models.

In our (maybe somewhat specific use case) we encounter a problem when initializing a child class of a model. During the call of the parent constructor (`PreTrainedModel`) `get_ourput_embeddings` of the child class is called when it is not completely initialized. This also happens when `tie_word_embeddings=False` and the output embeddings are not even needed.  Changing the order of the conditions fixes the problem without changing the functionality.

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

## 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.

@patrickvonplaten, @thomwolf, @sgugger

<!-- 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: , @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._
HTTPSConnectionPool(host='s3.amazonaws.com', port=443): Max retries exceeded with url: /models.huggingface.co/bert/bert-base-uncased.tar.gz (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000002456AF21710>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',))
Author: laibamehnaz
Pull request: no

I have been trying to executing  this code : 

import torch
from pytorch_pretrained_bert import BertTokenizer, BertModel, BertForMaskedLM

# Load pre-trained model tokenizer (vocabulary)
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')

# Tokenized input
text = "Who was Jim Henson ? Jim Henson was a puppeteer"
tokenized_text = tokenizer.tokenize(text)

# Mask a token that we will try to predict back with `BertForMaskedLM`
masked_index = 6
tokenized_text[masked_index] = '[MASK]'
assert tokenized_text == ['who', 'was', 'jim', 'henson', '?', 'jim', '[MASK]', 'was', 'a', 'puppet', '##eer']

# Convert token to vocabulary indices
indexed_tokens = tokenizer.convert_tokens_to_ids(tokenized_text)
# Define sentence A and B indices associated to 1st and 2nd sentences (see paper)
segments_ids = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]

# Convert inputs to PyTorch tensors
tokens_tensor = torch.tensor([indexed_tokens])
segments_tensors = torch.tensor([segments_ids])

# Load pre-trained model (weights)
model = BertModel.from_pretrained('bert-base-uncased')
model.eval()

This is the error that I am getting continuously :

 HTTPSConnectionPool(host='s3.amazonaws.com', port=443): Max retries exceeded with url: /models.huggingface.co/bert/bert-base-uncased.tar.gz (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000002456AF21710>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',))

Can you help me with this please

Comments:
Hi, you need a (stable) internet connection to download the weights. This operation is only done once as the weights are then cached on you drive.

Thankyou so much!

@laibamehnaz have you solved the problem? I have a similar problem.

Hi,
I am facing a similar issue, can anyone help with this? 

解决方式 method：

import os
os.environ['NO_PROXY'] = 'huggingface.co' # 不走代理

or

import os
import requests
os.environ['NO_PROXY'] = 'huggingface.co' # 不走代理

or

import os
os.environ['NO_PROXY'] = 'XXXXX.com' # 不走代理，任何网址都可以




Thank you very much!

> 解决方式 method：
> 
> import os os.environ['NO_PROXY'] = 'huggingface.co' # 不走代理
> 
> or
> 
> import os import requests os.environ['NO_PROXY'] = 'huggingface.co' # 不走代理
> 
> or
> 
> import os os.environ['NO_PROXY'] = 'XXXXX.com' # 不走代理，任何网址都可以
Non-unique `local` in toctree
Author: mishig25
Pull request: no

`local` field in toctree is treated as an id; therefore, it has to be unique. Because of this, in https://huggingface.co/docs/transformers/multilingual, you cannot reach the second `multilingual` page

I will work on the doc-builder that checks locals are unique;

[line here](https://github.com/huggingface/transformers/blob/master/docs/source/_toctree.yml#L32)

<img width="300" alt="Screenshot 2022-03-03 at 18 08 52" src="https://user-images.githubusercontent.com/11827707/156615355-af17d9fc-0c8b-488c-ada3-77edc923bf15.png">



Comments:
Thanks for this! I think we can actually remove the first `multilingual` page since it is outdated now. On a related note, can we also remove the `custom_datasets` [page](https://huggingface.co/docs/transformers/master/en/custom_datasets) since it has also been replaced by the fine-tune for downstream tasks section?

Is this also why for section headers that share the same name, the second header cannot be reached (i.e., feature extractor [here](https://huggingface.co/docs/transformers/master/en/preprocessing#feature-extractor))?

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.

@mishig25 Add you added something to error when entries are not unique?
ASR Pipeline: End of transcripts missing when chunking enabled 
Author: nkaenzig-aifund
Pull request: no

## Environment info
- `transformers` version: 4.18.0
- Platform: Linux-5.4.144+-x86_64-with-Ubuntu-18.04-bionic
- Python version: 3.7.13
- Huggingface_hub version: 0.5.1
- PyTorch version (GPU?): 1.10.0+cu111 (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?: yes & no
- Using distributed or parallel set-up in script?: no


### Who can help
@Narsil, @patrickvonplaten, @jonatasgrosman, @anton-l

## Information
If you use the chunking feature implemented in the asr pipeline, in some cases it cuts off the end of the audio transcripts.

Model I am using:
`facebook/wav2vec2-large-960h-lv60-self`

The problem arises when using:
* [x] the official example scripts: (give details below)
* [x] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [x] my own task or dataset: (give details below)

## To reproduce
The issue can be reproduced using the following colab notebook:
https://colab.research.google.com/drive/1SSWr-2X2nnbKLa5dUSEm_Y_WFTju2-fN?usp=sharing

## Expected behavior
`chunk_length_s=None` and `chunk_length_s=10` should yield the same (or similar) results, without cutting off the end of the transcript.


Comments:
Hey @nkaenzig-aifund,

Thanks a lot for the reproducible bug report! I'm looking into it and will try to submit a fix today. cc @Narsil 

```python
#!/usr/bin/env python3
from transformers import pipeline

pipe = pipeline(model='facebook/wav2vec2-large-960h-lv60-self')

result_1 = pipe('47.wav', chunk_length_s=None)

result_2 = pipe('47.wav', chunk_length_s=10)

print("Correct", result_1)
print("Wrong", result_2)
```

with:

!wget https://public-a2d129863a16ad26b0deda49d22c64b8.s3.us-west-2.amazonaws.com/47.wav
AutoConfig.from_pretrained can fail with Tokenizers
Author: d-miketa
Pull request: no

`tokenizer_config = AutoConfig.from_pretrained("/path/to/tokenizer_config.json")` resolves the Auto Class by checking the `model_type` key, which is not always included for tokenizers, see e.g. https://huggingface.co/seyonec/ChemBERTa-zinc-base-v1/blob/main/tokenizer_config.json.

Perhaps `model_type` should be exported in `tokenizer_config.json` when running `trainer.save(/path/to)`?

Comments:
The `AutoConfig` utility is a utility for models only, it's the tool one can use to instantiate a model. 

What would you like to do by instantiating a configuration for a tokenizer? The `AutoTokenizer` class should handle everything on its own.

Ahh I was under the impression that you needed to provide a separate `tokenizer-config.json`. Must've been an old example or someone overcomplicating their own usage. Thanks for clarifying!
TF: remove set_tensor_by_indices_to_value
Author: gante
Pull request: yes

# What does this PR do?

Removes our TF `set_tensor_by_indices_to_value` function and replaces all its uses by `tf.where`. They are the same, but with a different input order -- removing it means one fewer function to test while making the code easier for TF users.

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

@sgugger The last diff belongs to @patrickvonplaten, but because the function was moved (from [here](https://github.com/huggingface/transformers/blame/a3dbbc346763c8eaa49577a448e5b5a2da1428ed/src/transformers/generation_tf_utils.py#L1631) (link from the commit immediatly before it was moved)). Last time it was touched was 2 years ago 😅
Moved functions to pytorch_utils.py
Author: anmolsjoshi
Pull request: yes

# What does this PR do?

Moved all pruning stuff, apply_chunking_to_forward to pytorch_utils.py

Fixes #15543

## 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?

@patrickvonplaten @sgugger 

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

@patrickvonplaten I'm new to contributing to this repo. What other updates are required?

Those should be removed entirely honestly (components should be in model files, not modeling_utils), so I care little where they are :-)

@patrickvonplaten won't moving Conv1D back to modeling_utils.py cause circular imports?

@patrickvonplaten any thoughts?

@sgugger any more changes to complete on this PR?

Good to go for me!

Waiting for final review from @sgugger 

I'm good on my side, was waiting for you Patrick ;-)
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 documentation is not available anymore as the PR was closed or merged._

@sgugger @LysandreJik thanks for the review! I have incorporated all the requested changes. 

@sgugger unsure why the PR Documentation check is failing

Failure is unrelated to this PR and is fixed independently.
Thanks a lot for addressing all comments!
[FlaxSpeechEncoderDecoder] Fix input shape bug in weights init
Author: sanchit-gandhi
Pull request: yes

The tuple `input_shape` is required in the `init` method of the FlaxSpeechEncoderDecoderModel in order to initialise the model weights - one must specify these input shapes to enable JAX to trace through the model dimensions.
This tuple consists of two entries: the encoder and decoder input lengths. Speech encoders almost always downsample the sequence length dimension. Given an encoder input length, the decoder input length is computed through a convolutional formula. This convolutional formula should take into consideration two convolutional based modules:

1. Feature extractor
2. Adapter module (optional)

Currently, only the first of these two convolutional based modules is accounted for. This PR amends the model script to account for the second of the two, i.e. the adapter module.



Comments:
_The documentation is not available anymore as the PR was closed or merged._
add Bigbird ONNX config
Author: vumichien
Pull request: yes

# What does this PR do?

Add Bigbird OnnxConfig to make this model available for conversion.

## Who can review?
@lewtun @LysandreJik

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

5040f17eba15504bad66b14a645bddd9b015ebb7 #15622 

@lewtun Thank you for reviewing my code. I have fixed the merge conflicts and all tests by running this `RUN_SLOW=1 pytest tests/onnx/test_onnx_v2.py -k "bigbird"` was passed.

This all looks good to me @vumichien - thanks for iterating! Gently pinging @LysandreJik or @sgugger for final approval
TF beam search: handle case without past
Author: gante
Pull request: yes

# What does this PR do?

Fixes `tests/vision_encoder_decoder/test_modeling_tf_vision_encoder_decoder.py::TFViT2GPT2ModelIntegrationTest::test_inference_coco_en`, whose root cause was in `beam_search` (it was not handling correctly cases without cache). This one slipped through the cracks, I probably forgot to run a final check on this test file before merging -- my bad 😅 

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

(merging as Patrick has approved #16713, which also contains these changes)
how can i distill xlm-roberta model , just like distill roberta model , any suggestion ?thanks a lot  
Author: ciel-zhang
Pull request: no
Labels: name: wontfix

# ❓ Questions & Help

how can i distill xlm-roberta model , maybe i can distill it ,just like distill roberta model , any suggestion ? thanks a lot

Comments:
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.


Any answer on this?
Move generic PyTorch utils function from modeling_utils.py to pytorch_utils
Author: patrickvonplaten
Pull request: no
Labels: name: Good First Issue

# 🚀 Feature request

> Since we're creating a new module file, can we maybe move some other functions there? Like the no_init_weight context manager, and:
> 
> all pruning stuff
> apply_chunking_to_forward
> get_parameter_device
> get_parameter_dtype
> so that the modeling utils file stays focused on PreTrainedModel and the layers it defines?

Taken from comment here: https://github.com/huggingface/transformers/pull/15498#pullrequestreview-874783288

## Motivation

<!-- Please outline the motivation for the proposal. Is your feature request
     related to a problem? e.g., I'm always frustrated when [...]. If this is related
     to another GitHub issue, please link here too. -->

## Your contribution

<!-- Is there any way that you could help, e.g. by submitting a PR?
     Make sure to read the CONTRIBUTING.MD readme:
     https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md -->


Comments:
may I work on this issue?

Yes please :-)

Great job @davidegavio ! Really nice clean-up :-)
Tokenizers setter of ids of special tokens don't work
Author: davidleonfdez
Pull request: no

## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->

- `transformers` version:
- Platform:
- Python version:
- PyTorch version (GPU?):
- Tensorflow version (GPU?):
- Using GPU in script?:
- Using distributed or parallel set-up in script?:

### Who can help
- Tokenizers: @SaulLu

## Information

The problem arises when using:
* [ ] the official example scripts: (give details below)
* [x] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [x] my own task or dataset: (give details below)

## To reproduce

Steps to reproduce the behavior:

1. Create an instance of a pretrained tokenizer
2. Try to set the pad_token_id

For instance:

```
tokenizer = AutoTokenizer.from_pretrained('gpt2')
tokenizer.pad_token_id = tokenizer.eos_token_id
```

Output:
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_33/1516894257.py in <module>
      1 tokenizer = AutoTokenizer.from_pretrained('gpt2')
----> 2 tokenizer.pad_token_id = tokenizer.eos_token_id

/opt/conda/lib/python3.7/site-packages/transformers/tokenization_utils_base.py in pad_token_id(self, value)
   1173     @pad_token_id.setter
   1174     def pad_token_id(self, value):
-> 1175         self._pad_token = self.convert_tokens_to_ids(value)
   1176 
   1177     @cls_token_id.setter

/opt/conda/lib/python3.7/site-packages/transformers/tokenization_utils_fast.py in convert_tokens_to_ids(self, tokens)
    248 
    249         ids = []
--> 250         for token in tokens:
    251             ids.append(self._convert_token_to_id_with_added_voc(token))
    252         return ids

TypeError: 'int' object is not iterable
```

## Expected behavior

Set the `pad_token` appropriately.

I've fixed this in a branch and I'm submitting a PR.


Comments:
Thank you very much for sharing this problem (and a solution)! :hugs: 
You are right, this behaviour is not desirable
[from_pretrained] refactor find_mismatched_keys
Author: stas00
Pull request: yes

This PR refactors 2 large identical code copies introduced by the recent sharded checkpoint PR into a helper function which is then called from 2 places. There is no change in functionality.

It's an intermediary step for this PR: https://github.com/huggingface/transformers/pull/16657 which revamps `low_cpu_mem_usage` and integrates it better with the sharded checkpoint code branch.

I explained here why the helper function is not a closure but needs the input args explicitly: https://github.com/huggingface/transformers/pull/16657#discussion_r846812714

@sgugger 


Comments:
_The documentation is not available anymore as the PR was closed or merged._
Fix #16660 (tokenizers setters of ids of special tokens)
Author: davidleonfdez
Pull request: yes

# What does this PR do?

Fixes #16660

@LysandreJik

It seems no one was using those setters because the code is quite old, but here's a fix if you want to merge it.

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

Thank you very much for sharing your solution, it looks great! :hugs: 

Just to be able to merge this change on main I think it would be good to add a test to make sure that future changes don't break the behaviour you just fixed - I let @LysandreJik confirm.

This new test would surely have its place in `tests/test_tokenization_common.py`. If you ever need more help or don't have time to do it, don't hesitate to tell us!

Sure!

I've just added the checks into an existing test. Some things could be done differently depending on your preferences:
a) Simplify and assume that `len(tokenizer) > 0` always.
b) Add a dummy token before testing the setters when `len(tokenizer) == 0`. I've chosen not to do it because you may want to have tests as independent as possible, and this change would make the test fail when the method to add tokens fails.

Please let me know.

I ended up creating a different method for this test because I've seen at least two models where the ids shouldn't be set and I needed to disable only this test for those tokenizers.