noamaanMulla-03/transformers-issues huggingface dataset:
[i18n-ar] Translated file : `docs/source/ar/trainer.md` into Arabic
Author: AhmedAlmaghz
Pull request: yes


## What does this PR do?
Translated the `docs/source/ar/trainer.md` file of the documentation to `Arabic العربية`. I use transformers for my side-project and wanted to contribute. As a beginner, this seemed appropriate.

### Some questions:

- I can't access the pr documentation endpoint for `Arabic العربية`. Is there a missing step?
- I left all the other files alone after copying the English docs. Is this acceptable for future updates or should I add contents to the `_toctree.yml` only when translation is complete? Should I delete all other files for a cleaner review?
- In `Arabic`, people use both `Transformer` and `المحولات` to describe the model. However, as this is more of a product of HuggingFace I opted not to translate it. May you please let me know which you would prefer?

Thank you in advance for your review.

Part of #32435

### Before submitting

- [ ] 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?
 @stevhliu , @MKhalusova , @abodacs, may you please review this PR?
 

Comments:
Thank you @abodacs 

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_33080). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

The following pull requests have been added to the current pull request to be merged once

- [x]  Run training on Amazon SageMaker #33071
- [x]  Export to ONNX #33072

@abodacs  , @stevhliu 

أخي عبدالله @abodacs  هذا ما تم إنجازه في هذا القسم 
إلى الامام إن شاء الله



# DEVELOPER GUIDES

- [x]  Use fast tokenizers from 🤗 Tokenizers #33034
- [x]  Run inference with multilingual models #33048
- [x]  Use model-specific APIs #33030
- [x]  Share a custom model #33031
- [x]  Templates for chat models #33026
- [x]  Trainer #33080
- [x]  Run training on Amazon SageMaker #33071
- [x]  Export to ONNX #33072
- [x]  Export to TFLite #33077
- [ ]  Export to TorchScript #33079
- [ ]  Benchmarks #33023
- [ ]  Notebooks with examples #33049
- [ ]  Community resources #33027
- [ ]  Troubleshoot #33017
- [x]  Interoperability with GGUF files #33037


Please, merge this PR.
@stevhliu 

Thank you @stevhliu
add empty cache before load_best_model to prevent cuda OOM
Author: kaiwenw
Pull request: yes

# What does this PR do?

Sometimes `load_best_model` causes cuda OOM at the end of training. 
This PR clears the cache before loading the model and fixes this issue.

## 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:
Agents: turn any Space into a Tool with `Tool.from_space()`
Author: aymeric-roucher
Pull request: yes
Labels: name: Agents

# What does this PR do?

Allows to create tools from Spaces.

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_34561). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

cc @nsarrazin @gary149 have you seen this?
Update llm_engine.py
Author: louisbrulenaudet
Pull request: yes

# What does this PR do?
- Added support for optional token and max_tokens parameters in the constructor.
- Provided usage examples and detailed documentation for each method.

## 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#create-a-pull-request),
      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.
- [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?

Comments:
cc @aymeric-roucher for review

@louisbrulenaudet you'll just have to do a few style fixes (trailing whitespaces) before being able to merge.

Hi @aymeric-roucher, normally I've made the necessary corrections and removed the whitespaces, but I'm still getting a validation error that I can't explain.

Could you tell me what you think is wrong?

@louisbrulenaudet the error in both `check_repository_consistency`  and `check_code_quality` is the following:
```
The following objects docstrings do not match their signature. Run `make fix-copies` to fix this. In some cases, this error may be raised incorrectly by the docstring checker. If you think this is the case, you can manually check the docstrings and then add the object name to `OBJECTS_TO_IGNORE` in `utils/check_docstrings.py`.
- HfApiEngine
```
I believe it might be because 3 of the 4 arguments are defined as `(str, optional)` in the docstrings but are only `str` instead of `Optional[str]` in their signature, so should be `str`in the docstrings (yes the verification is picky 😅). You can run `make fix-copies` to check this.



Hello @aymeric-roucher,

I have the impression that all the tests have been passed, thank you again for your information and your help, I hope that everything will go well from now on and wish you a good day.

It's merged! Thanks a lot for this PR @louisbrulenaudet 🤗

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_33332). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Error when loading openbmb/RLHF-V
Author: pspdada
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.46.2
- Platform: Linux-5.15.0-120-generic-x86_64-with-glibc2.35
- Python version: 3.10.15
- Huggingface_hub version: 0.26.2
- Safetensors version: 0.4.5
- Accelerate version: 1.1.0
- Accelerate config:    not found
- PyTorch version (GPU?): 2.4.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 distributed or parallel set-up in script?: None
- Using GPU in script?: 1
- GPU type: NVIDIA A100-PCIE-40GB

### Who can help?

@zucchini-nlp, @amyeroberts, @qubvel

### 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

With the latest transformers version `transformers==4.46.2`, when I try to load this model by using:
```
model_name = "openbmb/RLHF-V"

model = AutoModelForCausalLM.from_pretrained(
            model_name,
            cache_dir=self.model_dir,
            torch_dtype=self.torch_dtype,
            low_cpu_mem_usage=True,
            device_map=self.device,
            attn_implementation="flash_attention_2" if "cuda" in str(self.device) else None,
        ).eval()
```
or use:
```
from transformers import pipeline

pipe = pipeline("text-generation", model="openbmb/RLHF-V", cache_dir="/root/llm-project/util/model")
```
An error occured: 
```
ValueError: The checkpoint you are trying to load has model type `beit3_llava` but Transformers does not recognize this architecture. This could be because of an issue with the checkpoint, or because your version of Transformers is out of date.
```
This seems to affect more than just this one model. Please identify the issue and fix it.

### Expected behavior

Fix it

Comments:
It looks like they use custom code:
https://huggingface.co/openbmb/RLHF-V/discussions/4#66bf4f95198f9d79f2259ed5

So you should install their library at https://github.com/thunlp/Muffin to properly use their models. 

> It looks like they use custom code: https://huggingface.co/openbmb/RLHF-V/discussions/4#66bf4f95198f9d79f2259ed5
> 
> So you should install their library at https://github.com/thunlp/Muffin to properly use their models.

I'm sorry for my carelessness; this is indeed the solution to the problem.
[i18n-ar] Translated file : `docs/source/ar/troubleshooting.md` into Arabic
Author: AhmedAlmaghz
Pull request: yes


## What does this PR do?
Translated the `docs/source/ar/troubleshooting.md` file of the documentation to `Arabic العربية`. I use transformers for my side-project and wanted to contribute. As a beginner, this seemed appropriate.

### Some questions:

- I can't access the pr documentation endpoint for `Arabic العربية`. Is there a missing step?
- I left all the other files alone after copying the English docs. Is this acceptable for future updates or should I add contents to the `_toctree.yml` only when translation is complete? Should I delete all other files for a cleaner review?
- In `Arabic`, people use both `Transformer` and `المحولات` to describe the model. However, as this is more of a product of HuggingFace I opted not to translate it. May you please let me know which you would prefer?

Thank you in advance for your review.

Part of #32435

### Before submitting

- [ ] 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?
 @stevhliu , @MKhalusova , @abodacs, may you please review this PR?
 

Comments:
Thank you @abodacs
Truncation when tokenizer does not have `max_length` defined
Author: fdalvi
Pull request: no

Hello,

I'm currently writing some code using transformers, and have something similar to:

```python
model = AutoModel.from_pretrained(model_name, output_hidden_states=True)
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)

ids = tokenizer.encode(sentence, truncation=True)
```

The issue I am facing is when sentence has > 512 tokens (wordpieces actually) for certain models. The above code works fine for `bert-base-multilingual-cased`, but fails for `qarib/bert-base-qarib`, because the tokenizer in the latter case does not define a max length:

```bash
Asking to truncate to max_length but no maximum length is provided and the model has no predefined maximum length. Default to no truncation.

....

RuntimeError: The size of tensor a (515) must match the size of tensor b (512) at non-singleton dimension 1
```

So the model itself is limited to 512, but the tokenizer is not aware of this max length. Apart from asking the original model creators to define the max_model_length in their tokenizer, is there anything else I can do to "autodetect" the max length? Can I use `model.config.max_position_embeddings` as a proxy for max length when using the tokenizer?

Thanks!

Comments:
Try this
`tokenizer(sentence, truncation=True, max_length=512)`

`model.config.max_position_embeddings` is the right way to see the max sequence length

Sounds good, thanks for the confirmation!

If it's so simple to check `model.config.max_position_embeddings`, why isn't this the default behaviour when using AutoTokenizer classes instead of raising a warning?
fix typo in trainer_utils/find_executable_batch_size for type hints
Author: Chanstien
Pull request: yes

# What does this PR do?

fix typo in trainer_utils/find_executable_batch_size for type hints

## 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#create-a-pull-request),
      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. 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
- vision models: @amyeroberts, @qubvel
- speech models: @ylacombe, @eustlb
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Rocketknight1
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @SunMarc
- chat templates: @Rocketknight1

Integrations:

- deepspeed: HF Trainer/Accelerate: @muellerzr
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc @MekkCyber

Documentation: @stevhliu

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

 -->


Comments:
Agents: Small fixes in streaming to gradio + add tests
Author: aymeric-roucher
Pull request: yes
Labels: name: Agents

# What does this PR do?

Merge `stream_run` and `direct_run` in one more elegant function to streamline the code.

Comments:
Note to self: my attempt to unify a `stream_run` function that `yield`s results as they come and the `direct_run` function was misled: inserting even the tyniest `yield` in a function turns it into a generator, which I don't want for my `run` function.
Since this PR has nice monitoring tests and improvements, I'll still keep it with only these bits!

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_34549). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Update agents.md 
Author: ish3lan
Pull request: yes

Use the function variable task instead of the hard coded string

# 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 # (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?

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
- vision models: @amyeroberts, @qubvel
- speech models: @ylacombe, @eustlb
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Rocketknight1
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @SunMarc
- chat templates: @Rocketknight1

Integrations:

- deepspeed: HF Trainer/Accelerate: @muellerzr
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc @MekkCyber

Documentation: @stevhliu

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

 -->


Comments:
RingAttention Support
Author: Hambaobao
Pull request: no
Labels: name: Feature request

### Feature request

Hello,

I would like to inquire about the potential inclusion of [RingAttention](https://github.com/lhao499/ring-attention) in `Transformers`, which could enable training with longer sequences.

### Motivation

The incorporation of `RingAttention` would significantly enhance the capabilities for users engaged in advanced projects involving `LLMs` and `LMMs`. I believe this feature would make `Transformers` even more versatile and valuable for the research and development community.

### Your contribution

References:
- [RingAttention](https://github.com/lhao499/ring-attention)
- [LWM](https://github.com/LargeWorldModel/LWM)

Comments:
[Trainer] rename tokenizer to tokenizer_or_processor
Author: Hambaobao
Pull request: no
Labels: name: Feature request

### Feature request

I suggest renaming the `tokenizer` parameter in **Trainer** to `tokenizer_or_processor`.

### Motivation

In the future, the training of many **multimodal models** will certainly require the use of **Trainer**. However, in multimodal models, the processors used to process  data are not just `tokenizer`, but also include things like `tokenizer` and `image_processor`, which are now mostly referred to as `processor`. Renaming `tokenizer` to `tokenizer_or_processor` will help improve the readability of the **Trainer** code during multimodal model development.

### Your contribution

I can help rename `tokenizer` to `tokenizer_or_processor`.

Comments:
fyi @pacman100 and @muellerzr 🤗
🌐 [i18n-KO] Translated herbert.md to Korean
Author: maximizemaxwell
Pull request: yes

# What does this PR do?

Translated the herbert.md file of the documentation to Korean.
Thank you in advance for your review.

Part of https://github.com/huggingface/transformers/issues/20179
## Before reviewing

  - [X]  Check for missing / redundant translations (번역 누락/중복 검사)
  - [X]  Grammar Check (맞춤법 검사)
  - [X]    Review or Add new terms to glossary (용어 확인 및 추가)
  - [X]    Check Inline TOC (e.g. [[lowercased-header]])
  - [ ]    Check live-preview for gotchas (live-preview로 정상작동 확인)

## Who can review? (Initial)

@junejae, @Jwaminju, @010kim, @4N3MONE, @boyunJang
## 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?
   - [ ]    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? (Final)

@stevhliu May you please review this PR?

Comments: