noamaanMulla-03/transformers-issues huggingface dataset:
CLI: use hub's `create_commit`
Author: gante
Pull request: yes

# What does this PR do?

This PR changes the method to open PRs in `pt-to-tf` to the permanent method defined by the hub -- `create_commit`. It also updates the commit description (it now supports line breaks 🎉 ) and adds a flag to add extra description (so I can programmatically tag the right HF maintainer in certain repos)

We can see an example PR [here](https://huggingface.co/joaogante/test_text/discussions/9) -- @Rocketknight1 confirms that the notification got to him!

After this PR gets merged, we can announce `pt-to-tf`, as it no longer depends on unreleased functionality 🚀 

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

Some CI runs have hub 0.7.0 cached, figuring how to best update it
Offload fixes
Author: sgugger
Pull request: yes

# What does this PR do?

This PR fixes a few bugs in the current offload to disk implementation via Accelerate.

1. The `offload_folder` is not created if it doesn't exists, loading to cryptic errors about missing files.
2. When the model is a task model and the checkpoint one of the base model (like for OPT), there are two issues arising:
    - if `offload_state_dict=True`, the weights should be reloaded in `model_to_load` from the temporary offload
    - all the weights offloaded to disk are missing the `base_model_cls` prefix since they were offloaded as weights of `model_to_load` and not of `model`.

Comments:
_The documentation is not available anymore as the PR was closed or merged._
[WIP] Add Jukebox model 
Author: ArthurZucker
Pull request: yes
Labels: name: WIP

This is a draft pull request. 

# What does this PR do?
This PR will progressively add the [Jukebox](https://openai.com/blog/jukebox/) model to the hub.
It is linked to [#16870](https://github.com/huggingface/transformers/issues/16870). 

# Currently planned steps (WIP)

- [x]  Create template files with `transformeres-cli add-new-model-like`
- [x] `src/transformers/tokenization_jukebox.py`
- [x]  `src/transformers/test_tokenization_jukebox.py`
- [x]  `src/transformers/configuration_jukebox.py`
- [x]  `src/transformers/modeling_jukebox.py`
- [ ]  `src/transformers/configuration_jukebox.py`
- [ ]  `docs/source/model_doc/jukebox.rst`
- [ ] `src/transformers/tokenization_jukebox_fast.py` (will most probably use WordLevel tokenizer). Also requires to implement a converter function `class JukeboxConverter(Converter):`




Comments:
Tokenizer and corresponding test should be done. Lacking some detailed description and also probably something about the arguments in the init that are not data but I don't remember if I should create setters (@patrickvonplaten would love to have your review)

Cool nice to see much progress here! 

Feel free to also add a file that shows how you compare OpenAI's original to the current (HF) implementation

What happened to the git commit history here?

I rebased instead of merging 🤕 Will create a new PR to replace that one 

See followup in #17826
Improve error message Union not allowed
Author: BramVanroy
Pull request: yes

I am working with a lot of custom Dataclasses inside the `HfArgumentParser`, and while my Python code was technically correct (using `Union`), I did get the brief error message _Only `Union[X, NoneType]` (i.e., `Optional[X]`) is allowed for `Union`_. From the error message it was not clear what triggered it, and it took me a while to figure out why I could not use Union. My assumption now is that we cannot use Union due to limitations of `argparse` (I am not sure yet how I can allow for floats and ints though).

This PR simply clarifies the error message a bit and gives the field name of the offending item.

Minimal test case:

```python
from typing import Union

from dataclasses import dataclass, field
from transformers import HfArgumentParser


@dataclass
class OtherArguments:
    validation_size: Union[float, int] = field(
        default=0.2  # might be a float for percentage of training set or int for absolute split
    )


if __name__ == '__main__':
    dataclass_tester = OtherArguments(0.5)
    parser = HfArgumentParser((OtherArguments, ))

    oargs = parser.parse_args_into_dataclasses()
```

EDIT: my current solution to allow for floats and ints is below, but the PR is still useful in itself I think.

```python
from argparse import ArgumentTypeError
from typing import Union

from dataclasses import dataclass, field
from transformers import HfArgumentParser


def float_or_int(arg: str):
    # I am aware that this is very naive (e.g. scientific notations), but it works for my purposes.
    # Other suggestions welcome though
    likely_float = "." in arg  
    try:
        arg = float(arg)
    except ValueError:
        raise ArgumentTypeError(f"{arg} is not a float-able input")

    if not likely_float:
        arg = int(arg)
    return arg


@dataclass
class OtherArguments:
    validation_size: float_or_int = field(
        default=0.2,
        metadata={"help": "If a validation set is not present in your dataset, it will be created automatically from"
                          " the training set. You can set the ratio train/valid here (float) or an exact number of"
                          " samples that you wish to include in the validation set (int)."}
    )


if __name__ == '__main__':
    parser = HfArgumentParser((OtherArguments, ))

    oargs = parser.parse_args_into_dataclasses()[0]
    print(oargs.validation_size)
    print(type(oargs.validation_size))
```

@sgugger 

Comments:
_The documentation is not available anymore as the PR was closed or merged._
[Closed - code changes not shown on GH for unknown reason] replace `Python-base tokenizer` by `non-fast tokenizer` in error message
Author: SaulLu
Pull request: yes

# What does this PR do?

As one user rightly pointed out in an issue #17809, when a user receives the V error it is not obvious that a python-based tokenizer refers to a tokenizer class without the term Fast at the end. 

I therefore propose to change the error messages using this term to refer to the term fast which is more easily understood by users.

Fixes #17809


## 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.


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_17825). All of your documentation changes will be reflected on that endpoint.
Changing the number of hidden layers for BERT
Author: paul-you
Pull request: no
Labels: name: wontfix

## ❓ Questions & Help

Hello, 

when reducing the number of hidden layers for BERT, say from 12 to 3, which layers are loaded from the pretrained model, the first 3 layers or the last 3 ones? and is there a way to control this?

Thanks in advance


Comments:
Hi,
The first ones are loaded and there is currently no simple way to control this.

**Is there any evidence than the first layers is the best choice when reducing the number of layers ?**

For example in your article about Distil-Bert, you chose to initialize the student by taking the even layers. Why so ?

> For example in your article about Distil-Bert, you chose to initialize the student by taking the even layers. Why so ?

It empirically produces stronger performance.
There are some other empirical evidences in [this paper](https://arxiv.org/abs/1909.11556) from Angela Fan, Edouard Grave and Armand Joulin.

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.


I also want to ask this
Fix artifact path for cuda extension test in push CI
Author: ydshieh
Pull request: yes

# What does this PR do?

Fix artifact path for cuda extension test in push CI

### More details
In #17335, `working-director` is updated (a fix) for (single-gpu) cuda extension test, but the artifact path was not updated, which leads to strange slack report.

```bash
      - name: Run all non-slow selected tests on GPU
        working-directory: /workspace/transformers
        ...
```

Comments:
Get different weights from model.get_input_embeddings()
Author: heya5
Pull request: no
Labels: name: bug

### System Info

```shell
@patil-suraj, @patrickvonplaten

- `transformers` version: 4.10.0
- Platform: macOS-10.16-x86_64-i386-64bit
- Python version: 3.8.3
- PyTorch version (GPU?): 1.11.0 (False)
- Tensorflow version (GPU?): not installed (NA)
- 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>
```


### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

```py
from transformers import GPT2Config, GPT2LMHeadModel
config = GPT2Config.from_pretrained("gpt2")
model = GPT2LMHeadModel(config=config)
# print (model1.get_input_embeddings().weight.shape)
arr = model.get_input_embeddings().weight.detach().numpy()
print (arr)
print (arr.shape)
```


<img width="573" alt="image" src="https://user-images.githubusercontent.com/27731754/175279258-f0551493-2c42-4dbd-a17f-257d8298ae7c.png">

### Expected behavior

```shell
I think `model.get_input_embeddings()` should give same weights every time when it was called
```


Comments:
Sorry, I made a mistake. I got answer from the documents.

> config (:class:`~transformers.GPT2Config`): Model configuration class with all the parameters of the model.
        Initializing with a config file does not load the weights associated with the model, only the
        configuration. Check out the :meth:`~transformers.PreTrainedModel.from_pretrained` method to load the model
        weights.

I need use `GPT2LMHeadModel.from_pretrained("gpt2")` rather than `GPT2LMHeadModel(config=config)`
TF: generate without `tf.TensorArray`
Author: gante
Pull request: yes

# What does this PR do?

Some models, like XLNet, need more than just the previous token when `past` is used. This PR solves this problem with the help of some refactoring -- we no longer use `TensorArray`, instead we scatter updates into a fixed-size tensor. This refactor simplifies `generate`, especially `beam_search`, which may prove to be helpful in enabling XLA.

Slow tests have been run for the usual generate models (gpt2, t5, rag, speech_to_text, encoder_decoder, vision_encoder_decoder, bart).

### Why was this refactor needed?

As it can be read in [this issue](https://github.com/tensorflow/tensorflow/issues/56272), `TensorArray` is meant to be used as a write-once array, anything else falls in the unexpected behavior domain -- in other words, our use was dangerous. The original solution to the XLNet problem was to read all existing tokens from the `TensorArray`, using the same logic as in this PR, but it failed with XLA -- and the behavior depended on what was written into the variable on its first write. Since we use fixed-size tensors, a normal tensor works just fine, and with simpler code (assuming the reader is familiar with how scatter works :D ).

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

cc @ydshieh -- this PR fixes the XLNet generate error we have been seeing :)

Cool!

@Rocketknight1 no differences in terms of execution speed 👍 

`GPT2` `sample` on a 3090, average of 10 runs (excluding compilation time)
- Eager: 884 ms -> 888 ms
- XLA: 29.2 ms -> 29.3 ms
- JAX: 19.7 ms
Update type hints modeling_yoso.py 
Author: F02934
Pull request: yes

# What does this PR do?

Type hints for modelling yoso PYTORCH
#16059 
Fixes # (issue)


## Before submitting
- [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [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.
- [x] 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).
- [x] 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.
@Rocketknight1 


Comments:
HI @Rocketknight1 this should be it, you can check if everything is good. If there's some problem I will resolve it tonight!

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

Nope, this is perfect. Thanks for the PR, and sorry for the confusion with the last one!
Add missing type hints for QDQBertModel
Author: willtai
Pull request: yes

# What does this PR do?
Adding missing type hints for QDQBertModel as referenced in this issue.(https://github.com/huggingface/transformers/issues/16059#issuecomment-1160830014).

## Before submitting
- [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.
- [x] 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?

@Rocketknight1 
EDIT: Anyone feel free to review too 😄 


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

Hey, this looks really good! Would you be willing to add type hints to the other model classes in the same file too? (`QDQBertLMHeadModel` and the classes that start with `QDQBertFor...`)

@Rocketknight1 I've pushed a change that also adds type hints for `QDQBertLMHeadModel` and the classes that start with `QDQBertFor...`. I've also removed `config` which was unused parameter, but left the other classes untouched, as those seem a bit tricky to type hint for now

@Rocketknight1 I am getting the following error for tests

```
E   ImportError: cannot import name 'login' from 'huggingface_hub' (/home/circleci/.local/lib/python3.7/site-packages/huggingface_hub/__init__.py)
```

Is there a dependency change for huggingface_hub perhaps?

Also, I have removed the type hints for the config objects passed as `python utils/check_copies.py` fails due to line above `class QDQBertEmbeddings`
```
# Copied from transformers.models.bert.modeling_bert.BertEmbeddings with Bert -> QDQBert
```

@willtai I suspect something like that is the problem, yes. Can you try:

1) Pulling upstream commits from `transformers` to your repository's `main` branch (you can do this in the Github interface)
2) Pull those changes from Github to your local machine's `main` branch
3) Rebase your PR branch onto `main` locally
4) Force push (`push -f`) your PR branch to Github

This should resolve those issues if they're caused by a recent code change 

This is perfect, thank you! The rebase looks clean and all tests are passing, so I'm happy to merge it now.
Properties of unset special tokens return the string 'None' in non verbose Tokenizers
Author: guillaumekln
Pull request: no
Labels: name: bug

### System Info

```shell
- `transformers` version: 4.20.0
- Platform: Linux-5.4.0-120-generic-x86_64-with-glibc2.27
- Python version: 3.8.0
- Huggingface_hub version: 0.7.0
- PyTorch version (GPU?): 1.11.0+cu102 (False)
- Tensorflow version (GPU?): not installed (NA)
- 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

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

For example, `MarianTokenizer` does not set `bos_token`. The corresponding property returns the string `'None'`:

```python
>>> import transformers
>>> tokenizer = transformers.MarianTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-de", verbose=False)
>>> tokenizer.bos_token
'None'
```

### Expected behavior

```shell
The property should return None, not the string 'None'.
```


Comments:
Hi @guillaumekln ,

Thanks a lot for letting us know about this issue! ~~I'm planning to fix it in the PR #17824~~ EDIT: sorry, I haven't seen your PR. Closing mine in favor of yours :hugs: 

Thanks for the update! I also suggested a fix here #17797. Feel free to close this PR if needed.

Let's keep yours!
replace `Python-base tokenizer` by `non-fast tokenizer` in error message
Author: SaulLu
Pull request: yes

# What does this PR do?

As one user rightly pointed out in an issue #17809, when a user receives the error `"tokens() is not available when using Python-based tokenizers"` it is not obvious that a python-based tokenizer refers to a tokenizer class without the term Fast at the end. 

I therefore propose to change the error messages using this term to refer to the term fast which is more easily understood by users.

Fixes #17809


## 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. Would love to have the approval of @sgugger , @LysandreJik , @patrickvonplaten or @patil-suraj :hugs: 


Comments:
_The documentation is not available anymore as the PR was closed or merged._
Fix properties of unset special tokens in non verbose mode
Author: guillaumekln
Pull request: yes

# What does this PR do?

Fixes #17796.


## 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).
- [x] Did you write any new necessary tests?


## Who can review?

@n1t0, @LysandreJik

<!-- 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._