noamaanMulla-03/transformers-issues huggingface dataset:
translate model.md to chinese
Author: ji-huazhong
Pull request: yes

# What does this PR do?
Part of https://github.com/huggingface/transformers/issues/26803


## 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).
- [ ] 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.

<!-- 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:

- text models: @ArthurZucker and @younesbelkada
- vision models: @amyeroberts
- speech models: @sanchit-gandhi
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @gante
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @pacman100

Integrations:

- deepspeed: HF Trainer/Accelerate: @pacman100
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc and @younesbelkada

Documentation: @stevhliu and @MKhalusova

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->

cc @stevhliu


Comments:
pad_across_processes not compatible with PyTorch's nested_tensor
Author: frankier
Pull request: no

### System Info

Latest transformers version

### Who can help?

@muellerzr @pacman100

### 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

To reproduce, take any model, and return a `nested_tensor` from its output, and then train it with `Trainer`. If you give direct be towards a self-contained example to start from, I will modify it to give the error. When pad_across_processes reaches the nested tensor it will try and do stuff like looking at the `len(...)`

### Expected behavior

The simplest fix is to just pass through nested_tensor

```python
    def _pad_across_processes(self, tensor, *args, **kwargs):
        if getattr(tensor, "is_nested", False):
            return tensor
        return super()._pad_across_processes(tensor, *args, **kwargs)
```

This should work, as long as the user processes things correctly themselves themselves in `preprocess_logits_for_metrics`.

There is not an obvious default since numpy doesn't have an exact equivalent. It would be possible to add some default behaviour, e.g. list of numpy arrays, or pad everything using `to_padded_tensor`. I would, however, favor simply bailing out when a nested_tensor reaches preprocess_logits_for_metrics, telling the user they must define custom behaviour. The reason for this is that nested_tensor is not yet stable.

Comments:
Hashlib usage is underspecified
Author: DueViktor
Pull request: no

### Feature request

From python 3.9 hashlib introduced the `usedforsecurity` argument:
> Changed in version 3.9: All hashlib constructors take a keyword-only argument usedforsecurity with default value True. A false value allows the use of insecure and blocked hashing algorithms in restricted environments. False indicates that the hashing algorithm is not used in a security context, e.g. as a non-cryptographic one-way compression function.

`transformers` use hashing in many cases where the purpose is indeed _not for security_ purposes. This should be specifed in the code.



### Motivation

Transformers use MD5 from hashlib, which is not a secure algorithm, but are not specifying that it is for other purposes than security. This is causing issues for organisations following certain security standard. FIPS compliance could be an example. 

### Your contribution

I will attach a PR specifying the usage of hashlib algorithms. Since `usedforsecurity` is only specified from 3.9+ and transformers support 3.6+, I'll add a functionality to detect python version and change kwargs based on that.

Comments:
Hey! Thanks for reporting I'll see if this relevant for us 🤗 

Great @ArthurZucker. The pull request have passed all tests already and are ready to merge. 
No behaviour is changed. 

My guess is that pretty much all federal systems in the world would have this issue.
> Federal Information Processing Standards (FIPS) 140-2 is a mandatory standard for the protection of sensitive or valuable data within Federal systems. - https://www.wolfssl.com/license/fips/

Hey @DueViktor! Coming back to you about this request. We've finally specified hashlib usage in [huggingface_hub](https://github.com/huggingface/huggingface_hub/pull/1782), [transformers](https://github.com/huggingface/transformers/pull/27483), [datasets](https://github.com/huggingface/datasets/pull/6414) and [diffusers](https://github.com/huggingface/diffusers/pull/5790). Everything's merged now so I'll close this issue. Thanks again for the heads up!

Hi @Wauplin! Thanks so much for the update and for addressing the hashlib usage across all those libraries. Appreciate your team's prompt action on this matter. Keep up the fantastic work!
Adding LeakyReLU
Author: rafaelpadilla
Pull request: yes

# What does this PR do?

Simple thing.... it includes LeakyReLU in the `ACT2CLS`.
Noticed that the RTDetr official implementation supports "leaky_relu" ([here](https://github.com/lyuwenyu/RT-DETR/blob/3330eca679a7d7cce16bbb10509099174a2f40bf/rtdetr_pytorch/src/nn/backbone/common.py#L70)), which is not being mapped in our ACT2CLS.

Edited: CI failing tests are not related to this PR.

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?
@amyeroberts 

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

Failing tests are note related to this PR: 
`examples/pytorch/test_accelerate_examples.py:176: AssertionError`
`tests/models/auto/test_tokenization_auto.py:428: AssertionError`

@rafaelpadilla Can you rebase on main? There were some fixes last week committed which should resolve these.
flash attention 2.0 for internLM
Author: MaxLEAF3824
Pull request: no


Comments:
cc @younesbelkada 

Hi @MaxLEAF3824 

InternLM is now using the same architecture as Llama as you can see here: https://huggingface.co/internlm/internlm-7b/discussions/4/files 

While waiting for that PR to be merged, you can benefit from FA-2 + intern-LM with the snippet below:

```python
# pip install flash-attn --no-build-isolation

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained(
        "internlm/internlm-7b",
        use_flash_attention_2=True,
        torch_dtype=torch.float16,
        low_cpu_mem_usage=True,
        revision="refs/pr/4"
)
```

cc @Rocketknight1 do you have an idea why https://huggingface.co/internlm/internlm-7b/discussions/4/files did not get merged yet 🙏 

Hi @younesbelkada, we're still waiting on approval from the InternLM team!

OK thanks ! Hopefully it will get merged soon

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.
[`core`] Fix gradient checkpointing `use_reentrant` issues
Author: younesbelkada
Pull request: yes

# What does this PR do?

Partially fixes: https://github.com/huggingface/trl/issues/835 more details coming soon

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.
Improving Typing
Author: Siddhesh-Agarwal
Pull request: no

### Feature request

I was working on a project using Transformers and came across a few functions that had not been typed completely. Example:
1. [TrainingArguments](https://github.com/huggingface/transformers/blob/e1cec43415e72c9853288d4e9325b734d36dd617/src/transformers/training_args.py#L161)
2. [activations_tf.py](https://github.com/huggingface/transformers/blob/e1cec43415e72c9853288d4e9325b734d36dd617/src/transformers/activations_tf.py)
3. [convert_slow_tokenizer.py](https://github.com/huggingface/transformers/blob/e1cec43415e72c9853288d4e9325b734d36dd617/src/transformers/convert_slow_tokenizer.py)

### Motivation

I am a fan to greatly typed code since it makes my code editors' intellisense work better.

### Your contribution

Can I create a PR to solve this?

Comments:
We use typings to make the code readable. We're not looking to have our code **_exactly_** typed if it has to come at the expense of readability. If the changes you have in mind adhere to this mindset, then yes, feel free to open a PR.

I totally get you, I'll be making some small changes here there (Hope to make things a little better)

Hey @LysandreJik, I was going through the code and came across this:

```
class ClassInstantier(OrderedDict):
    def __getitem__(self, key):
        content = super().__getitem__(key)
        cls, kwargs = content if isinstance(content, tuple) else (content, {})
        return cls(**kwargs)
```
> [Source](https://github.com/huggingface/transformers/blob/5bfda28dd36b47912da1cdd0e2e83ab32c7408e4/src/transformers/activations.py#L206-L210)

It seems like transformers is only meant for [python>=3.8](https://github.com/huggingface/transformers/blob/5bfda28dd36b47912da1cdd0e2e83ab32c7408e4/setup.py#L149) and [Dictionary order is preserved since Python 3.7](https://docs.python.org/3/whatsnew/3.7.html). So, I am guessing we can replace the `OrdererDict` with the native `dict`.

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.
update readme
Author: Chanchal-D
Pull request: no

### Feature request

the existing readme is too long.  It should contain prerequisites and license.

### Motivation

I felt bored when I found the readme too long.

### Your contribution

I will make the readme more concise and brief in an interactive way. 

Comments:
Sorry you felt bored :(
What would you remove?

There's a lot of extra theory that is of no use, I can make it short and interactive.  Plus there are 200+ model architectures that are too long. only the key highlights should be mentioned.

For model architectures I get your point, the rest seems pretty much required no? What exactly would you remove?

yes, it is required, but could written in a short and concise way that is easy to understand.

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.
can we support LLM about quantization int4 
Author: toby911
Pull request: no

### Feature request

For individual users, due to limited resources, we have particularly high requirements for the int4 model

### Motivation

For individual users, due to limited resources, we have particularly high requirements for the int4 model

### Your contribution

For individual users, due to limited resources, we have particularly high requirements for the int4 model

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.
Wrongly load .safetensors weights because it loads only depends on file names not weight files
Author: Rickylht
Pull request: no

### System Info

[2023-10-11 16:31:10,112] [INFO] [real_accelerator.py:110:get_accelerator] Setting ds_accelerator to cuda (auto detect)

Copy-and-paste the text below in your GitHub issue and FILL OUT the two last points.

- `transformers` version: 4.31.0
- Platform: Linux-5.15.0-70-generic-x86_64-with-glibc2.31
- Python version: 3.10.13
- Huggingface_hub version: 0.17.3
- Safetensors version: 0.4.0
- Accelerate version: 0.21.0
- Accelerate config:    not found
- PyTorch version (GPU?): 2.1.0+cu121 (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?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>

### Who can help?

_No response_

### Information

- [X] 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

@gante @Narsil 
If there is a file(e.g. json file) with a name "...safetensor...*" in my model directory, it will automatically load .safetensor weights. As there is no .safetensor weights but only .bin weights in my directory.

I found this is because in the following .py 
`/opt/conda/envs/llava/lib/python3.10/site-packages/transformers/modeling_utils.py`

line 112: `_safetensors_available = _is_package_available("safetensors")`

line 41: `def _is_package_available(pkg_name: str, return_version: bool = False) -> Union[Tuple[bool, str], bool]:`

It only depends on the file name not the existence of weights file. 
I think it is better to check whether '.safetensor' at the end of the file names since the corresponding json file of safetensor named as 'model.safetensors.index.json'. 

### Expected behavior

If there is no .safetensor weights in my dir, don`t load the .safetensor but load .bin weights.

Comments:
Hmmm indeed, would you like to offer a fix?

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.
Adding leaky relu in dict ACT2CLS
Author: rafaelpadilla
Pull request: yes

# What does this PR do?

Simple thing.... it includes LeakyReLU in the `ACT2CLS`.
Noticed that the RTDetr official implementation supports "leaky_relu" ([here](https://github.com/lyuwenyu/RT-DETR/blob/3330eca679a7d7cce16bbb10509099174a2f40bf/rtdetr_pytorch/src/nn/backbone/common.py#L70)), which is not being mapped in our ACT2CLS.

Edited: CI failing tests are not related to this PR.

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?
@amyeroberts 

Comments:
tokenizer.decode throwing an error for TransfoXLTokenizer
Author: dsplog
Pull request: no

### System Info

- `transformers` version: 4.34.0
- Platform: Linux-5.15.0-88-generic-x86_64-with-glibc2.17
- Python version: 3.8.18
- Huggingface_hub version: 0.17.3
- Safetensors version: 0.4.0
- Accelerate version: 0.23.0
- Accelerate config: 	not found
- PyTorch version (GPU?): 2.1.0+cu121 (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?: no
- Using distributed or parallel set-up in script?: no




### Who can help?

_No response_

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

```
from transformers import TransfoXLTokenizer
tokenizer = TransfoXLTokenizer.from_pretrained("transfo-xl-wt103")

enc = tokenizer.encode("Hello, my dog is cute")
enc
[14049, 2, 617, 3225, 23, 16072]

tokenizer.decode(enc)
Traceback (most recent call last):
File "", line 1, in
File "/home/home/.local/lib/python3.8/site-packages/transformers/tokenization_utils_base.py", line 3738, in decode
return self._decode(
File "/home/home/.local/lib/python3.8/site-packages/transformers/tokenization_utils.py", line 1001, in _decode
filtered_tokens = self.convert_ids_to_tokens(token_ids, skip_special_tokens=skip_special_tokens)
File "/home/home/.local/lib/python3.8/site-packages/transformers/tokenization_utils.py", line 982, in convert_ids_to_tokens
tokens.append(self._convert_id_to_token(index))
File "/home/home/.local/lib/python3.8/site-packages/transformers/models/transfo_xl/tokenization_transfo_xl.py", line 451, in _convert_id_to_token
return self.idx2sym[idx]
IndexError: list index out of range
```

### Expected behavior

`tokenizer.decode(enc) `should not throw an error

additional note : 
could see tokenizer.sym2idx defined, but tokenizer.idx2sym is an empty list.

this issue is not there till transformer version 4.33.3
after that, from v4.34.0 till v4.35.2, we have this issue. could see tokenizer.sym2idx defined, but tokenizer.idx2sym is an empty list.

Comments:
Thanks for reporting 😉 @jtang98 fixed this 🔥
Add `convert_hf_to_openai.py` script to Whisper documentation resources
Author: zuazo
Pull request: yes

# What does this PR do?

This PR updates the Whisper model documentation by adding a link to the [`convert_hf_to_openai.py`](https://github.com/zuazo-forks/transformers/blob/convert_hf_to_openai/src/transformers/models/whisper/convert_hf_to_openai.py) script in the Resources section. The script converts Whisper models from the Hugging Face format back to the original OpenAI format.

A brief example is included to demonstrate how to use the script. This addition will help users who prefer working with the original OpenAI implementation or require specific features from it.

Of course, any feedback is welcome! And sorry for the delay!

Fixes #26854

## Before submitting
- [x] This PR fixes a typo or improves the docs.
- [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/)? Yes, see here: https://github.com/huggingface/transformers/pull/26854#issuecomment-1765861491
- [x] Did you make sure to update the documentation with your changes?
- [x] Did you write any new necessary tests? Yes, there are doctests inside the script code.


## Who can review?

Possible candidates:
- `convert_openai_to_hf.py` script creator: @ArthurZucker
- Speech models: @sanchit-gandhi

Comments: