noamaanMulla-03/transformers-issues huggingface dataset:
Easier way to download pretrained model files to local
Author: m0hit-aggarwal
Pull request: no
Labels: name: wontfix

# ❓ Questions & Help

<!-- The GitHub issue tracker is primarily intended for bugs, feature requests,
     new models and benchmarks, and migration questions. For all other questions,
     we direct you to Stack Overflow (SO) where a whole community of PyTorch and
     Tensorflow enthusiast can help you out. Make sure to tag your question with the
     right deep learning framework as well as the huggingface-transformers tag: 
     https://stackoverflow.com/questions/tagged/huggingface-transformers 
     
     If your question wasn't answered after a period of time on Stack Overflow, you
     can always open a question on GitHub. You should then link to the SO question 
     that you posted.
     -->

## Details
<!-- Description of your issue -->
Is there any why we can save vocab and models files to local without having to run the following code with cache_dir parameter. What i am asking is some utility or some endpoint from where we could get a tar of all model files.
```
from transformers import BartTokenizer, BartForSequenceClassification
tokenizer = BartTokenizer.from_pretrained('facebook/bart-large',cache_dir='path/to/local_dir')
model = BartForSequenceClassification.from_pretrained('facebook/bart-large',cache_dir='path/to/local_dir')
```
The reason for such a requirement is, we run our code in VMs where there is no internet access, so we have to run the code in our local for every model and save files. It would be helpful if there is a easier way to download all the files for pretrained models as a tar or zip file.

<!-- You should first ask your question on SO, and only if
     you didn't get an answer ask it here on GitHub. -->


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 news on this? We have the same problem when running a Docker-container  (it takes a while to load the model all the time)

Hey! The recommended way of handling that is to use `from_pretrained`/`save_pretrained` to a directory, and to load from that directory from then on.

If for some reason that's not sufficient, you can use the `huggingface_hub` library as shown in the [following guide](https://huggingface.co/docs/huggingface_hub/how-to-downstream). I believe repositories cannot be downloaded as zips currently, cc @osanseviero @julien-c
use base_version to check torch version in torch_less_than_1_11
Author: nbroad1881
Pull request: yes

The current check `version.parse(torch.__version__) < version.parse("1.11")` doesn't work if the version has additional stuff after it like `1.11.0a0+17540c5`.

New way: `version.parse(version.parse(torch.__version__).base_version) < version.parse("1.11")`

This change, as suggested by @whoknowsB [here](https://github.com/huggingface/transformers/pull/16043#issuecomment-1079644824),  fixes it.

Fixes https://github.com/huggingface/transformers/issues/16587 and https://github.com/huggingface/transformers/issues/14375

## Who can review?

@LysandreJik 
@sgugger 


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

> It also properly deals with the `dev0` and the likes, so all good to me, thanks for the fix! Could you just apply the same to the line before (`is_torch_less_than_1_8`) so that next time someone adds a new check like this, they don't hesitate and follow the same model?

Done.
[PegasusConfig] wrong default vocab_size
Author: yaozhaogoogle
Pull request: no

In PegasusConfig (https://github.com/huggingface/transformers/blob/v4.18.0/src/transformers/models/pegasus/configuration_pegasus.py#L108), the default vocab size should be 96000 instead of 50265.
 @patrickvonplaten


Comments:
Hey @yaozhaogoogle,

Thanks for the issue, could you maybe link to the original configuration that shows a default vocab size of 96000?

from the github https://github.com/google-research/pegasus , there is a link to the checkpoints and vocabs, https://pantheon.corp.google.com/storage/browser/pegasus_ckpt . They are all using a single vocab size of 96k

Thanks for the link @yaozhaogoogle, 

Note that in the configuration we just provide a default value that could be used when initializing Pegagus from scratch. If one loads a pretrained checkpoint the vocab size is overwritten by the value defined in the config on the HF Hub. 

E.g. this Pegagus checkpoint: https://huggingface.co/google/pegasus-large/blob/main/config.json#L122 has a vocab size of 96000 which would be used when doing:

```py
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

tokenizer = AutoTokenizer.from_pretrained("google/pegasus-large")

model = AutoModelForSeq2SeqLM.from_pretrained("google/pegasus-large")
```

Thanks for the explanation!
Refactor issues with yaml
Author: LysandreJik
Pull request: yes

This PR:
- Refactors the issue templates using the newly introduced YAML issues.
- Introduces a `config.yml` for issues which enables a redirect to the forum
- Removes the benchmarking issue which has not been used at all and introduces noise in the issue selection process. With its removal, I'm aiming for a lower number of blank issues.

See below for the comparison across issues. To see the issue templates yourself and play with the `config.yml`, head over to [my fork](https://github.com/LysandreJik/transformers/issues/new/choose).

Old         |  New
:-------------------------:|:-------------------------:
Bug report (MD) | Bug report (YML)
<img width="659" alt="image" src="https://user-images.githubusercontent.com/30755778/163278600-b8fd6b21-88bd-426c-976c-5c93115c0e44.png">  |  <img width="660" alt="image" src="https://user-images.githubusercontent.com/30755778/163278655-8ad5ccd0-f7f9-41e4-8334-a5b59d10f55f.png">
Old feature request           |  New feature request
<img width="797" alt="image" src="https://user-images.githubusercontent.com/30755778/163278892-d7736e07-e66d-4a3c-a4d6-8b546f2efb43.png">  |  <img width="796" alt="image" src="https://user-images.githubusercontent.com/30755778/163278913-bd83c945-d125-4739-9eee-a7ff8eb5932b.png">

The new index will now contain additional links, including a link to the forum:

<img width="1044" alt="image" src="https://user-images.githubusercontent.com/30755778/163278991-c5ad6cd8-c08a-4a45-b3c7-560ad2c28180.png">


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

Thanks!

For the new bug report screenshot, looks like the section Who can help is not editable?

The new layout looks good! I would like to have a section 'Code Snippet' if it is not in the new layout yet. 🙂 (Haven't really tried it yet, just looking the screenshots)

> The new layout looks good! I would like to have a section 'Code Snippet' if it is not in the new layout yet. slightly_smiling_face (Haven't really tried it yet, just looking the screenshots)

@ydshieh, yes the reproducible code example is available in the issue, I just migrated the existing issues so everything is still included.

Thanks for your reviews, merging!
fix _setup_devices in case where there is no torch.distributed package in build
Author: dlwh
Pull request: yes

# What does this PR do?

At least in some instances (e.g. conda on my m1), torch is built without distributed support enabled. This takes the form of torch.distributed.is_available() returning false and torch.distributed.is_initialized() raising an exception. In this particular method, it's enough to skip the check if it's not available.

This behavior causing this crash was added in https://github.com/huggingface/transformers/pull/16487

## 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?

  I could mock this out but it seems painful and unnecessary. I can try to do it if you want.


## Who can review?

Seems like @sgugger is the best reviewer here?

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

done!

Thanks!
[SegFormer, BEiT] Clean up tests
Author: NielsRogge
Pull request: yes

# What does this PR do?

BEiT and SegFormer still had some code that I had to remove, as semantic segmentation models are now created in the `_prepare_for_class` method in `test_modeling_common.py` (which was added in #15991).

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Wav2 vec2 phoneme ctc tokenizer optimisation
Author: ArthurZucker
Pull request: yes

# What does this PR do?

This is my FIRST PR! 
The Wav2Vec2PhonemCTCTokenizer is slow when its argument `do_phonemize` is set to True. It re-initialises the backend at each forward pass. This is adressed using a class argument. 

There was also an H4 title in the documentation which had a link which did not render( `<h4></h4>` used to replace `####`)  

Tests were passed, no additional ones were created. Runtime experiments to phonemize the entire 'tr' (turkish) subset of the common voice dataset gives a x10 boost in performances. 

Models:
- Wav2Vec2PhonemeCTCTokenizer: @patrickvonplaten, @LysandreJik 

Documentation: @sgugger



Comments:
_The documentation is not available anymore as the PR was closed or merged._
Some tests misusing assertTrue for comparisons fix
Author: code-review-doctor
Pull request: yes

Fixes #16770

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

tests are failing now because the comparisons are actually being performed by the tests. Before the tests were just checking if the first argument was truthy, because that's what `assertTrue` does.

I'm just a static analysis bot (boop beep) so I'm not sure if the comparisons in the tests are wrong and therefore the tests need updating, or if the logic under test need fixing. Can someone please confirm.

Hey @code-review-doctor,

It seems like you uncovered some bugs in the testing - thanks a lot! Do you want to fix them or should I go ahead and fix them? 

@patrickvonplaten glad to be of service :)

If you could go ahead and fix them that would be great. My "thing" is running static analysis checkers to detect common easily missed mistakes on hundreds of open source projects and then letting them know so they can fixed properly :)

FYI and FWIW I have [GitHub integration](https://github.com/marketplace/django-doctor/) so I can review your PRs to prevent problems like this in future :)



Thanks a lot @code-review-doctor !
Add onnx export of models with a multiple choice classification head
Author: echarlaix
Pull request: yes

This PR adds the export support of models with a multiple-choice classification head, resolving [#16695](https://github.com/huggingface/transformers/issues/16695)

This includes the following additions:
* The `"multiple-choice"` feature was added to the corresponding model topologies
* The dummy inputs are generated to match the expected inputs shape which includes an extra dimension corresponding to the number of candidates answers
* The `inputs` method of the models corresponding `OnnxConfig` were modified to support the additional dynamic axis corresponding to the number of candidates


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

Thanks for the  review as well as the reminder @sgugger !

Thanks for the reviews @lewtun and @michaelbenayoun. 
I have added some comments to make things clearer as well as the BigBird, Data2VecText, Electra and FlauBERT models support. Also when running the command line `RUN_SLOW=1 pytest tests/onnx/test_onnx_v2.py`, all the tests are passing.

Thanks for iterating on this @echarlaix - it looks great!
Add image classification script, no trainer
Author: NielsRogge
Pull request: yes

# What does this PR do?

This PR adds an example script for image classification that leverages Accelerate instead of the HuggingFace Trainer.

To do:

- [x] verify local `train_dir` and `validation_dir`
- [x] update README
- [x] add log fixes (Tensorboard)

Both can be updated after #16585 is merged.

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

@sgugger not sure why, but the test for the script fails:
```
WARNING  datasets.builder:builder.py:388 Using custom data configuration huggingface--image-classification-test-sample-b7448dc7ae37f2cf
INFO     run_image_classification_no_trainer:run_image_classification_no_trainer.py:388 ***** Running training *****
INFO     run_image_classification_no_trainer:run_image_classification_no_trainer.py:389   Num examples = 8
INFO     run_image_classification_no_trainer:run_image_classification_no_trainer.py:390   Num Epochs = 3
INFO     run_image_classification_no_trainer:run_image_classification_no_trainer.py:391   Instantaneous batch size per device = 2
INFO     run_image_classification_no_trainer:run_image_classification_no_trainer.py:392   Total train batch size (w. parallel, distributed & accumulation) = 2
INFO     run_image_classification_no_trainer:run_image_classification_no_trainer.py:393   Gradient Accumulation steps = 1
INFO     run_image_classification_no_trainer:run_image_classification_no_trainer.py:394   Total optimization steps = 12
INFO     run_image_classification_no_trainer:run_image_classification_no_trainer.py:471 epoch 0: {'accuracy': 0.0}
INFO     run_image_classification_no_trainer:run_image_classification_no_trainer.py:471 epoch 1: {'accuracy': 0.0}
INFO     run_image_classification_no_trainer:run_image_classification_no_trainer.py:471 epoch 2: {'accuracy': 0.0}
```
Weirdly, it passes locally for me.

I'm getting issues when only passing `id2label` and `label2id` to the config, but not the `num_labels`:

```
if size_average is not None or reduce is not None:
            reduction = _Reduction.legacy_get_string(size_average, reduce)
>       return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)
E       IndexError: Target 6 is out of bounds.
```

Oh ok, shouldn't be the case. Let's put back the `num_labels` for now and I'll have a look later at why it failed to update properly.
Missing activation Function
Author: RodSernaPerez
Pull request: no

I think the sigmoid / softmax activation function is missing here

https://github.com/huggingface/transformers/blob/31ec2cb2badfbdd4c1ac9c6c9b8a74e974984206/src/transformers/models/roberta/modeling_tf_roberta.py#L1299

Comments:
Hey @RodSernaPerez 👋  The `sigmoid` activation function was added to our list of TF activation functions, it should be operational now (you will have to install `transformers>=4.19.0.dev0` or pull from `main`). 

Feel free to reopen the issue if you run into problems :)
TF: Add sigmoid activation function
Author: gante
Pull request: yes

# What does this PR do?

Fixes #16810 -- adds the sigmoid activation function to the TF activation functions. 

Also sorts the activation functions in the enum-like dict and in the tests, to quickly identify missing functions.

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

As an aside, GELU is a core Keras activation now, although we might have to wait until we can move our minimum version before we can switch to using it instead of our own implementations. Other than that, this looks great!
Correct Logging of Eval metric to Tensorboard
Author: Jeevesh8
Pull request: yes

# What does this PR do?

An empty dictionary ``eval_metrics`` was being logged, is replaced by ``eval_metric`` which is the output dictionary of ``metric.compute()``. Probably this was a typo in the code. 

<!-- Remove if not applicable -->

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).


## Who can review?

@sgugger, @patil-suraj

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

Actually `eval_metrics` is never used, could you delete this line and update the PR ? This will fix the failing test.
https://github.com/huggingface/transformers/blob/d3bd9ac72802c0a3d04c3c63739bcd8f0731b593/examples/flax/text-classification/run_flax_glue.py#L595
replace `Speech2TextTokenizer` by `Speech2TextFeatureExtractor` in some docstrings
Author: SaulLu
Pull request: yes

# What does this PR do?

It seems to me that fbank features can be returned by an `FeatureExtractor` and not by a `Tokenizer`. This PR proposes to make some changes in the docstrings that mention that `Speech2TextTokenizer` should be used to return fbank features. 

It seems to me that among the 3 models - `Speech2Text`, `Speech2Text2` and `SpeechEncoderDecoder` -  only `Speech2Text` implements a feature extractor and I therefore deduce that the same feature extractor class that is used for the 3 models.

## 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. As it concerns audio related model, I would love to have your feedback @patrickvonplaten , @anton-l  or @patil-suraj 

Comments:
_The documentation is not available anymore as the PR was closed or merged._
Improve test_pt_tf_model_equivalence on PT side
Author: ydshieh
Pull request: yes

# What does this PR do?

Same as in #16557, but on PT test side.

Now we only have 2 `def test_pt_tf_model_equivalence` in the common test files 💯 

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

Merged (after a rebase)
Is there pre-train bert or xlnet from scratch code ?
Author: xealml
Pull request: no
Labels: name: Ex: LM (Pretraining)

# ❓ Questions & Help

<!-- The GitHub issue tracker is primarly intended for bugs, feature requests,
     new models and benchmarks, and migration questions. For all other questions,
     we direct you to Stack Overflow (SO) where a whole community of PyTorch and
     Tensorflow enthusiast can help you out. Make sure to tag your question with the
     right deep learning framework as well as the huggingface-transformers tag: 
     https://stackoverflow.com/questions/tagged/huggingface-transformers 
     
     If your question wasn't answered after a period of time on Stack Overflow, you
     can always open a question on GitHub. You should then link to the SO question 
     that you posted.
     -->

## Details
<!-- Description of your issue -->

<!-- You should first ask your question on SO, and only if
     you didn't get an answer ask it here on GitHub. -->
**A link to original question on Stack Overflow**:


Comments:
Yes, you can use the `run_language_modeling.py` script for pre-training e.g. BERT from scratch:

https://huggingface.co/transformers/examples.html#language-model-training

(Just leave the `model_name_or_path` parameter empty for pre-training from scratch)

@stefan-it thank u.

@xealml Curious whether you managed to train XLNet? If so, any pointers you could share? 

@jbmaxwell @xealml I am getting lost on this as well. How do you train XLNet from scratch? I can't find any field for inputting raw data to it
Add class LayoutLMv2ForRelationExtraction
Author: yuan-wenhua
Pull request: yes

# What does this PR do?
Add class LayoutLMv2ForRelationExtraction which in https://github.com/microsoft/unilm/tree/master/layoutlmft

Comments:
I've [implemented](https://github.com/woflowinc/transformers/tree/add-layoutlmv2-re) the requested changes, but I'm not sure how to contribute to this PR from here.

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.

Hi @quasimik,

could you open up a clean PR such that we can add it?
get the error "_forward_unimplemented() got an unexpected keyword argument 'labels'"
Author: FanniSun
Pull request: no
Labels: name: bug

### System Info

```shell
- `transformers` version: 2.11.0
- Platform: Linux-5.4.0-81-generic-x86_64-with-debian-bullseye-sid
- Python version: 3.7.3
- PyTorch version (GPU?): 1.6.0+cu101 (True)
- Tensorflow version (GPU?): 2.7.1 (True)
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>
```


### Who can help?

@LysandreJik 

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction

```
class  Seq2SeqModel(nn.Module):
    def __init__(self, device):
        super(Seq2SeqModel, self).__init__()
        self.device = device
        self.tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")
        self.model = BertModel.from_pretrained("bert-base-uncased")
        self.decoder = BertLMPredictionHead(self.model.embeddings.word_embeddings.weight)

    def farward(self, indexed_tokens, indexed_segment, labels, seq_len = 100):
        ones = torch.ones((1, 1, seq_len, seq_len), dtype=torch.float32, device=self.device)
        a_mask = ones.tril()
        s_ex12 = indexed_segment.unsqueeze(1).unsqueeze(2).float()
        s_ex13 = indexed_segment.unsqueeze(1).unsqueeze(3).float()
        a_mask = (1.0 - s_ex12) * (1.0 - s_ex13) + s_ex13 * a_mask
        enc_layers, _ = self.model(input_ids = indexed_tokens, token_type_ids=indexed_segment,attention_mask=a_mask,
                                   output_all_encoded_layers=True)
        squence_out = enc_layers[-1]
```

When I train the model defined above, train code like this:

```
self.bert_model = Seq2SeqModel(self.device)
_, _ = self.bert_model(token_ids,
                                            token_type_ids,
                                            labels=target_ids,
                                            device=self.device)
```

it return the error: 
`  File "/home/fanni/anaconda3/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
    result = self.forward(*input, **kwargs)
TypeError: _forward_unimplemented() got an unexpected keyword argument 'labels'`
I clearly defined labels and redefines the farward function， why return the error? Looking forward for your reply, thank you！

### Expected behavior

```shell
I should be able to override the 'farward' function and not be affected by the original parameters
```


Comments:
It's my error, I write "forward" to "farward"