noamaanMulla-03/transformers-issues huggingface dataset:
Add dia
Author: ArthurZucker
Pull request: yes

# What does this PR do?
Superseeds #37832 as it was on the main branch did not want to push to it!

Todos:
- cleanup cache, attention masks and cache positions. 
- cleanup generation, might be a way to make it `generate` compatible? if you always sample the top_k *num_channel tokens, you are getting the correct number of tokens. 

Comments:
Closing as #38405 supersedes this :)
vLLM v0.9.2: Qwen2.5-Omni-7B-AWQ fails to load with transformers 4.53.1 (requires 4.52.4)
Author: GreenerZ
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.53.1
- Platform: Linux-6.8.0-62-generic-x86_64-with-glibc2.35
- Python version: 3.12.11
- Huggingface_hub version: 0.33.2
- Safetensors version: 0.5.3
- Accelerate version: 1.8.1
- Accelerate config: 	not found
- DeepSpeed version: not installed
- PyTorch version (accelerator?): 2.7.0+cu128 (CUDA)
- 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?: <fill in>
- Using GPU in script?: <fill in>
- GPU type: NVIDIA GeForce RTX 4090


### Who can help?

When deploying the Qwen2.5-Omni-7B-AWQ model using vLLM v0.9.2 and Transformers v4.53.1, the service fails to start due to a type mismatch in the image processor class. 
Error Log
`The system expects a Qwen2VLImageProcessor, but receives a Qwen2VLImageProcessorFast instead.`

This issue is resolved by downgrading transformers to version 4.52.4.

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

image: vllm/vllm-openai:v0.9.2
command: >
--model=/models/Qwen/Qwen2.5-Omni-7B-AWQ
      --tokenizer_mode="auto"
      --uvicorn-log-level=debug
      --host=0.0.0.0
      --port=8000
      --served-model-name=qwen2.5-omni
      --enable-auto-tool-choice
      --tool-call-parser hermes     
      --dtype=bfloat16
      --trust_remote_code
      --tensor_parallel_size=1

### Expected behavior

Ideally, the model should be able to load and function correctly without requiring a downgrade of the transformers library.

Comments:
Fix link for testpypi
Author: Cyrilvallez
Pull request: yes

# What does this PR do?

2 times facing the link error -> time to update it on main

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

# What does this PR do?
Following up on #39164 lazy init is not really an option for now so for CB we need to make sure we init the cache properly

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_39361). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Small fixes for utils/check_docstrings.py
Author: manueldeprada
Pull request: yes

1. fix ast deprecations for python 3.14 by replacing:
    1.  `node.n` by `node.value` ([deprecation notice](https://github.com/python/cpython/blob/af48f39a440a5c23d89508c038da5d560e74fe48/Lib/ast.py#L530))
    2. `ast.Num` by `ast.Constant` ([deprecation notice](https://github.com/python/cpython/blob/af48f39a440a5c23d89508c038da5d560e74fe48/Lib/ast.py#L1822-L1830))
2. When `--fix_and_overwrite` is passed but fixing fails, exit with a detailed exception instead of failing silently.

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

Hi @manueldeprada  Thanks a lot!

This part is old and I am not the author. I think it makes sense but just have one question.

Looks like our current code is passing this modified check.

can we merge this so that the fail is not silent? I agree that the file needs some further scrutiny to know why 😅  

Before merge, could you update with the main branch , so we could fix the failing if any.
Remove device check in HQQ quantizer
Author: learning-chip
Pull request: yes

Fixes https://github.com/huggingface/transformers/issues/38439

Tested on CPU and NPU, both works out-of-box.

In this case, the HQQ dependency is installed by
```
DISABLE_CUDA=1 pip install git+https://github.com/mobiusml/hqq.git
```

## Who can review?

- quantization (bitsandbytes, autogpt): @SunMarc @MekkCyber



Comments:
@bot /style 

Style bot fixed some files and pushed the changes.

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: hqq

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_39299). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Updated Switch Transformers model card with standardized format (Issue #36979)
Author: giuseppeCoccia
Pull request: yes

# What does this PR do?

It updates the model card for Switch Transformer by following a new standardized format

#36979 

## 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#create-a-pull-request),
      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 -> [link](https://github.com/huggingface/transformers/issues/36979#issuecomment-3052596321)
- [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?

@stevhliu 


Comments:
Hi @stevhliu, thanks a lot for the detailed feedback. I have applied all the changes you suggested in a new commit.
Could you please review it again?

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

Thank you for all that you are making at HuggingFace. I am glad I can contribute to one of the most important, if not the most important, ML libraries out there
Fix bug with deepspeed  and accelerator args in training_args.py
Author: MuyaoLi-jimo
Pull request: yes

### System Info
- transformers version: 4.54.0.dev0
- Platform: Linux-5.4.119-19.0009.28-x86_64-with-glibc2.31
- Python version: 3.10.16
- Huggingface_hub version: 0.31.1
- Safetensors version: 0.4.5
- Accelerate version: 0.22.0.dev0
PyTorch version (GPU?): 2.6.0+cu124 (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?: T
Using distributed or parallel set-up in script?: T

### Who can help?
@SunMarc and @qgallouedec 

### Information
- [x] The official example scripts
- [ ] My own modified scripts

### Tasks
- [x] An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction
Right now any command with --deepspeed /path/to/json will fail and throw the following error

`--deepspeed: invalid Dict value`

This bug has occurred before and was previously fixed in [#24974](https://github.com/huggingface/transformers/pull/24974), but unfortunately, it’s broken again.

The root cause seems to be that Python’s dataclass fields do not support Union[str, dict] when parsed from the CLI.

### Expected behavior
deepspeed flag should support string.


Comments:
This should have been fixed by this PR actually, not sure why this is complaining now. Mind exploring a bit the cause ? https://github.com/huggingface/transformers/pull/30227
Update Readme to Run Multiple Choice Script from Example Directory
Author: eromomon
Pull request: yes

# What does this PR do?

In the Multiple Choice example, the Readme file includes the instruction 
```bash
python examples/pytorch/multiple-choice/run_swag.py \
--model_name_or_path FacebookAI/roberta-base \
--do_train \
--do_eval \
--learning_rate 5e-5 \
--num_train_epochs 3 \
--output_dir /tmp/swag_base \
--per_device_eval_batch_size=16 \
--per_device_train_batch_size=16 \
--overwrite_output
```
which may cause an error when attempting to find the file if the user is currently in the example directory. Assuming the user is in the example directory, this PR suggests removing the complete path and running the Python script directly from that location. Other instructions in this Readme, as well as in other examples, run the script from their respective directories without using the complete path ( examples/DIR_EXAMPLE/SCRIPT.py ).

## 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#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.

@stevhliu hi, I believe you cloud revie this PR.

Comments:
Sure, the PR has been updated to apply changes to the PyTorch examples for contrastive-image-text, summarization, and translation. Additionally, two command lines were updated in the main README.md in the PyTorch folder. Feel free to make any comments. Thank you.

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_39323). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Updated CamemBERT model card to new standardized format
Author: MShaheerMalik77
Pull request: yes

# What does this PR do?

This PR updates the CamemBERT model card `camembert.md`, by standardizing its format according to https://github.com/huggingface/transformers/issues/36979. It includes example code for performing masked language modelling with the pipeline and AutoModel classes, as well as a Quantization example.


## 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#create-a-pull-request),
      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?

@stevhliu please do let me know if you'd like me to make any changes!

Comments:
Hi @stevhliu! I've added all the suggested changes to the CamemBERT model card, please let me know if there's anything else you'd like me to update!

Hi @stevhliu. I went through all unresolved issues, applied all the suggestions and re-added the api references in the proper format. Please do let me know if there's anything you would like me to adjust!

Hi @stevhliu , I have incorporated remaining suggestions to the model document, let me know if there are any further changes you'd like me to make!

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_39227). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
fix gpt2 usage doc
Author: Xiang-cd
Pull request: yes

# What does this PR do?

Fixes # (issue)
 gpt2 usage doc can not execute rightly
@stevhliu

## Before submitting
- [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).

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

# What does this PR do?
As described in the issue, this PR updates the model card for the encoder decoder model with an additional translation example. I have also re-added the contributor names for the Mamba and Mamba-2 models which were previously removed by me. Please let me know if any modifications are required and I will make the necessary changes.

Fixes #8944
Refs #36979

## 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?
@stevhliu

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_39272). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Fix convert_internvl_weights_to_hf.py to support local paths
Author: xvyv99
Pull request: yes

# What does this PR do?

This PR includes one improvements to the convert_internvl_weights_to_hf.py script for converting InternVL models:

- Allows loading model weights directly from a local path, enabling conversion without requiring remote downloads.

This change has been tested and verified on the InternVL2_5-1B, InternVL3-1B model.

Fixes #38200 


## 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.
- [ ] 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 @yonigozlan
update docker file to use latest `timm` (for `perception_lm`)
Author: ydshieh
Pull request: yes

# What does this PR do?

Fix the whole `perception_lm` test suite is failing.

Merge without waiting to make CI better

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_39380). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Fix overriding Fast Image/Video Processors instance attributes affect other instances
Author: yonigozlan
Pull request: yes

# What does this PR do?

Fix an issue raised here https://github.com/huggingface/transformers/pull/39172#issuecomment-3052873789
After internal discussions with @ydshieh , we found that the issue is not due to class attributes, but to lists/dicts being passed around without being copied. 
In fact the same issue is also present in slow image processors, but we don't fix them here, as they all have their own attributes assignment logic, and are to be deprecated.

To reproduce the issue:
```python
>>> o = CLIPImageProcessorFast()
>>> o.image_mean[0]
0.48145466
>>> CLIPImageProcessorFast.image_mean
[0.48145466, 0.4578275, 0.40821073]
>>> o.image_mean[0] = 1
>>> CLIPImageProcessorFast.image_mean
[1, 0.4578275, 0.40821073]
>>>
```

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_39363). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Failed to full fine tuning code5p 2B
Author: latuan1
Pull request: no
Labels: name: bug

### System Info

I got assertion error while saving CodeT5+ 2B:
File "/root/anaconda3/envs/train-model/lib/python3.11/site-packages/transformers/trainer.py", line 2245, in train
return inner_training_loop(
^^^^^^^^^^^^^^^^^^^^
File "/root/anaconda3/envs/train-model/lib/python3.11/site-packages/transformers/trainer.py", line 2627, in _inner_training_loop
self._maybe_log_save_evaluate(
File "/root/anaconda3/envs/train-model/lib/python3.11/site-packages/transformers/trainer.py", line 3103, in _maybe_log_save_evaluate
self._save_checkpoint(model, trial)
File "/root/anaconda3/envs/train-model/lib/python3.11/site-packages/transformers/trainer.py", line 3200, in _save_checkpoint
self.save_model(output_dir, _internal_call=True)
File "/root/anaconda3/envs/train-model/lib/python3.11/site-packages/transformers/trainer.py", line 3902, in save_model
self._save(output_dir)
File "/root/anaconda3/envs/train-model/lib/python3.11/site-packages/transformers/trainer.py", line 4006, in _save
self.model.save_pretrained(
File "/root/anaconda3/envs/train-model/lib/python3.11/site-packages/transformers/modeling_utils.py", line 3337, in save_pretrained
misplaced_generation_parameters = model_to_save.config._get_non_default_generation_parameters()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/anaconda3/envs/train-model/lib/python3.11/site-packages/transformers/configuration_utils.py", line 1079, in _get_non_default_generation_parameters
default_config = self.class()
^^^^^^^^^^^^^^^^
File "/root/.cache/huggingface/modules/transformers_modules/Salesforce/codet5p-2b/0083d4d638746e6c9ee3dbd504e6dd68738e3c87/configuration_codet5p.py", line 78, in init
"encoder" in kwargs and "decoder" in kwargs
AssertionError: Config has to be initialized with encoder and decoder config.

### Who can help?

_No response_

### Information

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

### Tasks

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

### Reproduction

https://www.kaggle.com/code/latuan1st/testllm

### Expected behavior

This checkpoint will be saved

Comments:
Hi @latuan1, I confirmed the bug but this is a custom code model, which means the cause is likely some interaction between their outdated code and modern transformers.

To help us resolve this, can you try older versions of `transformers` to see if it works there? If so, a `git bisect` to identify the exact commit causing the issue would be very helpful!

@Rocketknight1 Thank you

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.
MambaInnerFnBackward
Author: HN-BB
Pull request: no

Hello, I'm using MambaConfig and MambaMixer from transformers.

`from transformers.models.mamba.configuration_mamba import MambaConfig
from transformers.models.mamba.modeling_mamba import MambaMixer`

When I train my model with mamba, the error shown below occurs.
`  File "/root/.cache/pypoetry/virtualenvs/reverie-retrieval-VsnhxLU2-py3.8/lib/python3.8/site-packages/torch/_tensor.py", line 522, in backward
    torch.autograd.backward(
  File "/root/.cache/pypoetry/virtualenvs/reverie-retrieval-VsnhxLU2-py3.8/lib/python3.8/site-packages/torch/autograd/__init__.py", line 266, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
RuntimeError: Function MambaInnerFnBackward returned an invalid gradient at index 6 - got [] but expected shape compatible with [1024]`

I applyed #37 to transformers/kernels/falcon_mamba/selective_scan_with_ln_interface.py because it has MambaInnerFnBackward class.
`dB_proj_bias = dB if not ctx.B_proj_bias_is_None else None`
`dC_proj_bias = dC if not ctx.C_proj_bias_is_None else None`
`dout_proj_bias = dout.sum(dim=(1)) if not ctx.out_proj_bias_is_None else None`

However, I have the same error.

Comments:
Hmmn, we'll need a reproducer script to figure this one out! It seems like the forward pass ran correctly but the backward is returning an empty tensor instead of the gradients, which means this bug probably won't be too easy to resolve

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.
Enable RUF013 to enforce optional typing
Author: cyyever
Pull request: yes

# What does this PR do?

This PR adds Optional to remaining types and add `RUF013` rule to enforce that.

RUFF rule `RUF013` checks for the use of implicit Optional in type annotations when the default parameter value is None.


Comments:
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the `Ready for review` button (at the bottom of the PR page). This will assign reviewers and trigger CI.

LGTM! One issue, though: We generally don't enforce type hinting. I understand that this will only enforce `Optional` **where there is already a type hint and the default value is None**, which makes a lot of sense, but I still want to check with the core maintainers @arthurzucker and @cyrilvallez that they're okay with a type hint style check like this!

@Rocketknight1  And only when we write incomplete types that can default to None. If we don't write types for new code, the check doesn't force us to type them.

@ArthurZucker This is useful for accurate typing.

@cyyever can you check the failing files in `check_code_quality`? There may be a version mismatch or something that's causing your `ruff` formatting to differ from our CI's

@Rocketknight1 Because of other packages, ruff was downgraded to 0.9 on my host..

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

No probs @cyyever, it looks good now! cc @arthurzucker @cyrilvallez - let me know if you're okay with adding an extra Ruff rule here to enforce `Optional` or `| None` where there is already a type hint and the default value is None.