noamaanMulla-03/transformers-issues huggingface dataset:
Load finetuned state dict without loading pretrained weights 
Author: laurahanu
Pull request: yes

# What does this PR do?

<!--
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.
-->

<!-- Remove if not applicable -->

Fixes #16672

## 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?

@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: @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._
Trying to Train Lonformer but from standard transfomer file, error AttributeError: module 'wandb' has no attribute 'run'. Even when I have not install Wandb
Author: nabarunbaruaAIML
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: 4.18.0
- Platform: Windows
- Python version: 3.7.13
- PyTorch version (GPU?): Yes
- Tensorflow version (GPU?): No
- Using GPU in script?: Yes
- Using distributed or parallel set-up in script?: No

### Who can help
<!-- Your issue 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.
@sgugger 
Models:
- Longformer, BigBird: @ydshieh


Library:


- Tokenizers: @SaulLu
- Trainer: @sgugger


 -->

## Information

The model  Longformer,  I am using in a fresh environment with below packages:
torch==1.8.2+cu111 
torchvision==0.9.2+cu111 
torchaudio===0.8.2
tqdm
mlflow
pandas
transformers
datasets
PyYAML 
boto3
matplotlib
sklearn
python-dotenv
s3fs

Ther Problem start when Trainer API executed. In the Transformers Python file error comes stating no module Wandb but I haven't installed Wandb. My understanding is if I have installed Wandb then only this Integration should trigger.
 
 I am getting Error in integrations.py in Transformer Package
        File "D:\Virtual_Env\GitHub_projects\AIOPS\DVC\Fact_Checking_Health_related_Claims\env\lib\site- 
               packages\transformers\integrations.py", line 592, in setup     
                      if self._wandb.run is None:
               AttributeError: module 'wandb' has no attribute 'run'
My Code from where I am triggering Trainer API: can be found here https://github.com/nabarunbaruaAIML/Fact_Checking_Health_related_Claims/blob/master/src/stage_03_train.py

The tasks I am working on is:
* Text Classification on Publicly available Dataset


## To reproduce

Steps to reproduce the behaviour:

1. After setuping Environment  
2. Execute Python File: stage_01_load_save & stage_02_prepare_dataset which download Public Dataset and convert it to Dataset
3. Lastly Execute Python file to start training via trainer API: python src/stage_03_train.py 
**Github:** https://github.com/nabarunbaruaAIML/Fact_Checking_Health_related_Claims/tree/master/src
![image](https://user-images.githubusercontent.com/64695833/162567205-ec7f3584-9f32-42cf-9f8c-00ee452ebffa.png)

## Expected behavior

Training should happen


Comments:
Got the Solution In previous Development I had set Wandb Global Environment Variable as True. And I suppose Transformer Library checks for the Variable and if found it will try for Integration because of which this Issue happened. To fix if you're not using Wandb then execute 

> export WANDB_DISABLED=true
else add it to your env file

This issue can be closed now.
Use decoder_inputs in generate function
Author: JoaoLages
Pull request: no

# 🚀 Feature request
Use the generate function with some initial decoder inputs.

## Motivation
Imagining I have a trained encoder-decoder transformer and want to generate some output for a given input, but I also have part of the output completed. How do I pass decoder_inputs to the generate method for the model to start the beam search decoding with some initial decoder inputs?
I don't think that it is possible nowadays, even with the `model_kwargs` argument.

## Your contribution
I'm available to help change the `generate` function to make it work. Just need someone to point me to the needed changes to make it easier.


Comments:
it's possible to pass `decoder_input_ids` to `generate`, it takes it as a keyword argument.

```python
model.generate(...,  decoder_input_ids=decoder_input_ids)
```

> it's possible to pass `decoder_input_ids` to `generate`, it takes it as a keyword argument.
> 
> ```python
> model.generate(...,  decoder_input_ids=decoder_input_ids)
> ```

As I said, `'I don't think that it is possible nowadays, even with the model_kwargs argument.'` Even if it accepts the argument, it does not perform the generate method as intended

> Even if it accepts the argument, it does not perform the generate method as intended

What do you mean by it does not perform as intended ? Could you post the code-snippet to re-produce what the exact issue is ?

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.

Just tried it and it's working, it was either solved or I was mistaken. Thank you!
camembert tokinizer 
Author: ElleuchMed2022
Pull request: no

# Initialize CamemBERT tokenizer
tokenizer=CamembertTokenizer.from_pretrained('camembert-base',do_lower_case=True)


TypeError: 'NoneType' object is not callable

Comments:
Make sure you install `sentencepiece`!

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.
Incomplete padding support for Funnel Transformer.
Author: Fraser-Greenlee
Pull request: no

Looks like there's a tiny bug in the funnel transformer implementation.
https://github.com/huggingface/transformers/blob/39249c9589f5eb9677807e74221e2eb3ea1b4a35/src/transformers/models/funnel/modeling_funnel.py#L783

Should be:
```python
module.word_embeddings.weight.data[module.word_embeddings.padding_idx].zero_()
```

Though a `pad_token_id` is not a field in `FunnelConfig` the `FunnelEmbeddings` do use the field if its present in the config.

I could make a PR to fix the line & add a usually assign `config.pad_token_id  = None`?

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.
Missing tags on Docker Hub after version 4.9.1
Author: AdrienDS
Pull request: no

## Environment info

- `transformers` version: > 4.9.1

### Who can help

@mfuntowicz ?

## Information

https://hub.docker.com/r/huggingface/transformers-pytorch-gpu/tags

I was expecting 1 tag per transformers version on the docker hub, but the most recent tag (aside from `latest`) is for 4.9.1 and was pushed on July 26, 2021.

## To reproduce

Steps to reproduce the behavior (and see existing tags):

1. Either visit https://hub.docker.com/r/huggingface/transformers-pytorch-gpu/tags and sort by Newest
2. Or run `wget -q https://registry.hub.docker.com/v1/repositories/huggingface/transformers-pytorch-gpu/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n'  | awk -F: '{print $3}'`

Current tags available:

```
latest
2.10.0
2.11.0
2.6.0
2.7.0
2.8.0
2.9.0
2.9.1
3.0.0
3.0.1
3.0.2
3.1.0
3.2.0
3.3.0
3.3.1
3.4.0
3.5.0
3.5.1
4
4.0.0
4.0.1
4.1.0
4.1.1
4.2.0
4.2.1
4.2.2
4.3.0
4.3.1
4.3.2
4.3.3
4.4.0
4.4.1
4.4.2
4.5.0
4.5.1
4.6.1
4.7.0
4.8.0
4.8.1
4.8.2
4.9.0
4.9.1
````

## Expected behavior

Each time a image is pushed with the `latest` tag, it could also be tagged with the current version number, like it was before version 4.9.1. (I was expecting to see 4.16.2 for example)


Comments:
cc'ing @mfuntowicz (among others)

Hey! We indeed stopped pushing images a while back, but we've started doing so again a few weeks ago. It makes sense to push images with the versions.

Will try to make some time and do so.

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.
After vocabulary extension the tokenizer keeps on running. 
Author: pratikchhapolika
Pull request: no

I am training a simple binary classification model using Hugging face models using pytorch.

Bert PyTorch HuggingFace.

`keyword_lst` has `20k` new token which I add to tokenizer. 

`I take mean of old tokenizer to update new tokenizers.`


I am training this model for `4,00,000 data points.`

Here is the code:

```
tok_orig = tr.RobertaTokenizer.from_pretrained("../models/unitary_roberta/tokenizer")
tokenizer = tr.RobertaTokenizer.from_pretrained("../models/unitary_roberta/tokenizer")
tokenizer.add_tokens(keyword_lst)


# do tokenization
train_encodings = tokenizer(train_texts, truncation=True, padding=True, max_length=512, return_tensors="pt")
val_encodings = tokenizer(val_texts, truncation=True, padding=True, max_length=512, return_tensors="pt")
    
# make datasets
train_data = HateDataset(train_encodings, train_labels)
val_data = HateDataset(val_encodings, val_labels)
    
# load model
model = tr.RobertaForSequenceClassification.from_pretrained("../models/unitary_roberta/model", 
                                                             num_labels=2)
# add embedding params for new vocab words
model.resize_token_embeddings(len(tokenizer))
weights = model.roberta.embeddings.word_embeddings.weight
    
# initialize new embedding weights as mean of original tokens
    with torch.no_grad():
        emb = []
        for i in range(len(keyword_lst)):
            word = keyword_lst[i]
            # first & last tokens are just string start/end; don't keep
            tok_ids = tok_orig(word)["input_ids"][1:-1]
            tok_weights = weights[tok_ids]

            # average over tokens in original tokenization
            weight_mean = torch.mean(tok_weights, axis=0)
            emb.append(weight_mean)
        weights[-len(keyword_lst):,:] = torch.vstack(emb).requires_grad_()
```


The tokenizer keeps on running.  :(

Comments:
Hi @pratikchhapolika ! The best place to ask this question would be to use the [forum](https://discuss.huggingface.co/). We use issues for bug reports and feature requests.

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.
Various issues with  accelerate launch command for Large example
Author: ThomasGmeinder
Pull request: no

## Environment info
https://github.com/huggingface/transformers/tree/master/examples/pytorch/speech-pretraining

Python 3.6.9

## Information
I'm trying to run this command:
https://github.com/huggingface/transformers/tree/master/examples/pytorch/speech-pretraining#large

and found various issues with it:
1.  first line contains an erroneous space after the escape character:
`accelerate launch run_wav2vec2_pretraining_no_trainer.py \ `

2. The following line is missing the newline escape:
`--model_name_or_path=./ `

After fixing both I found another problem:

3. The value of --model_name_or_path is invalid: `./`

## Suggested Fix:
I fixed this with
` --model_name_or_path=patrickvonplaten/wav2vec2-large-xlsr-53-spanish-with-lm`

This command works now:
```
accelerate launch run_wav2vec2_pretraining_no_trainer.py \
	--dataset_name=librispeech_asr \
	--dataset_config_names clean clean other \
	--dataset_split_names train.100 train.360 train.500 \
	--output_dir=./test \
	--max_train_steps=200000 \
	--num_warmup_steps=32000 \
	--gradient_accumulation_steps=8 \
	--learning_rate=0.001 \
	--weight_decay=0.01 \
	--max_duration_in_seconds=20.0 \
	--min_duration_in_seconds=2.0 \
	--model_name_or_path=patrickvonplaten/wav2vec2-large-xlsr-53-spanish-with-lm \
	--logging_steps=1 \
	--saving_steps=10000 \
	--per_device_train_batch_size=2 \
	--per_device_eval_batch_size=4 \
	--adam_beta1=0.9 \
	--adam_beta2=0.98 \
	--adam_epsilon=1e-06 \
	--gradient_checkpointing
```

Comments:
cc @patrickvonplaten 

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.

Hey @ThomasGmeinder,

Thanks for spotting `1.` and `2.` - feel free to open a PR to correct the docs :-) 
The reason why I put `--model_name_or_path=./` is because this way you can train from your local directory, but the docs should have been cleaner here indeed

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 some doc examples in task summary
Author: ydshieh
Pull request: yes

# What does this PR do?

Fix some doctest CI failure found [here](https://github.com/huggingface/transformers/runs/5877708951?check_suite_focus=true)

A few failures:

- 
    ```
    Expected nothing
    Got:
        '_unknown_'
    ```
- 
    ```
    Expected nothing
    Got:
        'MISTER QUILTER IS THE APOSTLE OF THE MIDDLE CLASSES AND WE ARE GLAD TO WELCOME HIS GOSPEL'
    ```
- 
    ```
    Expected:
        <pad> prosecutors say the marriages were part of an immigration scam. if convicted, barrientos faces two criminal
        counts of "offering a false instrument for filing in the first degree" she has been married 10 times, nine of them
        between 1999 and 2002.
    Got:
        <pad> prosecutors say the marriages were part of an immigration scam. if convicted, barrientos faces two criminal counts of "offering a false instrument for filing in the first degree" she has been married 10 times, nine of them between 1999 and 2002.
<pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad><pad>
    ```

There is one error I haven't fixed yet
```
No such file or directory: 'jfk_moon_speech.wav'
```

Do you know where to get this file for testing purpose ..?

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

> Thanks for fixing these!
> 
> The `jfk_moon_speech.wav` is a local file I used to test some code examples, so maybe we can replace it with an audio example from the Hub?

Sure! Let me try. Haven't tried audio dataset from the Hub.

@sgugger @stevhliu I was able to use a file from dataset.

One example of change is

```py
>>> from transformers import pipeline
>>> from datasets import load_dataset
>>> import torch

>>> torch.manual_seed(42)  # doctest: +IGNORE_RESULT

>>> dataset = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation")
>>> dataset = dataset.sort("id")
>>> audio_file = dataset[0]["audio"]["path"]

>>> audio_classifier = pipeline(
...     task="audio-classification", model="ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition"
... )
>>> predictions = audio_classifier(audio_file)
>>> predictions = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in predictions]
>>> predictions
[{'score': 0.1315, 'label': 'calm'}, {'score': 0.1307, 'label': 'neutral'}, {'score': 0.1274, 'label': 'sad'}, {'score': 0.1261, 'label': 'fearful'}, {'score': 0.1242, 'label': 'happy'}]
```
I ran the tests, and `task_summary.mdx` is fine, except the one in #16644 (it is not merged yet).

Let me know if you have further comments :-)
BART can only generate a maximum of 20 tokens
Author: ayaka14732
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: 4.18.0.dev0
- Platform: Linux-5.11.0-1018-gcp-x86_64-with-glibc2.31
- Python version: 3.10.4
- Huggingface_hub version: 0.4.0
- PyTorch version (GPU?): 1.11.0+cu102 (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): 0.4.1 (tpu)
- Jax version: 0.3.4
- JaxLib version: 0.3.2
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

### Who can help

@patil-suraj @patrickvonplaten

## Information

Model I am using: BART

## To reproduce

Steps to reproduce the behavior:

```python
from transformers import BartTokenizer, BartForConditionalGeneration

tokenizer = BartTokenizer.from_pretrained('facebook/bart-base')
model = BartForConditionalGeneration.from_pretrained('facebook/bart-base')

sentences = ['At the launch of the latest report by the Intergovernmental Panel on Climate Change, on the mitigation of climate change, the UN Secretary-General called for an urgent shift of investments and subsidies from fossil fuels to renewable energy, warning that investing in new fossil fuels infrastructure is moral and economic madness.']

inputs = tokenizer(sentences, return_tensors='pt')
print('Input shape:', inputs.input_ids.shape)

generate_ids = model.generate(inputs.input_ids, num_beams=5, min_length=50)
print('Generated shape:', generate_ids.shape)

print(tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0])
```

Output:

```
Input shape: torch.Size([1, 60])
Generated shape: torch.Size([1, 20])
At the launch of the latest report by the Intergovernmental Panel on Climate Change, on
```

## Expected behavior

The output should not be truncated.

## Actual behavior

The output is truncated.

Note that the output is truncated even if `min_length=50` is specified.

Comments:
Hi @ayaka14732 👋  That happens because the stopping conditions take precedence over anything else. The default for `max_length` is `20`, so that's why you see 20 generated tokens. In your example, if you rewrite the generate line into `generate_ids = model.generate(inputs.input_ids, num_beams=5, min_length=50, max_length=100)`, you'll get the results you expect.

@patrickvonplaten @patil-suraj should we raise an exception in this case? (`min_length` > `max_length`) 

@gante, yes this would work for me! Let's maybe do this in `generate()` before we just into the sub-generation methods

@ayaka14732 if you pull from master (or install `transformers==4.19.0.dev0`), you shall see an informative Exception if you try to run your original script.

Thank you for reporting this issue :D