noamaanMulla-03/transformers-issues huggingface dataset:
Widen match condition for `_can_record_outputs`
Author: molbap
Pull request: yes

In case of module reloading, we currently lose tracking hooks for hidden states and attentions . Widening the matching condition a bit.

Should fix https://github.com/huggingface/transformers/issues/43761, also mentioned in https://github.com/linkedin/Liger-Kernel/pull/1061 

Reproducer for CLIP:

```python
import importlib, torch
from transformers import CLIPVisionConfig, CLIPVisionModel
import transformers.models.clip.modeling_clip as modeling_clip

config = CLIPVisionConfig(hidden_size=32, intermediate_size=64, num_hidden_layers=2, num_attention_heads=4, image_size=30, patch_size=10)
pixel_values = torch.randn(1, 3, 30, 30)

m1 = CLIPVisionModel(config)
o1 = m1(pixel_values=pixel_values, output_hidden_states=True)
print("before reload:", o1.hidden_states is None)

importlib.reload(modeling_clip)

m2 = CLIPVisionModel(config)
o2 = m2(pixel_values=pixel_values, output_hidden_states=True)
print("after reload:", o2.hidden_states is None)
```

Second reload will currently fail, and this is a fix proposal.

Added a test as well (specific to CLIP, likely enough)

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

I want to think that great minds think alike :eyes: @Cyrilvallez 's PR solves more problems with `check_model_inputs` https://github.com/huggingface/transformers/pull/43765
Enforce manual seed to reduce flakiness
Author: tarekziade
Pull request: yes

This patch aims to reduce flakiness in CI tests. We identified two causes of nondeterministic behavior:

- Some tests were not using a fixed RNG seed, which reduced determinism.
- The cli tests were occasionally triggering I/O errors due to writes on a closed stdout.

This branch was run multiple times and appears to reduce flakiness in all previously unseeded tests. While there’s no deterministic way to prove the improvement, using fixed seeds is still a best practice.

As a follow-up, we could centralize the seed initialization in a shared test fixture, avoiding the need to set it explicitly in individual tests.






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

run-slow: doge, donut, esm, fastspeech2_conformer, mimi, minimax_m2, mistral, mixtral, musicgen, musicgen_melody, nllb_moe, qwen2, qwen2_moe, qwen3, qwen3_moe, recurrent_gemma

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

models: ["models/doge", "models/donut", "models/esm", "models/fastspeech2_conformer", "models/mimi", "models/minimax_m2", "models/mistral", "models/mixtral", "models/musicgen", "models/musicgen_melody", "models/nllb_moe", "models/qwen2", "models/qwen2_moe", "models/qwen3", "models/qwen3_moe", "models/recurrent_gemma"]
quantizations: []

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

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [ea868138](https://github.com/huggingface/transformers/commit/ea868138dfc8908d71fe23adc852a33569ba5ce1) | merge commit |
| PR | [69eafe69](https://github.com/huggingface/transformers/commit/69eafe69c6271aa2be67a45cfc14ef9c78535771) | branch commit |
| main | [b9042c4e](https://github.com/huggingface/transformers/commit/b9042c4e9a00376412e4b2187161a8af52baa133) | base commit |

✅ No failing test specific to this PR 🎉 👏 !


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

run-slow: doge, donut, esm, fastspeech2_conformer, mimi, minimax_m2, mistral, mixtral, musicgen, musicgen_melody, nllb_moe, qwen2, qwen2_moe, qwen3, qwen3_moe, recurrent_gemma
Add TRL CI bot workflow to trigger tests on PR comments
Author: qgallouedec
Pull request: yes

Trainer is going to be heavily refactored over the coming weeks/months (see #43595). To avoid the recurring pattern:

PR merges in `transformers` → TRL CI breaks → follow-up PR in `transformers` to fix something we could have caught earlier
(e.g. #43711 → #43780),

I propose adding a small "slash-command" bot that lets us run TRL’s CI against the exact commit/branch from a `transformers` PR, so we can detect downstream breakages before merging.

To use it, just comment on the PR:

> `/trl-ci`





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

The generate tests that compare prompt lookup or speculative decoding to the base model have an extremely high rate of flakiness, I guess because of inherent non-determinism. The actual generation works, but the test frequently sees divergence from this non-determinism at some point and throws an error.

It'd be cool to make a more reliable version of these tests at some point, but for now I'm just marking them as flaky to clean up the CI!

Example failing job here: https://app.circleci.com/jobs/github/huggingface/transformers/2143338

Comments:
cc @ydshieh 

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

Another flaky one: https://app.circleci.com/pipelines/github/huggingface/transformers/162727/workflows/39b55545-b8ef-4b4a-8bfe-1491009d9bea/jobs/2143532

My 5 cents on the issue:

This one is flaky for multimodal LLMs which I believe is because of special `multimodal` tokens. For most VLMs we fixed it by this line which adds `force_no_generate_tokens`. So I believe Kosmos2/GraniteSpeech have different namings for those special tokens and we're back to flakiness

```
# The added line
logits_processor_kwargs = self._get_logits_processor_kwargs(config=model.config)
```

Hmn, interesting! Is there a way we can fix just those models?

Not sure, we'll need a list of still-flaky models and examine what is happening when we 'merge_image_text_features'. I think we can mark them flaky for individual model for now, if we don't want to waste time investigating



Closing for now because I think this is covered by https://github.com/huggingface/transformers/pull/43794 - we'll revisit it if the errors keep happening
[docs] reveal more in toctree
Author: stevhliu
Pull request: yes

expands the base classes, inference, and training sections as these are quite important and will give readers a better idea of what's available

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_43808). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Add ViT NEPA
Author: sbucaille
Pull request: no
Labels: name: New model

### Model description

Summary : Next-Embedding Prediction: The Simple Secret to Strong Vision Learners

NEPA is a self-supervised method. It trains Vision Transformers to predict future patch embeddings. No complex loss functions or extra heads. Achieves 85.3% top-1 accuracy on ImageNet-1K with ViT-L.

The NEPA model got released two days ago and while the results are promising, I couldn't not notice how close to transformers the code they released was, and as @NielsRogge mentioned in his [tweet](https://x.com/NielsRogge/status/2002415390060663189), they heavily relied on the HF libraries.
So I suggest we could add this model to transformers and showcase how easy it becomes easy for researchers to pick and build on top of existing models. Anyway, I got a first draft PR to be opened.

### Open source status

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

### Provide useful links for the implementation

Every useful links are in the HF paper page : https://huggingface.co/papers/2512.16922

@yonigozlan @SihanXU 

Comments:
Hi there! I noticed there's an active PR for NEPA in `transformers`, but it looks like the process is still ongoing. Our team is currently working on NEPA follow-ups and benchmarking; having this integrated into the main library would significantly accelerate our reproduction efforts. Could you speed up the merge process?
docs: remove deprecated pipeline examples from summarization and tran…
Author: nulone
Pull request: yes

Fixes #43827

## What does this PR do?

Removes deprecated `pipeline()` examples from summarization.md and translation.md that reference pre-v5 API.

The manual `model.generate()` approach is preserved.

## Before submitting

- [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).

Comments:
Closing — just noticed #43831 was submitted earlier for the same fix. Thanks!
Dummy `nn.Conv2d` in `Sam3PixelDecoder`
Author: james77777778
Pull request: no
Labels: name: bug

### System Info

transformers==5.0.0rc1

### Who can help?

I’ve noticed that `Sam3Model.from_pretrained("facebook/sam3")` sets `num_upsampling_stages=3`. However, `backbone_features` passed to `Sam3PixelDecoder` is a tuple of size 3. As a result, `self.conv_layers[2]` and `self.norms[2]` are bypassed and do nothing.

Is this the expected behavior?

Please let me know if you confirm this as a bug that needs to be fixed. I'm willing to work on a PR.

Code:

https://github.com/huggingface/transformers/blob/a7f29523361b2cc12e51c1f5133d95f122f6f45c/src/transformers/models/sam3/modeling_sam3.py#L1943-L1949

https://github.com/huggingface/transformers/blob/a7f29523361b2cc12e51c1f5133d95f122f6f45c/src/transformers/models/sam3/modeling_sam3.py#L1953-L1977

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

```python
import requests
import torch
from PIL import Image, ImageDraw
from transformers.models.sam3 import Sam3Model
from transformers import Sam3Processor

device = "cuda" if torch.cuda.is_available() else "cpu"

model = Sam3Model.from_pretrained("facebook/sam3").to(device)
processor = Sam3Processor.from_pretrained("facebook/sam3")

# Load image
image_url = "http://images.cocodataset.org/val2017/000000077595.jpg"
image = Image.open(requests.get(image_url, stream=True).raw).convert("RGB")

# Segment using text prompt
inputs = processor(images=image, text="ear", return_tensors="pt").to(device)

with torch.no_grad():
    outputs = model(**inputs)
```

### Expected behavior

`self.conv_layers[2]` should be touched.

Comments:
cc @yonigozlan 

Hey @james77777778 ! Nice catch, you're absolutely right, these weights are not used, as is the case in the original facebook implementation. Unfortunately it would be difficult to remove them now as we would need to change the checkpoints on the hub. As these weights don't add a relatively significant number of parameters, I think we can leave it like this for now

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.
Continuous batching: output queue requeue starvation and request-scoped iterator does not terminate on completion
Author: pythongiant
Pull request: no



### **Description**

There are two related correctness issues in the continuous batching result consumption logic that can lead to unfairness and non-terminating iterators under concurrent workloads.

#### 1. Starvation and incorrect timeout handling in `get_result`

`ContinuousBatchingManager.get_result` currently retrieves a single item from the shared output queue and immediately re-queues it if the `request_id` does not match, returning `None` afterward. Under concurrent requests, this can lead to:

* Starvation when mismatched outputs are repeatedly re-queued
* Timeout semantics that are not respected, since re-queueing returns early instead of continuing to search within the remaining timeout
* Unfair consumption behavior that depends on queue ordering rather than request progress

This behavior is observable when multiple streaming requests are active and results are interleaved in the output queue.

#### 2. `request_id_iter` does not terminate after normal completion

`request_id_iter` currently exits only when a request is cancelled or the generation thread terminates. For requests that complete normally, the iterator continues polling indefinitely after the final `FINISHED` output has been yielded.

This can result in:

* Infinite iteration loops for request-scoped consumers
* Unexpected blocking behavior in streaming-style usage
* Reliance on caller-side logic to manually stop iteration

The iterator should terminate once a terminal `FINISHED` output is observed for the given request.

---

### **Expected behavior**

* `get_result` should fairly search for a matching result within the specified timeout without starvation or early return.
* `request_id_iter` should stop iterating once the request reaches a terminal finished state, in addition to cancellation or thread termination.

---

### **Proposed fix** 

A minimal, backward-compatible fix (#42942) can:

* Defer re-queuing mismatched outputs until a matching result is found or the timeout expires
* Explicitly terminate `request_id_iter` when a `GenerationOutput` reports a finished state

This preserves existing APIs, streaming semantics, and benchmarking behavior while fixing the correctness issues.

---

### **Environment**

* Transformers version: main
* Feature: continuous batching
* Device: CPU / CUDA (independent of backend)

---

### **Additional context**

These issues are easiest to reproduce with multiple concurrent streaming requests sharing a single `ContinuousBatchingManager`.


Comments:
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.
model_inputs should have the same dtype
Author: KoichiYasuoka
Pull request: yes

# What does this PR do?

Bug fix for ImageTextToTextPipeline on bfloat16 models.

## 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?

- multimodal models: @zucchini-nlp




Comments:
cc @ydshieh can I ask for this one to be force-merged while the CI is red? :sweat_smile: 

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

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=43387&sha=12c10f

Thank you for force-pushed in [v5.1.0](https://github.com/huggingface/transformers/blob/v5.1.0/src/transformers/pipelines/image_text_to_text.py#L337) with #43731.
fix(cli): Fix TypeAdapter NameError when pydantic is not installed
Author: Mr-Neutr0n
Pull request: yes

## What does this PR do?

Fixes a `NameError: name 'TypeAdapter' is not defined` error when importing transformers without pydantic installed.

## Problem

The `TypeAdapter` class from pydantic was used as a type annotation in `_validate_request()` at line 588:

```python
def _validate_request(
    self,
    request: dict,
    schema: TypedDict,
    validator: TypeAdapter,  # <-- NameError here
    unused_fields: set,
):
```

However, `TypeAdapter` is only imported inside an `if serve_dependencies_available:` block, which requires pydantic to be installed. When pydantic is not installed, Python raises `NameError` when parsing the class definition.

## Solution

1. Added `TypeAdapter` to the `TYPE_CHECKING` imports block
2. Changed the type annotation to use a string literal `"TypeAdapter"` for forward reference

This ensures the type annotation is only evaluated during static type checking, not at runtime.

Fixes #43824

Comments:
This 3-line patch fixes a NameError when `transformers` is imported without pydantic installed. All 14 CI checks are green and there is already an approving review. Could a maintainer take a look at merging this?
openai/whisper-large-v2 can't run
Author: LIANGQI0811
Pull request: no
Labels: name: bug

### System Info

```python
tt = pipeline(model="openai/whisper-large-v2")
tt("https://hf-mirror.com/datasets/Narsil/asr_dummy/resolve/main/mlk.flac")
```

print error message like this:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/developer/.local/lib/python3.10/site-packages/transformers/pipelines/automatic_speech_recognition.py", line 266, in __call__
    return super().__call__(inputs, **kwargs)
  File "/home/developer/.local/lib/python3.10/site-packages/transformers/pipelines/base.py", line 1266, in __call__
    return next(
  File "/home/developer/.local/lib/python3.10/site-packages/transformers/pipelines/pt_utils.py", line 126, in __next__
    item = next(self.iterator)
  File "/home/developer/.local/lib/python3.10/site-packages/transformers/pipelines/pt_utils.py", line 271, in __next__
    processed = self.infer(next(self.iterator), **self.params)
  File "/home/developer/.local/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 741, in __next__
    data = self._next_data()
  File "/home/developer/.local/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 801, in _next_data
    data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
  File "/home/developer/.local/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 35, in fetch
    data.append(next(self.dataset_iter))
  File "/home/developer/.local/lib/python3.10/site-packages/transformers/pipelines/pt_utils.py", line 188, in __next__
    processed = next(self.subiterator)
  File "/home/developer/.local/lib/python3.10/site-packages/transformers/pipelines/automatic_speech_recognition.py", line 486, in preprocess
    extra["num_frames"] = processed.pop("num_frames")
  File "/usr/lib/python3.10/_collections_abc.py", line 962, in pop
    value = self[key]
  File "/home/developer/.local/lib/python3.10/site-packages/transformers/feature_extraction_utils.py", line 90, in __getitem__
    return self.data[item]
KeyError: 'num_frames'

### Who can help?

_No response_

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


tt = pipeline(model="openai/whisper-large-v2")
tt("https://hf-mirror.com/datasets/Narsil/asr_dummy/resolve/main/mlk.flac")

### Expected behavior

will run and result data

Comments:
`KeyError: 'num_frames'` an issue that occurred in older versions. The pipeline expects the feature extractor to return a `num_frames ` key, but it is not being generated or passed correctly in your version. `pip install --upgrade transformers accelerator librosa` should fix it.

it't looks work now
Fix slack-report workflow file
Author: ydshieh
Pull request: yes

# What does this PR do?



Comments:
run-slow: vit

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

models: ["models/vit"]
quantizations: []

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

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [0a089e10](https://github.com/huggingface/transformers/commit/0a089e10ab0807e0bb39f28ab153b698861450b7) | merge commit |
| PR | [045d8e53](https://github.com/huggingface/transformers/commit/045d8e53338b0716ae8245d3dfed26ee6fe4f7c6) | branch commit |
| main | [7769f660](https://github.com/huggingface/transformers/commit/7769f660935b5d48b73bf6711d0a78b6f8f98739) | base commit |

✅ No failing test specific to this PR 🎉 👏 !


The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_43851). 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: vit
Add DEIMv2 model, image processor, and basic tests
Author: Vinayaktoor
Pull request: yes

# What does this PR do?

This PR introduces the DEIMv2 model along with its configuration, image processor, and unit tests. The changes include:

Model Implementation: Added Deimv2ForObjectDetection supporting object detection tasks.

Configuration: Added Deimv2Config for model hyperparameters.

Image Processing: Added Deimv2ImageProcessor to handle preprocessing and postprocessing of images.

Unit Tests: Added tests for configuration, image processing, and model forward pass (tests/models/deimv2/).

This PR builds upon and makes changes to PR by @kekwlboy12469, PR #41291.
Fixes #41211
Fixes missing or incomplete DEIMv2 model integration.

Fixes absence of unit tests for DEIMv2 model and image processor.

Fixes compatibility issues with Transformers pipelines for object detection.


## 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?
- [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).
- [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.





Comments:
cc @nielsrogge @yonigozlan

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

run-slow: deimv2

Hi, 

Is there still a will to merge this PR at some point ? 

I think the implementation is unfinished yet; DEIMV2_PRESETS defines dinov2 as backbone instead of dinov3 and the published model.safetensors doesn't align with the proposed model anyway. 

Best 

gentle ping @molbap @nielsrogge @mcpatate if anyone wants to take it!