noamaanMulla-03/transformers-issues huggingface dataset:
🚨 Clean up `image-text-to-text` pipeline
Author: ebezzam
Pull request: yes

# What does this PR do?

This PR standardizes / cleans up `image-to-text-text` pipeline to use the chat template logic from the base pipeline class.

TODO:
- [x] add function to convert from OpenAI format to HF-format to address [this failing test](https://github.com/huggingface/transformers/blob/f77950605e2f2f27613b829559b133c2b9fd8912/tests/pipelines/test_pipelines_image_text_to_text.py#L363) after https://github.com/huggingface/transformers/pull/42359 removed `add_images_to_messages` (see [here](https://github.com/huggingface/transformers/pull/42359#discussion_r2565062454))


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

run-slow: bark

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

The [last commit](https://github.com/huggingface/transformers/pull/42430/commits/fdc4db18334e3dc2931ba135995ddf57d6db8dc5) is more breaking to enforce chat template usage if the model supports it.
Default model for `image-to-text` pipeline fails to load
Author: davidmezzetti
Pull request: no
Labels: name: bug

### System Info

transformers v5.0.0rc0

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

```python
from transformers import pipeline
pipeline("image-to-text")
```

```
OSError: ydshieh/vit-gpt2-coco-en does not appear to have a file named model.safetensors or model.safetensors.index.json and thus cannot be loaded with `safetensors`. Please make sure that the model has been saved with `safe_serialization=True` or do not set `use_safetensors=True`.
```

### Expected behavior

Pipeline loads

Comments:
cc @ydshieh can you add safetensors weights to that repo? 😅 

Hi pushed the safetensor files. The provided code snippet doesn't give error anymore.

wait, i made a mistake, only running with v4 not v5. still checking

still failing (with v5rc). Something more to check ... please be patient 🙏 

There is something wrong in the codebase:

this code snippet works
```
from transformers import VisionEncoderDecoderModel


repo_id = "ydshieh/vit-gpt2-coco-en"
model_class = VisionEncoderDecoderModel

model = model_class.from_pretrained(repo_id, use_safetensors=True)
print(model)
```
while the pipeline loading fails.

At the line

> if resolved_archive_file is None and filename == _add_variant(SAFE_WEIGHTS_NAME, variant):

in the file `src/transformers/modeling_utils.py`, 

- `resolved_archive_file` is `None` when running with pipeline loading for this model.
  - then it went to the `if` branch and fails inside it  
- `resolved_archive_file` is `/root/.cache/huggingface/hub/models--ydshieh--vit-gpt2-coco-en/snapshots/e46020106a48310f1eff33b3b31a9f139d752cc1/model.safetensor` when running with model loading

I need to check what's wrong.

It's from

Refactor weight loading (#41580)

I have ping the people internally. 

OK, fixed by 

#42618 

I verified it works, so close the issue. Let me know if you still encounter problems with this.
Update revision so that there is a safetensors model
Author: LysandreJik
Pull request: yes

The linked revision does not contain a safetensors model

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42618). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Every model forward() should have **kwargs
Author: Rocketknight1
Pull request: yes

This PR ensures every model inheriting directly or indirectly from PreTrainedModel accepts `**kwargs` in its `forward()` method. We were quite inconsistent about this before, and not accepting them causes issues in some cases. It also adds a test to `check_repo.py` to ensure we stay consistent in future!

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42603). 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: align, altclip, audioflamingo3, autoformer, bark, bart, beit, big_bird, bigbird_pegasus, biogpt, bit, blenderbot, blenderbot_small, blip, blip_2, bloom
Refactor: Remove redundant else in get_activation
Author: leaderofARS
Pull request: yes

Hi! I was reading through 
activations.py
 to better understand how the library handles activation mappings, and I noticed a small opportunity to clean up the 
get_activation
 function.

Since the if block returns early, the else block isn't actually needed. I've removed it to flatten the logic a bit. I know it's a tiny change, but I figured it was worth polishing up to keep the code readable.

Comments:
Hey! Can you run `pip install -e .[quality]` followed by `make style` to get the code quality tests to pass?
[core] Fix quark
Author: MekkCyber
Pull request: yes

# What does this PR do?

Fix Quark after weight refactor, all tests passing locally

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

@bot /style

Style bot fixed some files and pushed the changes.

@bot /style 

Style fix is beginning .... [View the workflow run here](https://github.com/huggingface/transformers/actions/runs/19895066454).

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

run-slow: quark_integration
Fix _is_package_available to handle underscore/hyphen equivalence
Author: mertunsall
Pull request: yes

## Problem

`is_flash_attn_2_available()` returns `False` when both `sgl-kernel` and `flash-attn` are installed, even though `flash-attn` 2.8.1 works fine.

**Reproduction:**
```python
# Simulates the bug when distributions = ['sgl-kernel', 'flash-attn']
pkg_name = "flash_attn"
distributions = ["sgl-kernel", "flash-attn"]

# Current logic (line 60)
result = pkg_name if pkg_name in distributions else distributions[0]
print(result)  # 'sgl-kernel' ❌ (version 0.3.16, fails >= 2.1.0 check)

# 'flash_attn' not in ['sgl-kernel', 'flash-attn'] because underscore ≠ hyphen
```

## Root Cause

`importlib.metadata.packages_distributions()` returns multiple distributions for `flash_attn`. The check `pkg_name in distributions` fails because `'flash_attn'` (underscore) doesn't match `'flash-attn'` (hyphen), so it falls back to `distributions[0]`.

## Fix

Per PEP 503, underscores and hyphens are equivalent in package names. Normalize before matching:

```python
normalized_pkg_name = pkg_name.replace("_", "-")
if normalized_pkg_name in distributions:
    distribution_name = normalized_pkg_name
elif pkg_name in distributions:
    distribution_name = pkg_name
else:
    distribution_name = distributions[0]
```

Now `flash_attn` → `flash-attn` → correct version `2.8.1` ✓

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42615). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Fix incorrect fix_mistral_regex warning for local non-Mistral tokenizers
Author: arrdel
Pull request: yes
Labels: name: Code agent slop

## What does this PR do?

Fixes #42591

This PR fixes an issue where loading a local non-Mistral tokenizer incorrectly triggers the `fix_mistral_regex` warning.

## The Problem

When loading a local tokenizer with a `config.json` file, the code was setting `mistral_config_detected = True` unconditionally on line 1136, regardless of whether the model was actually a Mistral variant or not.

This caused the warning to be triggered for **all** local tokenizers, including non-Mistral models like LLaMA, GPT, etc.

### Before:
```python
# Line 1136 in tokenization_utils_tokenizers.py
mistral_config_detected = True  # Set unconditionally if config.json exists
```

This meant that loading any local tokenizer would trigger:
```
The tokenizer you are loading from 'path/to/non-mistral-model' with an incorrect regex pattern...
You should set the fix_mistral_regex=True flag when loading this tokenizer to fix this issue.
```

## The Solution

Now, `mistral_config_detected` is only set to `True` when the `model_type` in the config is actually a Mistral variant:

```python
# Only set mistral_config_detected if it's actually a Mistral model
if transformers_model_type in ["mistral", "mistral3", "voxtral", "ministral", "pixtral"]:
    mistral_config_detected = True
```

This ensures the warning is only shown for Mistral-based models that actually need the regex fix.

## Testing

The fix ensures:
- ✅ Loading local non-Mistral tokenizers (e.g., LLaMA, GPT) no longer triggers the warning
- ✅ Loading local Mistral tokenizers still correctly triggers the warning when needed
- ✅ Loading remote tokenizers continues to work as expected

Comments:
[V5] Return a BatchEncoding dict from apply_chat_template by default again
Author: Rocketknight1
Pull request: yes

This is basically PR #41626 again! Some of it got clobbered in the tokenizer refactor, but it's just as good the second time.

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

run-slow: blenderbot, bloom, cohere, gpt2, gpt_sw3

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

cc @LysandreJik - this was one of the V5 PRs before, do I need to do anything special with this one, or can we just merge it to `main`?
more tts pipeline exampel
Author: Deep-unlearning
Pull request: yes

Following this: https://github.com/huggingface/transformers/pull/42473

Here are more example for TTS pipeline

@ebezzam @eustlb 

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

# What does this PR do?

Adapt some test case on npu

Fixes # (issue)


## 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).
- [x] 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 @ydshieh maybe? 

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

run-slow: qwen3
🛠️ Add Failure-Safe Training with Emergency Checkpointing
Author: yaswanth19
Pull request: no
Labels: name: Feature request

### Feature request

Introduce a **failure-safe training mode** in the `Trainer` API (e.g., via a flag like `enable_emergency_checkpoint=True`) that ensures training progress is saved **automatically upon unexpected failure**, such as hardware interruptions, out-of-memory errors, or bugs during training. This allows users to resume from the **last known safe state**, even if a checkpoint hasn't yet been saved via the normal `save_strategy`.


### Motivation

Current training rely on:

- Periodic checkpoints using steps or epoch
- Manual try/except logic for error handling and saving state

However, these methods have limitations:

- Saving too frequently using steps slows down training due to I/O overhead
- Saving only at the end of an epoch (`save_strategy="epoch"`) risks **losing progress if failure occurs mid-epoch**
- Manual error handling is fragile and inconsistent between users

This can lead to **wasted compute time** and inability to resume training effectively.


### Your contribution

N/A

CC: @SunMarc 

Comments:
@SunMarc a gentle ping for this feature request.
extend FA2 and other cases to XPU, 
Author: yao-matrix
Pull request: yes

we expect all model cases except CUDAGraph specific, CUDA compute capability specific and FA3 specific can run XPU. For FA3, we are developing.

@ydshieh, pls help review, thx very much.

Comments:
@yao-matrix don't forget 

https://github.com/huggingface/transformers/pull/42536#discussion_r2580336110

🙏 

> @yao-matrix don't forget
> 
> [#42536 (comment)](https://github.com/huggingface/transformers/pull/42536#discussion_r2580336110)
> 
> 🙏

Yes, done, thx very much for your always support, :).

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

run-slow: gemma2, gemma3, glm4v, glm4v_moe, granitemoehybrid, idefics2, kosmos2_5, longcat_flash, mimi, modernbert, musicgen, musicgen_melody, pixtral, qwen2_5_omni, qwen2_5_vl, qwen2_moe

@ydshieh , pls take a second look, thx very much.
Initialize cache state in RecurrentGemmaRecurrentBlock based on batch…
Author: 3outeille
Pull request: yes

Fix needed to pass CI training test (generation matching test) in https://github.com/huggingface/transformers/pull/42597

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

run-slow: recurrent_gemma

run-slow: recurrent_gemma

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

models: ["models/recurrent_gemma"]
quantizations: []

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

✅ No failing test specific to this PR 🎉 !


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

The `test_load_balancing_loss` test is intermittently flaky for me. This PR sets a manual seed to make it more reproducible, which hopefully solves the issue!

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

run-slow: ernie4_5_moe, jamba, minimax, mixtral, qwen2_moe, qwen3_moe

cc @ydshieh 

run-slow: ernie4_5_moe, jamba, minimax, mixtral, qwen2_moe, qwen3_moe

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

models: ["models/ernie4_5_moe", "models/jamba", "models/minimax", "models/mixtral", "models/qwen2_moe", "models/qwen3_moe"]
quantizations: []

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

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

✅ No failing test specific to this PR 🎉 !


Hi @Rocketknight1 

Could you share the job run pages , or the full error log you have if you are running some tests locally.

This test doesn't seem to require seed (from what this test is actually testing), so I would like to know what is wrong without seed.

(and the daily CI doesn't have this test failing, only once for mixtral)

@ydshieh the test has a model initialized from `config`, so all of the weights are randomly initialized. This is the bit that causes flakiness, and the bit that we need to set a seed for! There's a random failure about ~1% of the time when the initialization we get behaves badly. People have tried to fix it by setting really wide `atol` and `rtol` values, but I think fixing the seed is a much more sensible approach.

From my experience of dealing failing tests, use seed in this scenario is a quick hot fix but not the best approach handling it.
Seems it's 1% as you said, maybe we could wait until I check them next week?
  

Closing since it's superceded by #42509!
[loading] Allow loading to happen without threading
Author: Cyrilvallez
Pull request: yes

# What does this PR do?

As per the title. This should help a lot in our CI, and for ZeroGPU as well!

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

An extra file was added to the repo root in #42168, I think by accident. This PR removes it.

cc @ydshieh in case you know why it's here!

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

# What does this PR do?

This PR fixes an error related to fsdpv1 + bnb . Thanks @winglian for the help ! The issue was that I assumed that all bnb 4bit model were stored in torch.unint8. However for fsdp, we need them in b/float16 

Comments:
@bot /style 

Style bot fixed some files and pushed the changes.

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

@bot /style 

Style bot fixed some files and pushed the changes.
Move max_new_tokens recommendation into GenerationConfig docstring
Author: hawon223
Pull request: yes

# What does this PR do?

This PR moves the recommendation about using `max_new_tokens` over `max_length` directly into the GenerationConfig docstring. 
It clarifies the recommended usage for users when generating sequences.



## 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_42384). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Hi! After updating the branch with the latest main, some tests related to Mistral tokenization started failing.

My PR only changes a docstring and does not modify any tokenizer or chat template behavior.

The failures seem to be caused by recent changes on main (multiple chat templates, different default behavior).
If needed, I can rebase again once main stabilizes.

Hey, no worries, I will merge this for you :)

Thank you! Let me know if anything else is needed from my side.
Tiny Clean up `_deps` in setup.py
Author: Sai-Suraj-27
Pull request: yes

# What does this PR do?

`dataclasses` comes built-in from `python>=3.7`. So, it can be removed from the `_deps` list as well.


**Un-related** but, I observed that this [splitted_tests.txt](https://github.com/huggingface/transformers/blob/main/splitted_tests.txt) was added in the repo's main directory in this [PR](https://github.com/huggingface/transformers/pull/42168) & It has only 1 line. Maybe that's why test's didn't ran?? https://github.com/huggingface/transformers/pull/42168#issuecomment-3596609989 I am not sure, but flagging it just in case it was committed accidentally.


## 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?


## Who can review?
@Rocketknight1 @ArthurZucker @ydshieh 

Comments:
CI seems unstable due to HTTP timeouts right now - give it a little bit, then try rebasing or rerunning tests and ping me to merge once it's green!

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

> CI seems unstable due to HTTP timeouts right now - give it a little bit, then try rebasing or rerunning tests and ping me to merge once it's green!

Thanks for the review @Rocketknight1. CI Look's Green now.
[WIP] Add YuE model
Author: Manalelaidouni
Pull request: yes
Labels: name: New model

name: Audio

# What does this PR do?

This draft PR aims at integrating the `YuE` model to `transformers`, it's a lyrics to song generation model that takes a lyrics prompt and a reference audio tokenized using a finetuned `Xcodec` model, YuE itself uses a two stage generation based on 2 Llama2 models, toped with the `Vocos` vocoder to enhance the produced song.

**Progress** : the `YuEProcessor` and `YuETokenizer` produce identical results as the original YuE implementation and I'm currently working on the replicating modeling part.



Comments:
cc @eustlb @ebezzam
[torchao] safetensors
Author: liangel-02
Pull request: yes

**Summary**
updating safetensors logic to support all tensor subclasses generically 

**Test**
verified integration with vllm 
unit tests pass: `python tests/quantization/torchao_integration/test_torchao.py -k TorchAoSafeSerializationTest`


Comments:
cc @SunMarc @MekkCyber 

@MekkCyber to avoid adding torchao specific logic to the core model loader and unblock landing, i reverted the changes to the regex logic and added all other tensor data names. in the future, maybe we can implement a strategy that generalizes this matching in a better way?

cc @jerryzh168 

@MekkCyber @SunMarc can you help me merge this, thanks!

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

run-slow: torchao_integration