noamaanMulla-03/transformers-issues huggingface dataset:
Update push_to_hub to leverage HTTP API
Author: NielsRogge
Pull request: no

### Feature request

Would be great to update the current `model.push_to_hub`, `tokenizer.push_to_hub`, `processor.push_to_hub`, etc. functionalities to leverage the new `upload_file` method of the `huggingface_hub` library, which only leverages HTTP calls instead of git, making the user experience much, much nicer.



### Motivation

I'm porting models to the hub, and in case I need to update for instance a tiny file (like preprocessor_config.json), the current push_to_hub first pulls all files from the hub (including the weights of the PyTorch checkpoint), then cleans it, etc. This takes a long time (> 10 minutes).

This wouldn't be the case anymore with the new [upload_file](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/hf_api#huggingface_hub.HfApi.upload_file) method.

### Your contribution

Docs is here: https://huggingface.co/docs/huggingface_hub/main/en/how-to-upstream

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.

Closing as this has been fixed per #18366
streamlining 'checkpointing_steps' parsing
Author: rahular
Pull request: yes

# What does this PR do?

As discussed in #18720, changing the `checkpointing_steps` parsing logic in all PyTorch examples with no trainers.

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?

@muellerzr 

Comments:
_The documentation is not available anymore as the PR was closed or merged._
CLI: Improved error control and updated hub requirement
Author: gante
Pull request: yes

# What does this PR do?

This PR adds three things to the `pt-to-tf` CLI:
- Updates the hub minimum version requirement, so that all users can adequately use this CLI (the new `0.9.0` is a requirement to open a PR with a non-god token)
- Adds more flexible admissible error control (some models were failing with errors like 6e-5, which was annoying. The `5e-5` is a magic number anyways)
- Improves the commit message, in case the user fiddles with the admissible error

Comments:
_The documentation is not available anymore as the PR was closed or merged._
VisionEncoderDecoderModel gradient checkpointing
Author: metemadi
Pull request: no

### Feature request

Would love to be able to use gradient checkpointing on VisionEncoderDecoder model.
>>> model.gradient_checkpointing_enable() 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/lib/python3.8/site-packages/transformers/modeling_utils.py", line 1418, in gradient_checkpointing_enable
    raise ValueError(f"{self.__class__.__name__} does not support gradient checkpointing.")
ValueError: VisionEncoderDecoderModel does not support gradient checkpointing.

### Motivation

Gradient checkpointing always helps increase the accessibility of larger models - HuggingFace is awesome!!!

### Your contribution

Happy to take a stab at this if someone can point me to a previous example of this working with an EncoderDecoder model.

Comments:
@NielsRogge, have you seen such examples? :)

Here's a PR that added gradient checkpointing to T5: https://github.com/huggingface/transformers/pull/11353/files

Fixed per #18697
[Wav2vec2 + LM Test] Improve wav2vec2 with lm tests and make torch version dependent for now
Author: patrickvonplaten
Pull request: yes

Trying to correct potentially flaky test: 
```
tests/models/wav2vec2_with_lm/test_processor_wav2vec2_with_lm.py::Wav2Vec2ProcessorWithLMTest::test_word_time_stamp_integration
```
The test actually always passed for me locally.

I've now changed list to tensor as list comparison with float numbers seems brittle. @ydshieh - just to better understand, is this test consistently failing or was it flaky?

Comments:
It fails consistently since PT 1.12.

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

Note after some more debugging the reason seems to be in `datasets`. E.g. this part of the test:

```python
ds = load_dataset("common_voice", "en", split="train", streaming=True)
ds = ds.cast_column("audio", datasets.Audio(sampling_rate=16_000))
ds_iter = iter(ds)
sample = next(ds_iter)
print(sample["audio"]["array"])
```

yields different results between `torchaudio=0.11.0` and `torchaudio=0.12.1`. Opening an issue in Datasets.

@ydshieh good for a second review
failed to use PyTorch jit mode due to: forward() is missing value for argument 'position_ids'.
Author: Captainr22
Pull request: no

I want to use pytorch jit to improve my inference speed on CPU. My model is BertForTokenClassification. And I found position_ids must be given to model if I want to use pytorch jit. 
Could you please give some suggestions to solve this problem? Or the position_ids is indispensable.
Thank you!

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.
FIX: set save state in EarlyStoppingCallback
Author: Richar-Du
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 #16620  (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.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?

## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_18172). All of your documentation changes will be reflected on that endpoint.

As mentioned in the issue you link to, this is not the right fix. This callback is not responsible for saving, only for interrupting training.

control.should_save = True  not work for me

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.
Add TF implementation of LongT5 model
Author: stancld
Pull request: no
Labels: name: TensorFlow

name: New model

### Feature request

Add TF implementation of LongT5 model

### Motivation

Add support for TF backend to allow using LongT5 with TF.

### Your contribution

I will add this :]

cc: @gante @patrickvonplaten 

Comments:
Gonna start working on this today, sorry for delay :]
Support private (Opacus) training of BART by altering BartLearnedPositionalEmbedding's forward method
Author: donebydan
Pull request: no

### Feature request

Alter the signature of `BartLearnedPositionalEmbedding`'s forward method to take a `torch.Tensor` instead of `torch.Size` input.

### Motivation

This will support private fine-tuning of BART via DP-SGD in Opacus. To use Opacus on a custom `nn.Module` like `BartLearnedPositionalEmbedding` there is a fairly reasonable assumption that layers take tensors as input. This assumption falls over with `BartLearnedPositionalEmbedding` since it take a `torch.Shape` input instead.

In particular, `opacus/grad_sample/grad_sample_module.py`  line 190 (the `capture_activations_hook` method) tries to detach the input from device via:

`module.activations.append(forward_input[0].detach())`

If we pass the tensor instead, we can start fine-tuning BART-type summarization models with differential privacy.

### Your contribution

A few lines of code need to be changed in `modeling_bart.py`. In particular, the `forward` signature of `BartLearnedPositionalEmbedding.forward()` and references to this method.

I already have a change with BART-related tests passing. More than happy to create a PR :)

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.
when i use TFGPT2LMHeadModel, how can i build labels and input_ids?
Author: Orient12
Pull request: no
Labels: name: bug

### System Info

when i use TFGPT2LMHeadModel,i don't know how to build input_ids and labels!

### Who can help?

@patil-suraj

### 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

def encode_example(ds, limit=-1):
        print(len(ds))
        input_ids_list = []
        attention_maks_list = []
        label_list = []
        for row in ds:
            input_ids_list.append(row["input_ids"])
            attention_maks_list.append(row["attention_mask"])
            label_list.append(row["labels"])
        return tf.data.Dataset.from_tensor_slices(
            (input_ids_list, attention_maks_list, label_list)).map(map_example_to_dict)

or like this

def encode_example(ds, limit=-1):
        print(len(ds))
        input_ids_list = []
        attention_maks_list = []
        label_list = []
        for row in ds:
            input_ids_list.append(row["input_ids"][:-1])
            attention_maks_list.append(row["attention_mask"][:-1])
            label_list.append([-100 if k == 1 else k for k in row["labels"][1:]])
        return tf.data.Dataset.from_tensor_slices(
            (input_ids_list, attention_maks_list, label_list)).map(map_example_to_dict)




### Expected behavior

who can tell me the input_ids and label format？

Comments:
Hey @Orient12! The `TFGPT2LMHeaDModel` works with CLM objectives. To that end, I think the best way for you to understand how it works would be to try it using the following script: https://github.com/huggingface/transformers/tree/main/examples/tensorflow/language-modeling

This fine-tunes models with the CLM objective.

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.
Model Loading Imbalance
Author: cliangyu
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.20.1
- Platform: Linux-5.4.0-81-generic-x86_64-with-glibc2.31
- Python version: 3.10.4
- Huggingface_hub version: 0.8.1
- PyTorch version (GPU?): 1.12.0 (True)
- 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?: Yes
- Using distributed or parallel set-up in script?: I guess I tried :)

### Who can help?

@patil-suraj @patrickvonplaten @LysandreJik 
This is a OPT related issue.

### 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

```python
with init_empty_weights():
    model = OPTModel.from_pretrained("facebook/opt-6.7b", device_map="auto")
```

Model loading imbalance across the GPUs.

<img width="902" alt="image" src="https://user-images.githubusercontent.com/45140242/179495680-b1a4dae5-be85-4818-a969-8a58346be57d.png">


### Expected behavior

Model parameter numbers are balanced.

Comments:
I think @sgugger is working on that as we speak

Yes, we will add support for more options to `device_map`, one of which is `"balanced"` after the next release. It's already available in Accelerate if you want to try it on.

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.
Allow loading pretrained shared Pytorch checkpoints into flax models
Author: Sea-Snell
Pull request: yes

Motivation: Sharded pytorch checkpoints cannot currently be loaded into flax models; this may be desirable in some cases (e.g. "google/ul2").

Changes: I added an few lines to `modeling_flax_utils.py` to support this behavior. The behavior of the added code exactly matches how sharded checkpoints are loaded in `modeling_utils.py` for pytorch models.

@patrickvonplaten, @patil-suraj

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_18170). All of your documentation changes will be reflected on that endpoint.

Oops! Thanks, just added that import.

Now you'll need to run `make style` to fix the formatting issues :-)

done!

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.
Have 'Random Crop' option for truncation_side for Tokenizer 
Author: SantoshGuptaML
Pull request: no

### Feature request

Currently for the tokenizer, there's only two options for truncation_side, 'right' and 'left'. 

I would like an option for 'random_crop' so that it takes a sequence of max length anywhere from the sequence. 



### Motivation

As a way for data augmentation, some people might want a random crop rather than to consistently get a crop from one side or another. 

This will vary the inputs into the model from the same data source. 

### Your contribution

I'm not quite sure. I don't know Rust which I believe is what the tokenizer is based on. 

Comments:
@SantoshGuptaML Where would you want this to happen?

One option you have is to write a custom slow (non-fast) tokenizer. You can follow this example where the tokenizer is able to make random variations in output tokens: https://github.com/huggingface/transformers/pull/11149/files
afaik rust is used for fast tokenizers, but the slow tokenizers are written in python.

Another option is you can subclass the DataCollator. This allows you to augment samples during training using the Trainer API instead of creating an augmented dataset ahead of time. Here's a working (albeit unoptimized) example of a custom data collator that does what you want.
```
from transformers import DefaultDataCollator
from dataclasses import dataclass
import random


@dataclass
class RandomCropDataCollator(DataCollatorWithPadding):
    random_truncation_token_length = 10

    def __call__(self, features):
        for f in features:
            original_token_length = len(f['input_ids'])
            start_truncation = random.randint(0, original_token_length-self.random_truncation_token_length)
            f['input_ids'] = f['input_ids'][:start_truncation] + f['input_ids'][start_truncation+self.random_truncation_token_length:]
            f['attention_mask'] = f['attention_mask'][:start_truncation] + f['attention_mask'][start_truncation+self.random_truncation_token_length:]
            end_shape = len(f['input_ids'])
            #print(original_token_length, "-------->", end_shape)
        return super().__call__(features)

```
`data_collator = RandomCropDataCollator(tokenizer)`
[colab](https://colab.research.google.com/drive/1HRTDjuKw1TRTRlIT08MhZOXCbViGlpht?usp=sharing)

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.
Troubleshooting.mdx Translation Italian
Author: F02934
Pull request: yes

# What does this PR do?

Fixes # (issue)
Translation of Troubleshooting.mdx (english) to Italian and Update toctree #17459 


## 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?

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.
@mfumanelli 




Comments:
@F02934 Hi, I remade the translation because the previous PR had problem with the commits history. You can check if everything good with the translation and with the toctree

Hi @F02934! Sorry for the late reply.

No worries! You simply have to edit the _toctree file, removing the empty sections, and adding a title, your _toctree file should look like this:

``` yaml
- sections:
  - local: index
    title: 🤗 Transformers
  - local: quicktour
    title: Tour rapido
  - local: installation
    title: Installazione
  title: Iniziare
- sections:
  - local: pipeline_tutorial
    title: Pipeline per l'inferenza
  - local: autoclass_tutorial
    title: Carica istanze pre-allenate con AutoClass
  title: Esercitazione
- sections:
  - local: troubleshooting
    title: Risoluzione dei problemi
  title: Guide pratiche
```

I forgot to add a section and to translate the last title!

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.

Hi @F02934 could you tanslate *How-to Gudes* --> Guide pratiche like in the @mfumanelli example?

@sgugger @omarespejel 

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.
Improve GPT2 doc
Author: ekagra-ranjan
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 the typos and dimensions of args in doc of GPT2.


## 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?


@sgugger

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

Superseeded by #18787
VisualBERT, visual feature projection.
Author: shiv6891
Pull request: no

The default implementation takes in 1x197x768 visual features and gives an error while multiplying 197x768 with 2048x768 (or 1021/512 x 768 depending upon the model used).
Do we really need to modify the inner visual projection code for VisualBERT? Feels weird. Can someone help pl?

Comments:
cc @gchhablani 

@Shiv681991 Can you please share some code examples of what you are trying to do? It'll help me replicate and understand the issue better.

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.