noamaanMulla-03/transformers-issues huggingface dataset:
Remove unnecessary slicing in sdpa_attention_forward
Author: justinchuby
Pull request: yes

The slicing in sdpa_attention_forward was there only because some masks were not constructed correctly (I was told). When the key size is dynamic, the slice op also prevents torch.export from correctly reasoning about its size.

cc @vasqu


Comments:
@Cyrilvallez Looks like this change passes the CI.

@vasqu @Cyrilvallez any thoughts? Thanks. This is an important fix we hope to include in the 5.0 release

Responded in https://github.com/huggingface/transformers/pull/41559#discussion_r2468914497

But I'm pro this, we might wanna check some important models with slow run. Let's wait for Cyril for a final decision

Sorry for the delay, I was off as @vasqu mentioned! Still very relevant, would be very happy to finally remove this (and in other attn functions as well, such as the eager ones but I can take care of it myself later no worries)

cc @ydshieh, could you run a more extensive CI run on this PR and tell us whether you see any new failures, especially on older models? I don't have much time to do it manually myself as I need to catch up on all reviews 🤓 Just a bit scared that the fast tests may not be enough on this one!

For sure, thank you for the ping. I will report back today or tomorrow.

run-slow: bert, gpt2, t5, modernbert, vit, clip, detr, table_transformer, got_ocr2, whisper, wav2vec2, qwen2_audio, speech_t5, csm, llama, gemma3, qwen2, mistral3, qwen2_5_vl, llava, smolvlm, internvl, gemma3n, gpt_oss, qwen2_5_omni

This comment contains `run-slow`, running the specified jobs: 

models: ["models/bert", "models/clip", "models/csm", "models/detr", "models/gemma3", "models/gemma3n", "models/got_ocr2", "models/gpt2", "models/gpt_oss", "models/internvl", "models/llama", "models/llava", "models/mistral3", "models/modernbert", "models/qwen2", "models/qwen2_5_omni", "models/qwen2_5_vl", "models/qwen2_audio", "models/smolvlm", "models/t5", "models/table_transformer", "models/vit", "models/wav2vec2", "models/whisper"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/19305173744)

✅ No failing test specific to this PR 🎉 !



[Update] Looks good!



~~The report is good, but let me take a look deeper inside the workflow run to make sure.~~

Alright, amazing @ydshieh, thanks! Merging then! Thanks again @justinchuby for pushing on something we wanted since a long time!
[`PEFT`] Fix prefix tuning
Author: vasqu
Pull request: yes

Prefix tuning is a bit more of a special case where we have different q and kv lengths despite having the encoder attention. We now rely on the mask for kv length now (if provided). The assumption was holding before because causal masks always have q == kv length. Fixes https://github.com/huggingface/transformers/pull/38301#issuecomment-3415672560

cc @BenjaminBossan 

Comments:
run-slow: bert,bart

This comment contains run-slow, running the specified jobs: 

models: ['models/bart', 'models/bert']
quantizations: [] ...

run-slow: bert,bart

This comment contains run-slow, running the specified jobs: 

models: ['models/bart', 'models/bert']
quantizations: [] ...

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

Ping @ArthurZucker could we please get this in before the next release?
Add sentiment analysis example to pipeline tutorial
Author: kowshik-thatinati
Pull request: yes
Labels: name: Code agent slop

Added a simple text-classification example using DistilBERT pipeline. Demonstrates sentiment analysis on multiple inputs.


Comments:
Hi @huggingface-maintainers 👋
I’ve added a sentiment analysis example to the pipeline tutorial.
All CI checks have passed, and the branch has been updated with the latest main.
Could you please approve the pending workflows and review the PR when convenient?
Thank you!

Hi @huggingface-maintainers 👋
I’ve added a sentiment analysis example to the pipeline tutorial.
All CI checks have passed, and the branch has been updated with the latest main.
Could you please approve the pending workflows and review the PR when convenient?
Thank you!

Hi @huggingface-maintainers 👋
I’ve added a sentiment analysis example to the pipeline tutorial.
All CI checks have passed, and the branch has been updated with the latest main.
Could you please approve the pending workflows and review the PR when convenient?
Thank you!
Enhance NER example in pipeline tutorial 
Author: kowshik-thatinati
Pull request: yes
Labels: name: Code agent slop

Added a detailed explanation of Named Entity Recognition (NER) and provided a code example using the Hugging Face transformers pipeline.

Comments:
Hi 👋, just checking in! Could someone please approve the build_pr_documentation workflow when possible?
The PR enhances the NER example in the pipeline tutorial. Thanks for your time and review!

Hi @huggingface-maintainers 👋
I’ve added a NER tutorial example to the pipeline tutorial.
All CI checks have passed, and the branch has been updated with the latest main.
Could you please approve the pending workflows and review the PR when convenient?
Thank you!

Hi 👋, just checking in! Could someone please approve the build_pr_documentation workflow when possible?
The PR enhances the NER example in the pipeline tutorial. Thanks for your time and review!
Remove import to deperated file
Author: yinpeiqi
Pull request: yes


the `tokenization_bert_tf.py` file is already removed, while the import in TYPE_CHECKING is still remain.


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

run-slow: bert

Ah, thank you for the PR! I made #42182 before I realized you'd made this one. I'm going to merge #42182 instead because it also cleans up the reference in `check_docstrings.py`, but thank you for spotting the bug in the first place!
[typo] fix mrope-interleave annotation to avoid ambiguity
Author: JJJYmmm
Pull request: yes

# What does this PR do?

Fixes a small typo in the MRoPE-I comment: the interleaved pattern should be [THWTHWTHW...TT]. 🫡


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

run-slow: qwen3_omni_moe, qwen3_vl, qwen3_vl_moe

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42177). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Load Mixtral-8x22B-Instruct-v0.1 lead to OOM
Author: Hermit-w
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.56.1
- Platform: Linux-5.10.0-1.oe.x86_64-x86_64-with-glibc2.34
- Python version: 3.12.11
- Huggingface_hub version: 0.35.3
- Safetensors version: 0.6.2
- Accelerate version: 1.10.1
- Accelerate config:    not found
- DeepSpeed version: not installed
- PyTorch version (accelerator?): 2.8.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?: yes
- Using GPU in script?: yes
- GPU type: NVIDIA H800

### 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, ...)
- [x] My own task or dataset (give details below)

### Reproduction

The code I used is as follows:
```python
from transformers import AutoModelForCausalLM
import torch

if __name__ == "__main__":
    torch.distributed.init_process_group("nccl")
    model = AutoModelForCausalLM.from_pretrained(
        "mistralai/Mixtral-8x22B-Instruct-v0.1",
        tp_plan="auto",
        tp_size=8,
        dtype="auto",
    )
    torch.distributed.destroy_process_group()
```
I run the script with the command:
```bash
torchrun --nproc-per-node=8 load.py
```

### Expected behavior

Load the model(~262G) with 8×H800(80G) should not lead to OOM

Comments:
cc @sunmarc or maybe @cyrilvallez for TP?

Hey @Hermit-w! Thanks a lot for the report! Indeed, this is not normal at all, there's currently a huge bug leading to parameters called with a number to NOT be sharded!! Opening a PR at once

Thanks for the response. I’ve manually applied the fix to my local source and it works perfectly. 
I will close this issue once the PR is merged.
[TP] Fix parameter detection issue and some invalid TP-plans
Author: Cyrilvallez
Pull request: yes

# What does this PR do?

Fixes https://github.com/huggingface/transformers/issues/42016. Currently, we replace any number in a parameter name with a `*` to match the tp_plan. However, params may contain numbers naturally in their name, such as Mixtral's MLPs containing `w1`, `w2` and `w3` param names. This means that they were replaced, and thus not detected as needing sharding. So basically they would be invisible from the tp_plan and never sharded 🥵🥵

The regex now checks for `.` (dots) on each side of the numbers, to only match layers or list names as we need.

Also fixes a few TP-plans, that were detected wrong by the test 🙃🙃

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

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

run-slow: apertus, aria, deepseek_v2, doge, flex_olmo, gemma3, glm4v_moe, qwen3_next, t5gemma
[`PEFT`] Fix the general test for prefix tuning
Author: vasqu
Pull request: yes

We now require exact masks! The test was utilizing the fact that we lazily cut masks cc @Rocketknight1 

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

# What does this PR do?

hello

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.

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_37082). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Fixed the issue of missing URLs in the "Learn More" section of the Chinese readme file
Author: junminhong
Pull request: yes

# What does this PR do?

Currently, the "Learn More" link in Chinese documents displays this image and does not correctly redirect to the Chinese language family.

<img width="1075" height="89" alt="Screenshot 2025-11-07 at 16 05 23" src="https://github.com/user-attachments/assets/72e8418b-a882-468f-8b47-b3c5e234e293" />


The file `docs/source/zh/migration.md` is translated from `docs/source/it/migration.md`.

## 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.

<!-- 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 @Cyrilvallez
- vision models: @yonigozlan @molbap
- audio models: @eustlb @ebezzam @vasqu
- multimodal models: @zucchini-nlp
- graph models: @clefourrier

Library:

- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- continuous batching: @remi-or @ArthurZucker @McPatate
- pipelines: @Rocketknight1
- tokenizers: @ArthurZucker and @itazap
- trainer: @SunMarc
- attention: @vasqu @ArthurZucker @CyrilVallez
- model loading (from pretrained, etc): @CyrilVallez
- distributed: @3outeille @ArthurZucker
- CIs: @ydshieh

Integrations:

- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization: @SunMarc @MekkCyber
- kernels: @MekkCyber @drbh
- peft: @BenjaminBossan @githubnemo

Devices/Backends:

- AMD ROCm: @ivarflakstad
- Intel XPU: @IlyasMoutawwakil
- Ascend NPU: @ivarflakstad 

Documentation: @stevhliu

Research projects are not maintained and should be taken as is.

 -->


Comments:
cc @stevhliu 

> Thanks for fixing the links!
> 
> I don't think we need to translate and include the `migration.md` doc though as that is quite outdated and no longer exists in the stable version of the docs.

I saw that the updates have already been made in this PR (https://github.com/huggingface/transformers/pull/42006). 

It looks like this PR can be closed now.
3D Object Detection Models
Author: SeucheAchat9115
Pull request: no
Labels: name: New model

### Model description

Hi together,
is there a reason or any other thread where 3D models like those at mmdet3d are discussed to be implemented. I have not found any discussion.
Thanks

### Open source status

- [ ] The model implementation is available
- [ ] The model weights are available

### Provide useful links for the implementation

BEVFormer: 
https://github.com/fundamentalvision/BEVFormer

Comments:
Definitely a good question! I'll try to find a list of specific SOTA models and open an issue to see if people want to contribute them. I'm also happy to contribute some myself if there is a large demand.
Do you have specific models in mind? feel free to edit this issue with specific models, with links to the original implementation 

I would say at least models like BEVFormer, from there we could go anywhere.

Any updates or comments?
VitModel never outputs an attention map
Author: hyenal
Pull request: no
Labels: name: Feature request

### Feature request

Hi everyone, since a [recent commit](https://github.com/huggingface/transformers/pull/39816) we lost the opportunity to output attention maps which I was personally using.

I would like to bring back this feature for `ViTModel`. I am happy to open a PR if this is of interest for the community ?

### Motivation

This was a feature that existed in the past and it was removed.

### Your contribution

I can submit a PR as I did for other feature request in the past

Comments:
Closing since that was a bug on my end, some automated way of switching from sdpa to eager has been removed, apologies.
[`Pop2Piano`] Fix tied weights
Author: vasqu
Pull request: yes

Turns out that the weights were a 2way tie and not 3way as indicated by the original key:
- Only encoder + decoder --> the lm heads are separate

My investigation came originally from the increased runtime in a test, turns out it is due to different weights and hence generation ran longer (longer sequence generated). And the profiler showed the most time was spent on the cache, which is kinda expected as we have to constantly torch cat during the rollout generation.

Fixed by correctly specifying the key and forcing tied weights keys as in bart. I checked with the first 2 integration tests that now pass (the last head version issues and I'm too lazy to resolve them)

NOTE:
It is likely that some other models are also affected by this as it's a mixture of what ties were really expected.

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

run-slow: pop2piano

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42193). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
New docker from AMD
Author: remi-or
Pull request: yes

This PR bumps the AMD docker base image because the last one was malfunctioning.  

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

It works _better_ according to AMD! Time will tell I guess
Add AutoTokenizer mapping for mistral3 and ministral
Author: patrickvonplaten
Pull request: yes
Labels: name: for patch

# What does this PR do?

This PR makes sure that:

```py
from transformers import AutoTokenizer

tok = AutoTokenizer.from_pretrained("mistralai/Mistral-Small-3.2-24B-Instruct-2506")
tok = AutoTokenizer.from_pretrained("mistralai/Ministral-8B-Instruct-2410")
```

works correctly

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

run-slow: auto

None of the test failures look related

Yep, but we need to sort that on our side iMO!
Remove _dynamic_tied_weights_keys
Author: BenjaminBossan
Pull request: yes

* No need to check `_dynamic_tied_weights_keys` and no need for recursion in `_get_tied_weight_keys`
* Updated an error message that mentioned `_dynamic_tied_weights_keys`
* Removed a test that involved `_dynamic_tied_weights_keys`

The attribute is still referenced in the custom `tie_weights` method of `musicgen` and `musicgen_melody`, but my understanding is that the custom method will be removed anyway, so I left it there.

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

When we import a `pytest` test class like `BambaModelTest` into another file to inherit from, this creates a reference to the parent class in the new file. When we run `pytest new_file.py`, both the new child test class **and** the parent class are run. This was causing the `bamba` tests to be run in the `granitemoehybrid` test file and the `cohere` tests to be run in the `cohere2` test file

This PR copies the test code into the new file, replacing the overridden attributes and methods as required, so that there's no reference to the parent class anywhere.

cc @ydshieh

Comments:
run-slow: cohere2, granitemoehybrid

This comment contains `run-slow`, running the specified jobs: 

models: ["models/cohere2", "models/granitemoehybrid"]
quantizations: []

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

Yes, I agree! Will check the changes but in principle yes

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/19341979861)

✅ No failing test specific to this PR 🎉 !


@ydshieh using the `del` solution instead, since it's a lot simpler

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

run-slow: cohere2, granitemoehybrid
fix(quantization): Skip weight initialization for quantized models
Author: mauricioharley
Pull request: yes

## Description

This Pull Request fixes a `RuntimeError` that occurs when loading `llmcompressor` W8A8 quantized models (e.g., `RedHatAI/Qwen2.5-VL-7B-Instruct-quantized.w8a8`) due to an attempt to initialize `int8` weights using `torch.nn.init.normal_()`, which only supports floating-point dtypes.

The issue was identified in `modeling_utils.py` within the `_initialize_missing_keys` method. When `is_quantized` is `True`, the `else` branch was still calling `self.initialize_weights()`, leading to the `RuntimeError`.

## Proposed Change

Added a conditional check `if not is_quantized:` before the call to `self.initialize_weights()` in the `else` branch of the `_initialize_missing_keys` method. This ensures that weight initialization is skipped for quantized models, as their weights are either already defined or will be loaded from a pretrained state dictionary, making the initialization redundant and problematic.

## Related Issue

Closes #39366

Comments:
cc @MekkCyber @SunMarc 

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

run-slow: fbgemm_fp8, finegrained_fp8, higgs, hqq, mxfp4
Use torch._check instead of a test in Gemma3Model
Author: xadupre
Pull request: yes

# What does this PR do?

``torch.export.export`` fails because of a test checking two dimension are equal. This PR replaces the test by ``torch._check``.


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

run-slow: gemma3

> torch.export.export fails 

does it fails even if the dimension are equal ..?
Refactor check_auto_docstring using AST
Author: yonigozlan
Pull request: yes

# What does this PR do?

Use AST instead of parsing the raw code to check for missing args in docstrings of class/functions using auto_docstring

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

@ArthurZucker @Cyrilvallez  Ready to be reviewed ;)

Thanks @Cyrilvallez , it should be good now!

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

run-slow: glm4v, glm4v_moe
Fix _init_weights to safely skip int8 tensors in Qwen2_5_VL model
Author: KaparthyReddy
Pull request: yes

### Summary
This PR fixes the `_init_weights()` method in `Qwen2_5_VLForConditionalGeneration` to safely skip int8 tensors during initialization. Previously, applying `normal_()` on int8 weights caused a RuntimeError when loading quantized models.

### Changes
- Added dtype check in `_init_weights()` to only initialize floating-point tensors (`float16`, `float32`, `bfloat16`).
- Ensures int8 weights from quantized models are skipped safely.
- Verified fix by successfully loading a quantized Qwen2.5-VL model on CPU.

### Motivation
Quantized models (W8A8, int8 weights) could not be loaded directly due to the previous `_init_weights()` implementation. This fix allows smooth loading without RuntimeError, making contributions compatible with LLMCompressor quantized models.

### Verification
- Model loaded successfully on CPU after applying the fix.
- `_init_weights()` safely ignores int8 tensors.

Comments:
cc @mekkcyber for quantization!

Thanks for the feedback! I’ve updated the PR to modify the correct file under src/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py. _init_weights now safely skips int8 tensors while initializing float tensors correctly.

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

run-slow: qwen2_5_vl
Update `test_dynamic_cache_exportability_multiple_run` (failing on torch 2.10 nightly)
Author: ydshieh
Pull request: yes

# What does this PR do?

See 

https://github.com/pytorch/pytorch/issues/167293#issuecomment-3529014252

The suggestion seems to reasonable since the test name is 

> test_dynamic_cache_exportability_multiple_run

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

it's a test, so i won't worry the BC :-)

gotcha, fine by me then :p