noamaanMulla-03/transformers-issues huggingface dataset:
as_target_tokenizer is not an attribute of PreTrainedTokenizerBase and Bart/RobertaTokenizer
Author: EvgheniiBeriozchin
Pull request: no

### Environment
Instance: Paperspace Gradient Cloud Instance
transformers: 3.5.1 (same issue on 4.14.1)
Python: 3.6.9

### Information
When creating an instance of the Roberta/Bart tokenizer the method as_target_tokenizer is not recognized. Code almost entirely the same as in the summarization example of Huggingface (https://github.com/huggingface/transformers/blob/master/examples/pytorch/summarization/run_summarization.py).

The tokenizer is instantiated in the following way:

```python
tokenizer = AutoTokenizer.from_pretrained("roberta-base")
```

and the executed code is:

```python
with tokenizer.as_target_tokenizer():
            labels = tokenizer(targets, max_length=MAX_TARGET_LENGTH, padding=USES_PADDING, truncation=True)
```

The error that occurs is:
AttributeError: 'RobertaTokenizer' object has no attribute 'as_target_tokenizer'

Same thing happens when instantiating just PreTrainedTokenizerBase, which according to the documentation has this function (https://huggingface.co/docs/transformers/internal/tokenization_utils).

Comments:
Hello! The `as_target_tokenizer` method is specifically for seq2seq models in order to separate between the source and target tokenizers. Why do you need it for RoBERTa?

cc @patrickvonplaten @sgugger 

I would double-check on v4.14.1 as every tokenizer has this method (it just doesn't do anything for models that are not seq2seq). It didn't exist for v3.5.1, so it's normal if you have an error on that version.

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.
improve saving strategy of sentencepiece tokenizer
Author: SaulLu
Pull request: yes

# What does this PR do?

The slow tokenizer  based on sentencepiece until now needed to access the original files (like `xxx/spiece.model`) that had been used to initialize them when we wanted to save them.

Since the version `0.1.91` of sentencepiece, there is a new method `serialized_model_proto` available which allows to create directly the sentence piece model file from the python object used by our tokenizer. 

This PR proposes to modify all the tokenizers based on sentencepiece to use this new method if the original file(s) is not be accessible anymore. A new test also test this new capability.

## Additional comments

In this PR I also modified:
- `BartphoTokenizer` so that some special tokens are not hardcoded anymore
- `M2M100Tokenizer` and `MarianTokenizer`, so that their saving method looks more like the other tokenizers

## Motivation

I think that when it is possible it is good to be able to save our object even if some files used during the initialization do not exist anymore. 

Moreover, this addition allows me to make easier the creation of other tests (like the test of [this PR](https://github.com/huggingface/transformers/pull/15319)).

## Who can review?

Anyone in the community is free to review the PR once the tests have passed. I would in particular love to read your thoughts @LysandreJik or @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._
Bump notebook from 6.1.5 to 6.4.1 in /examples/research_projects/visual_bert
Author: dependabot[bot]
Pull request: yes
Labels: name: dependencies

Bumps [notebook](http://jupyter.org) from 6.1.5 to 6.4.1.


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=notebook&package-manager=pip&previous-version=6.1.5&new-version=6.4.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language

You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/huggingface/transformers/network/alerts).

</details>

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Allow relative imports in dynamic code
Author: sgugger
Pull request: yes

# What does this PR do?

This PR ensures one can use relative imports when defining a module.py (or other kinds of file) living on the Hub. Without this, writing a custom configuration and wanting to use it in a custom model fails, line this [repo](https://huggingface.co/hf-internal-testing/test_dynamic_model).

To solve this, the way the module files are copied in the transformers module is changed slightly as they need to keep their original name (and not the e-tag). To make sure we don't copy cached files needlessly, but still benefit from updates in the main repo, the commit hash of the repo is used as a submodule name, so the modeling files are stored in `transformers_module/repo_id/hash/`. When the hash changes, a new copy of the modeling files from the cache is done, but those files are only downloaded if there was an update to them (since they are still cached with their e-tag name).

Several tests are added to make sure everything works well.

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Fix code format for Accelerate doc
Author: stevhliu
Pull request: yes

This PR fixes the format of externally linked code objects so they don't render like this:

![Screen Shot 2022-01-25 at 1 30 26 PM](https://user-images.githubusercontent.com/59462357/151076016-482c4d6e-473a-44f8-a504-b7ab3e0dacd4.png)

Also replaces the side-by-side image with a code block because the image isn't easily visible to users.

Comments:
_The documentation is not available anymore as the PR was closed or merged._
[WIP] Get started docs
Author: stevhliu
Pull request: yes
Labels: name: Documentation

# What does this PR do?

This PR contains the first draft of the Get Started docs as discussed for the new Transformers IA. Some additional thoughts:

- I think adding better signposts on the landing page will help users quickly get to the content they are looking for. For inspiration, maybe we can have cards like [these](https://stripe.com/docs/payments?payments=popular) with links to the pages (cc @mishig25). From the analytics, it looks like people view fine-tuning a pretrained model, fine-tuning for common downstream tasks, installation, and the BERT docs a lot. The first two pages definitely look valuable for getting users up and running with their tasks, but I would love to hear what other pages you think we can add to help guide users down the right path.

- On the Quick tour page, it'd be neat if we can embed a widget there (cc @mishig25) for sentiment analysis so users can play with it directly.

Comments:
Hey Steven, I believe there was an issue in your merge/rebase and GitHub is having a hard time understanding what happened. Could you close and reopen a new PR without touching at your branch so that we may see the actual differences? Thank you.
Set syncfree AdamW as the default optimizer for xla:gpu device in amp mode
Author: ymwangg
Pull request: yes

This PR sets the syncfree AdamW ([#3294](https://github.com/pytorch/xla/pull/3294)) as the default optimizer for xla:gpu device in amp mode. The syncfree AdamW optimizer shows 20%+ throughput speedup in the run_mlm test case.

Tested with the following script:
```sh
GPU_NUM_DEVICES=1 python run_mlm.py \
    --model_name_or_path bert-base-uncased \
    --dataset_name wikitext \
    --dataset_config_name wikitext-2-raw-v1 \
    --overwrite_output_dir true \
    --output_dir /tmp/test-mlm \
    --per_device_train_batch_size 12 \
    --do_eval \
    --fp16 true \
    --do_train \
    --num_train_epochs 10
```
With normal AdamW:
```sh
***** train metrics *****
  epoch                    =       10.0
  train_loss               =     1.6235
  train_runtime            = 0:19:13.85
  train_samples            =       4627
  train_samples_per_second =       40.1
  train_steps_per_second   =      3.345
```
With syncfree AdamW:
```sh
***** train metrics *****
  epoch                    =       10.0
  train_loss               =     1.6166
  train_runtime            = 0:16:14.05
  train_samples            =       4627
  train_samples_per_second =     47.502
  train_steps_per_second   =      3.963
```

cc @sgugger

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

Thanks a lot for your PR! I think it would be better to be less magical and offer the option of using this optimizer through a new choice (for instance named adamw_syncfree) in the `--optim` parameter instead of changing the default.

We did not even dare change the default from our implementation to the PyTorch ones for fear of braking changes :-)

@sgugger I added `adamw_torch_xla` as an optimizer option.
Train Bart-Large multi-labels
Author: GenVr
Pull request: no

Hello,
I have two similar questions. **First**, I'm trying to fine-tune the facebook/bart-large ([https://huggingface.co/facebook/bart-large](url)) but I want to train with 2 classes:

Example:
```
Text-input: "Hello, this text is about school and education."
Class 1: [X, Y, Z]
Class 2: [A, B, C]

Model answer: Y, C
```

I'm using the run_glue file on my personal training files. My question is: How should I set the labels of the training file to train?

My labels with 1 class (8 labels) are actually 0, 1, 2...7 so my csv-entry is something like:
```
Input - Label
Text1 - 2
Text2 - 6
Text3 - 4
```
(This is an example, my csv is in the glue-like format and work with 1 class)
I don't know how to modify them to train on 2 classes.


**Next** question, I want also to fine-tune the network with 1 class but in multi-label mode.

Example:
```
Text-input: "Hello, this text is about school and education."
Class 1: 0, 1, 2, 3, 4, 5, 6, 7

Model answer: 2, 4, 6
```

I've tried something like this, but it's not working

```
Input - Label
Text1 - [2,3]
Text2 - [6]
Text3 - [1,2,5,6]
```

Thank you, sorry if it is explained a little badly.

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.

Hello, thanks for opening an issue and sorry for getting back late to this! We try to keep the github issues for bugs/feature requests.
Could you ask your question on the [forum](https://discuss.huggingface.co) for a better chance of getting an answer?

Thanks!
Convering tf to torch: How to set custom embedding_size when using load_tf_weights_in_bert?
Author: alexyzhou
Pull request: no

I'm trying to convert a bert-tiny model into torch version and I am using the "load_tf_weights_in_bert" scripts from transformers.
And when I executed the function and fed the right checkpoints and configs, the scripts reported:

ValueError: Pointer shape torch.Size([312]) and array shape (128,) mismatched

After debugging the code I realized that transformers uses "hidden_size" to initialize the embedding layer, which is: 
![image](https://user-images.githubusercontent.com/3974928/147655692-040902d6-02b7-4e71-b677-fae1b354de02.png)

However, in the bert model config it uses a different "embedding_size" to indicate the hidden size of the embedding layer, which is different from "hidden_size config", like the following:

![image](https://user-images.githubusercontent.com/3974928/147655811-bfceeba4-9005-43ab-ad3b-5b67bc602a3a.png)

Since the source code uses the config.hidden_size to initialize the embedding layer, is there any way I can pass a different number to initialize it? So that I can successfully convert the tf model to torch. Thanks!

Comments:
Hi,

In that case, I would fork the library, and create a new branch that adjusts the word embeddings to be:

`self.word_embeddings = nn.Embedding(config.vocab_size, config.embedding_size, padding_idx=config.pad_token_id)`

If you then convert the checkpoint from your new branch, it will work.

Thanks. Will it be considered to add this feature into the main branch? Or shall I create a MR for it?

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.

I don't think we are going to include this in the main branch. Therefore, closing this issue.

If you have comments, feel free to reopen.
Prepare deprecated ONNX exporter for torch v1.11
Author: lewtun
Pull request: yes

# What does this PR do?

This PR extends #15270 to ensure the deprecated `transformers.convert_graph_to_onnx` package can also run on `torch` v1.11.

I also took the liberty of adding a deprecation warning to this package.


Comments:
_The documentation is not available anymore as the PR was closed or merged._
[Fix doc example] FlaxMarianPreTrainedModel
Author: ydshieh
Pull request: yes

# What does this PR do?

Tiny fix:

change
```
>>> tokenizer = MarianTokenizer.from_pretrained("facebook/marian-large-cnn")
```
to 
```
>>> tokenizer = MarianTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-de")
```

BTW, `Helsinki-NLP/opus-mt-en-de` has no Flax model checkpoint. The next line

```
 >>> model = FlaxMarianMTModel.from_pretrained("Helsinki-NLP/opus-mt-en-de")
```
will fail I think.


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

@ydshieh `Helsinki-NLP/opus-mt-en-de` already has a flax checkpoint. cf
https://huggingface.co/Helsinki-NLP/opus-mt-en-de/blob/main/flax_model.msgpack

> @ydshieh `Helsinki-NLP/opus-mt-en-de` already has a flax checkpoint. cf https://huggingface.co/Helsinki-NLP/opus-mt-en-de/blob/main/flax_model.msgpack

Great. Sorry, Google search leads me to the wrong page (`de-en` instead ...)
Error loading Speech2Text2Processor.from_pretrained("facebook/wav2vec2-xls-r-2b-21-to-en")
Author: ShRajSh
Pull request: no

- `transformers` version: 4.12.5
- Platform: Linux-5.4.0-90-generic-x86_64-with-Ubuntu-18.04-bionic
- Python version: 3.6.9
- PyTorch version (GPU?): 1.9.0+cu102 (True)
- Tensorflow version (GPU?): 2.6.0 (False)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>


The tokenizer class you load from this checkpoint is not the same type as the class this function is called from. It may result in unexpected tokenization. 
The tokenizer class you load from this checkpoint is 'MBart50Tokenizer'. 
The class this function is called from is 'Speech2Text2Tokenizer'.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/shivam/.local/lib/python3.6/site-packages/transformers/models/speech_to_text_2/processing_speech_to_text_2.py", line 106, in from_pretrained
    tokenizer = Speech2Text2Tokenizer.from_pretrained(pretrained_model_name_or_path, **kwargs)
  File "/home/shivam/.local/lib/python3.6/site-packages/transformers/tokenization_utils_base.py", line 1750, in from_pretrained
    **kwargs,
  File "/home/shivam/.local/lib/python3.6/site-packages/transformers/tokenization_utils_base.py", line 1872, in _from_pretrained
    tokenizer = cls(*init_inputs, **init_kwargs)
  File "/home/shivam/.local/lib/python3.6/site-packages/transformers/models/speech_to_text_2/tokenization_speech_to_text_2.py", line 85, in __init__
    with open(vocab_file, encoding="utf-8") as vocab_handle:
TypeError: expected str, bytes or os.PathLike object, not NoneType


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.

Hey @ShRajSh, 

Sorry we only recently fixed this error. The model should actually be loaded as follows:

```python
Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-xls-r-2b-21-to-en")
```

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.

Think we can close this one now
Make links explicit
Author: Rocketknight1
Pull request: yes

This small change makes the links in the examples `README.md` explicit. Right now the text assumes you're reading it on GitHub, and that you can see the directory tree above. However, the text is copied to https://huggingface.co/docs/transformers/examples where you can't see the directory tree and so can't access any of the examples!

Comments:
_The documentation is not available anymore as the PR was closed or merged._
[deepspeed] saving checkpoint fallback when fp16 weights aren't saved
Author: stas00
Pull request: yes

`_save_checkpoint` saves the deepspeed checkpoint, but this path:

```
push_to_hub => save_model => questionable outcome 
```
for z3 if `stage3_gather_fp16_weights_on_model_save=false` will not save the model, so this PR adds a fallback to saving the full checkpoint instead from which weights can be recovered.

Blocking events:

- [x] https://github.com/microsoft/DeepSpeed/pull/1663 merged
- [x] new deepspeed version released
- [x] our dep table has deepspeed version adjusted to the above version

all resolved

@sgugger 


Comments:
So the idea is that `deepspeed.save_fp16_model()` will return True if the weights have already been saved at the given path in which case there is no need to call `deepspeed.save_checkpoint()`?

That's right. I just want to make sure that someone won't lose their work in case they misconfigured their DS setup.

We could check the DS config on our side as well, but I think all these things should be Deespeed's business.

Looking at your DS pull request, I wonder what do you think about using a new method to tell us if a checkpoint actually exists on disk (perhaps using the tag argument and checking the contents of the `latest` file).

That new method could give us more flexibility/control when calling save_checkpoint()

That would be an ambiguous API, since the checkpoint on disc could pre-exist from an old run. So checking timestamps will be required and it quickly becomes complicated and uncertain.

Given that the saving is super-fast, even for huge 100B models, I think it's no problem if on a rare occasion it will get saved twice.

I think we could have worked out something better in the HF Trainer normal path, but if someone uses parts of the API, that's when things become potentially "unsafe". 

If a user uses parts of the HF Trainer API but builds their own training loop and doesn't care for the saved model then they won't call it. 

Am I missing some path that will do an inefficient double saving in the normal case?

It's just my OCD, I need to get that fixed at some point :-). As far as I'm concerned, the normal case works 100% correctly. Again, many thanks for your work!

IMHO, while OCD in life can be harmful at times, OCD in software should be the standard and not considered a handicap. Especially in a library used by tens of thousands of users.

In other words if you see a path that is invalid we should fix it.

I'm still interested in this. In the mean time, the associated deepspeed change has been included in release 0.5.9. 

Thank you, @MihaiBalint - the version update has to happen in `setup.py` and the dependency table is automatically updated. I adjusted things. testing now as CI doesn't test deepspeed here.
preprocessing_num_workers missing in run_summarization_no_trainer
Author: yanan1116
Pull request: no

Hello, I find that in script: https://github.com/huggingface/transformers/blob/master/examples/pytorch/summarization/run_summarization_no_trainer.py

The `preprocessing_num_workers` does not exist. It just appears in the arguments, but does not take effect in dataset map operations.

So is it intentionally missing ?


Comments:
Seems like an oversight. Do you want to make a PR to fix this?

> Seems like an oversight. Do you want to make a PR to fix this?

Sorry, I don't know how to make a PR.