noamaanMulla-03/transformers-issues huggingface dataset:
Chat template: save and load correctly for processors
Author: zucchini-nlp
Pull request: yes

# What does this PR do?

FIxes #33459. The chat template was not being saved after the last PR for adding LLaVa-OneVision, because I fixed a small bug when chat template was being saved in both places: in its own file and in processor config.

In this RP we never serialize chat template in the dict so that it is not saved and when saving we check for `self` attributes. Yer, I am not 100% sure if it is ok to not add the template to the dict. Or we should pop template when serializing to json, in `to_json_string` maybe, WDYT?

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

Would you consider making the same changes for ImageProcessingMixin class as well? Here, to be exact: https://github.com/huggingface/transformers/blob/cd74917ffc3e8f84e4a886052c5ab32b7ac623cc/src/transformers/image_processing_base.py#L205
Qwen-VL models use processors inheriting this class and it doesn't save the chat template into chat_template.json. 

ImageProcessingMixin should not have a chat template, instead they should be serialized together with a processing class. In that case, it's better to ping the model authors so they can correct the config files

> ImageProcessingMixin should not have a chat template, instead they should be serialized together with a processing class. In that case, it's better to ping the model authors so they can correct the config files

Thanks for the clarification, I'll follow with Qwen authors for the fix.
Fix loading logic flaw with regards to unexpected and missing keys
Author: LysandreJik
Pull request: yes

As per tests, currently there were some paths failing when loading a checkpoint with unrelated weights (which are well defined in the "unexpected weights on load"). This makes sure that this flag is respected and to ignore such weights.

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

All right, I think this is quite an important issue so I decided to take over to accelerate it if possible! Because it made me realize the flaw was slightly bigger than the original issue: `unexpected` and `missing` keys were not perfectly handled. It's now the case, and the new tests pass!
cc @ArthurZucker 

(Failing tests are unrelated)

Should also solve https://github.com/huggingface/transformers/issues/40972!
Handle loading non-existent checkpoints or corrupted checkpoints.
Author: zhengchenyu
Pull request: yes

# What does this PR do?

* 1 Handle loading non-existent checkpoints

Setting resume_from_checkpoint to true at the start of training will result in an error because the latest checkpoint cannot be found. Therefore, we should only set to false or null at the beginning. If you then interrupt training and want to resume from the latest checkpoint, we need to set resume_from_checkpoint to true. This adjustment is unnecessary. If the latest checkpoint cannot be found at the start of training, simply print the message; there is no need to raise an exception.

* 2 Handle loading  corrupted checkpoints

I've noticed that an exception during the checkpoint process can interrupt the checkpoint, resulting in corrupted files. This can cause errors when loading the checkpoint. This PR add "latest" tag to the checkpoint to ensure the checkpoint is complete.

## 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#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.


Comments:
cc @sunmarc
Guard torchvision imports to prevent crashes in text-only pipelines
Author: paytonison
Pull request: yes

### Problem
Users running text-only pipelines (like pipeline("text-generation")) currently crash if torchvision is installed but not version-matched with torch. The error looks like:

```
RuntimeError: operator torchvision::nms does not exist
...
ModuleNotFoundError: Could not import module 'pipeline'
```

This happens because image_utils.py unconditionally imports torchvision transforms at import time, even if the user never touches an image pipeline.

Solution
* Guard torchvision imports in image_utils.py with try/except.
* If torchvision fails to import, log a warning and fall back to no-op mappings.
* Vision-specific pipelines will still raise later if torchvision is truly required, but text-only workflows are unaffected.

Impact
* Fixes a common pain point for text-only users who don’t care about image pipelines.
* No behavior change for healthy torch/torchvision stacks.
* Provides a clearer warning instead of a hard crash.

How to test
* Uninstall torchvision: pip uninstall torchvision → text-only pipeline still works.
* Install mismatched torchvision (simulate bad build) → text-only pipeline still works with warning.
* Run vision pipeline with working torchvision → behaves as before.

Notes
This change is deliberately minimal and does not alter API. It only makes import-time more robust.

Resolves #41146.

---

## Before submitting
- [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.
- [ ] 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.

Models:
@ArthurZucker

Library:
@Rocketknight1 


Comments:
Support setting total_train_batch_size.
Author: zhengchenyu
Pull request: yes

# What does this PR do?

Set a fixed total_batch_size by adjusting gradient_accumulation_steps. This is extremely useful in elastic training.

## 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#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.


Comments:
cc @sunmarc @mekkcyber
Confusion about Qwen3-Next’s linear attention
Author: fanglinpu
Pull request: no

<img width="1796" height="1470" alt="Image" src="https://github.com/user-attachments/assets/ca6d3fa3-793d-40c0-8f90-0953d40893c2" />
It seems “sequence_length” and “num_heads” are reversed here.

Comments:
cc @Cyrilvallez 

See https://github.com/huggingface/transformers/pull/41036, there was a mistake in the order of variable names - the logic was correct, the namings not. The linked PR fixes this but lmk if not

Closing this as explained above, should be fixed on main. But ping me if there is a(nother) issue there
Real time sentiment analysis dashboard
Author: 3015pavan
Pull request: no
Labels: name: Feature request

### Feature request

򫹰򬐠 
The Real-Time Sentiment Dashboard is an enhancement that streams live social media content (e.g., Twitter/X, 
Reddit) and classifies sentiment using Hugging Face’s pre-trained models. It visualizes public sentiment trends 
across topics, regions, and time.

### Motivation

While Hugging Face Transformers offer powerful sentiment analysis models, they are typically used in static or batch-processing contexts. In today’s fast-paced digital world, there’s a growing need to analyze public sentiment as it unfolds, especially across platforms like Twitter/X, Reddit, and news feeds.

This enhancement bridges that gap by introducing a real-time dashboard that streams live content, classifies sentiment instantly, and visualizes trends interactively. It empowers developers, journalists, and researchers to monitor public opinion dynamically — whether for elections, product launches, or social movemen

### Your contribution

This contribution includes:

- A streaming pipeline using snscrape or tweepy  
- Sentiment classification using Hugging Face’s pipeline("sentiment-analysis")  
- A dashboard UI built with Streamlit or Dash  
- Optional geo-mapping and multilingual support  
- Full documentation, testing, and demo app

This enhancement demonstrates how Hugging Face models can be used in live, real-world applications, making NLP more accessible and impactful.

Comments:
That sounds quite interesting tbh. Have you created this feature already because I would like to contribute to it..

Cool idea but this is definitely a separate product, not something that should be in `transformers` itself!
Suggestion: Support HMP protocol for multi-agent LLM workflows
Author: kagvi13
Pull request: no
Labels: name: Feature request

### Feature request

Enable **decentralized agent-to-agent communication** for Transformers models, allowing multiple agents to share knowledge, maintain cognitive diaries, and coordinate actions via [HyperCortex Mesh Protocol (HMP)](https://github.com/kagvi13/HMP).

### Motivation

Currently, Transformers pipelines operate mainly as individual agents. Adding HMP support would allow models to:

* Form **processed synthetic knowledge** instead of only raw outputs.
* Share reasoning, experience, and memory traces between agents.
* Participate in distributed cognitive workflows, enhancing collaboration and learning.

### Your contribution

We have developed an experimental protocol and reference implementation:

* [HMP-0004-v4.1.md](https://github.com/kagvi13/HMP/blob/main/docs/HMP-0004-v4.1.md) — protocol specification
* [HMP-Ethics.md](https://github.com/kagvi13/HMP/blob/main/docs/HMP-Ethics.md) — ethics and validation
* [dht\_protocol.md](https://github.com/kagvi13/HMP/blob/main/docs/dht_protocol.md) — P2P discovery
* [HMP-agent-REPL-cycle.md](https://github.com/kagvi13/HMP/blob/main/docs/HMP-agent-REPL-cycle.md) — example agent cycle

We’re happy to provide guidance or examples for integrating HMP into Transformers pipelines if there’s interest.

Comments:
We prefer not to implement new protocols and specs and architectures until there's significant traction! Otherwise our codebase tends to get littered with discarded code that never really got acceptance.
Fix single quotes in markdown
Author: cyyever
Pull request: yes

# What does this PR do?



## 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: @eustlb
- graph models: @clefourrier

Library:

- flax: @gante and @Rocketknight1
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Rocketknight1
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @zach-huggingface, @SunMarc and @qgallouedec
- chat templates: @Rocketknight1

Integrations:

- deepspeed: HF Trainer/Accelerate: @SunMarc @zach-huggingface
- 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: @Rocketknight1
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_41154). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
extend gemma3n integration ut cases on XPU
Author: yao-matrix
Pull request: yes

@ydshieh , pls help review, thx very much.

Comments:
@SunMarc @ydshieh , pls help review, thx very much

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

run-slow: gemma3n

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

# What does this PR do?

 The argument is ignore.

Comments:
Hmm, I'm not sure about this one! If you read the source for `is_torch_xla_available`, `check_is_gpu` overrides `check_is_tpu`, so there's no point setting both to `True`

@Rocketknight1 Ok, let's just set `check_is_gpu`

I'm still uncertain, though - I don't know much about `neuroncore`, so I don't know if those devices type-check as GPUs or TPUs or what. That makes me a bit nervous about modifying this function!

@Rocketknight1 Delay it?
Force new vision models addition to include a fast image processor
Author: yonigozlan
Pull request: yes

# What does this PR do?

As the title says, this adds a test that will fail for models added after September 1st 2025, if they include a slow image processor but not a fast one.
Cc @qubvel as we discussed this

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

@qubvel I put it as an image processor test so that contributors know early on that they have to implement a fast image processor (while they are working on the slow image processor). I'm not sure how much contributors pay attention to the repo consistency check, and if they do it's probably at the very end when everything else is done.
That said I don't feel very strongly about this so I can move the test if you don't agree :)  

@ArthurZucker, it would be great to have it out of the box before merging now that fast image processors are becoming more standard. Fixing it after merging means breaking some backward compatibility, plus fast image processors should be easier to implement than slow ones
docs: update speech recognition examples to use modern Common Voice d…
Author: tanuj-rai
Pull request: yes


# What does this PR do?
This PR updates the existing `"common_voice" \` dataset with modern `"mozilla-foundation/common_voice_11_0" \`.

Fixes #40977

## 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.
- [ ] 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 

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @


Models:

- text models: @ArthurZucker
- vision models: @amyeroberts, @qubvel
- speech models: @eustlb
- graph models: @clefourrier

Library:

- flax: @gante and @Rocketknight1
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Rocketknight1
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @zach-huggingface, @SunMarc and @qgallouedec
- chat templates: @Rocketknight1

Integrations:

- deepspeed: HF Trainer/Accelerate: @SunMarc @zach-huggingface
- 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: @Rocketknight1
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


Comments:
Seems good! Did you try running it and see if you got the `backward()` issues described in #40977?

looks like #41027 supersedes this one, so I'll review it and might close this one.
Improve `add_dates` script
Author: yonigozlan
Pull request: yes

# What does this PR do?

Improve the script to automatically add dates in the model doc files.
One big issue was that the script was checking for the first commit merged into main to get the transformers release dates, but that can't work for new models. So now if the model is not on main (new model), we use today's date.
Also when check-all is not used, we now check which files have been changed against upstream main instead of checking against the local branch.
Also fixes Qwen3OmniMoe doc.

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_41167). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Fix flash-attn for paged_attention when no kernels
Author: remi-or
Pull request: yes

Currently there is an issue when using `paged_attention` without the `kernels` package and with `flash_attn` installed: the `flash_attn_varlen_func` is no longer referenced when reaching its call. For some reason, by assigning it to a value, this can be avoided. The issue was observed on A100 and Mi325.
In the case the `flash_attn_varlen_func` function is not imported but still ends up being used, we also add a dummy function to raise a comprehensive error message.

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_41078). 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.
Enable fa in amd docker
Author: remi-or
Pull request: yes

This PR adds `flash-attention` to the AMD docker, and fixes some `gemma3n` tests that started failing because of this. Some new test fail, but they are not AMD-exclusive failures, so out of scope for this PR. Also adds caching of url data that repeatedly fails to be downloaded on AMD CI (on `qwen2_5_vl`) and fixes a nit in the important models list. 
I will run a manual CI run on my instance tonight to check the CI is fine, so please do not merge, but until then I appreciate the review.

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_41069). 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.

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

run-slow: gemma3n, qwen2_5_vl
Add a line to make telemetry in examples more explicit
Author: LysandreJik
Pull request: yes


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

overtaken by https://github.com/huggingface/transformers/pull/41120 :)
Remove data from examples
Author: LysandreJik
Pull request: yes

Removes the examples telemetry as unused

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

We definitely should, yes

merging this now, checking notebooks

notebooks: https://github.com/huggingface/notebooks/pull/609