noamaanMulla-03/transformers-issues huggingface dataset:
Apply full_text_row_masked_out_mask before cross-attn residual in Mllama
Author: KirtiRamchandani
Pull request: yes
Labels: name: Code agent slop

## Problem

In `MllamaCrossAttentionDecoderLayer`, `full_text_row_masked_out_mask` was applied after the MLP, while the cross-attention output had already been merged into the residual. Text rows that should be fully blocked from image tokens could still receive cross-attention signal.

## Root cause

The mask was applied too late in the block. The reference Llama multimodal implementation zeroes cross-attention output immediately after attention, before the output projection/residual path.

## Fix

Move the mask multiplication to immediately after `cross_attn`, before the gated residual add. Remove the post-MLP masking.

## Testing

Added `MllamaCrossAttentionMaskTests.test_full_text_row_mask_zeroes_cross_attention_before_residual`, which mocks cross-attention to a constant output and asserts fully masked rows stay zero while unmasked rows receive the contribution.

Fixes #39379

Comments:
**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46627)

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

run-slow: mllama
Reject path traversal in sharded checkpoint index files
Author: KirtiRamchandani
Pull request: yes
Labels: name: Code agent slop

## Problem

Loading a model from a local directory with a crafted `model.safetensors.index.json` lets `weight_map` values escape the model folder via `../` or absolute paths. `get_checkpoint_shard_files` joined those strings directly, so `from_pretrained("/tmp/malicious_model")` could attempt to read arbitrary files the process can access.

## Root cause

Shard filenames from the index JSON were never validated before `os.path.join`. The same pattern existed in Trainer resume loading and Accelerate disk offload re-join logic.

## Fix

- Validate shard filenames reject `..`, absolute paths, and resolved paths outside the model directory (lexical `abspath` + `commonpath`, matching the existing Bark preset guard).
- Apply the same validation in `load_sharded_checkpoint` and when rebuilding offload weight maps.

## Testing

Added `tests/utils/test_checkpoint_shard_path_traversal.py` covering traversal rejection, absolute paths, and valid nested shard paths.

Fixes #46097

Comments:
**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46626)
fix(wav2vec2_phoneme): restore phonemizer language after switching back
Author: KirtiRamchandani
Pull request: yes

Fixes #46614

Comments:
**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46638)

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

run-slow: wav2vec2_phoneme
Add flash attention 2.0 support for GPT2LMHeadModel
Author: brresnic
Pull request: no
Labels: name: Good Second Issue

name: Feature request

```
    model = AutoModelForCausalLM.from_pretrained(
        my_GPT2LMHeadModel_checkpoint, 
        torch_dtype=torch.bfloat16, 
        attn_implementation="flash_attention_2",
    )
```
throws the following error:
```
Error loading Flash_Model_2: GPT2LMHeadModel does not support Flash Attention 2.0 yet. Please open an issue on GitHub to request support for this architecture: https://github.com/huggingface/transformers/issues/new
```

Comments:
I think there is a draft PR here #26502 ans #27479, maybe working on sdpa might be better

can you please share the detailed problem statement ? I would like to work on this
ci: add merge_group trigger to pr-ci-caller.yml
Author: ydshieh
Pull request: yes

## What does this PR do?

Adds `merge_group:` as a trigger to `pr-ci-caller.yml` so that the PR CI workflow runs when a PR is added to the merge queue.

Without this, the required status checks never fire for merge queue events, causing GitHub to eject the PR with "no response for status checks".

The companion changes to handle the `merge_group` event correctly inside the called workflows (PR number extraction, `RUN_FLAKY` fix) are in huggingface/transformers-test-ci#51.

- [x] I confirm that this is not a pure code agent PR.

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

# What does this PR do?

If users forget to add a token in tester class, that means we are never testing if placeholder tokens for that modality work correctly. This PR adds default values for special tokens in the Mixin and fixes prev skipped tests because they had no special token defined

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_46374). 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: blip_2, deepseek_vl, deepseek_vl_hybrid, florence2, instructblip, instructblipvideo, janus, ovis2, qwen2_5_omni
feat: Add HRM Model
Author: zbloss
Pull request: yes

# What does this PR do?

Adds the new Hierarchical Reasoning Model.

Fixes #41271

## 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.
- [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.

@ArthurZucker @Cyrilvallez hoping you can take a look. The model is currently implemented as a text model though further research hints it may be helpful for understanding images as well.


Comments:
Nice! cc @molbap for an initial review!


@molbap I believe I fixed everything, let me know when you get a chance to take another look.

I converted the author's original weights and uploaded them here after verifying that they work: 
* https://huggingface.co/zbloss/HRM-maze-30x30-hard
* https://huggingface.co/zbloss/HRM-sudoku-extreme

Reviewing now!

Hey @zbloss, reviewing now! 

Let me know when you want eyes on this @zbloss , looking forward to see this (and TRM) merged :rocket: 

Thanks for the update, reviewing soon!

Just saw the release notes for v5.0.0rc0

Are there any changes I'm going to need to make in this PR to prepare for v5.0.0, or are we aiming to get this merged before the big v5.0.0 release?

No should be alright! Just let me review! 🤗 

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

run-slow: auto, hrm

We can close this, HRM has been merged in #46025
ci: add NO_COLOR=1 to suppress ANSI color codes in CI output
Author: ydshieh
Pull request: yes

## What does this PR do?

Sets `NO_COLOR=1` in the `model_jobs.yml` workflow environment to suppress ANSI color escape codes in test output, making logs cleaner and easier to parse.

- [x] I confirm that this is not a pure code agent PR.

Without this PR, the raw logs looks

```bash
2026-06-12T13:17:47.9759715Z [33mWARNING [0m transformers.core_model_loading:core_model_loading.py:1484 Offloading parameter to disk — target_name='model.norm.weight', param_device='disk', in_model_buffers=False, offload_buffers=False, param shape=(4096,), dtype=torch.bfloat16, device=cpu, numel=4096, disk_offload_folder='/tmp/tmp02u8krsi', mapping=WeightRenaming(source_patterns=['model.norm.weight'], target_patterns=['model.norm.weight'])
2026-06-12T13:17:48.3755050Z [33mWARNING [0m accelerate.big_modeling:big_modeling.py:448 Some parameters are on the meta device because they were offloaded to the cpu and disk.
2026-06-12T13:18:01.1559419Z [32mPASSED[0m[33m                                                                   [ 33%][0mtests/models/phimoe/test_modeling_phimoe.py::PhimoeIntegrationTest::test_model_phimoe_instruct_logits [PASSED] 229.05s
2026-06-12T13:18:01.1561332Z 
2026-06-12T13:18:01.4551981Z tests/models/phimoe/test_modeling_phimoe.py::PhimoeIntegrationTest::test_phimoe_instruct_generation 
2026-06-12T13:18:01.4553024Z [1m-------------------------------- live log call ---------------------------------[0m
2026-06-12T13:18:01.4554680Z [33mWARNING [0m transformers.modeling_rope_utils:modeling_rope_utils.py:1028 Unrecognized keys in `rope_parameters` for 'rope_type'='longrope': {'short_mscale', 'long_mscale'}
2026-06-12T13:20:51.3094758Z [32mPASSED[0m[33m                                                                   [ 66%][0mtests/models/phimoe/test_modeling_phimoe.py::PhimoeIntegrationTest::test_phimoe_instruct_generation [PASSED] 170.15s
2026-06-12T13:20:51.3099246Z 
2026-06-12T13:20:51.5951284Z tests/models/phimoe/test_modeling_phimoe.py::PhimoeIntegrationTest::test_phimoe_instruct_with_static_cache 
2026-06-12T13:20:51.5952175Z [1m-------------------------------- live log call ---------------------------------[0m
2026-06-12T13:20:51.5953317Z [33mWARNING [0m transformers.modeling_rope_utils:modeling_rope_utils.py:1028 Unrecognized keys in `rope_parameters` for 'rope_type'='longrope': {'short_mscale', 'long_mscale'}
2026-06-12T13:24:43.8435241Z [32mPASSED[0m[33m    
```


Comments:
**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46659)

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

# Summary

This PR leverages an **awesome** kwarg in transformers: `logits_to_keep`. Simply, this drop the tokens for which we won't use the next token predictions before we enter the `lm_head`. Reduces the memory footprints of large prefill batches, increase their throughput, makes everyone happy.

## Performance ✅ 

label | main acc | new PR acc | main (tok/s) | new PR (tok/s) | diff
-- | -- | -- | -- | -- | --
gsm8k_default | 0.822 | 0.822 | 2460.91 | 2477.15 | +0.66%
gsm8k_sampling | 0.787 | 0.784 | 1952.33 | 1958.65 | +0.32%
gsm8k_compile | 0.821 | 0.821 | 2461.93 | 2473.02 | +0.45%
gsm8k_no_fast_decode | 0.822 | 0.822 | 2350.41 | 2355.21 | +0.20%
gsm8k_bare_bones | 0.821 | 0.821 | 1845.35 | 1845.52 | +0.01%
ifeval_default | 0.445 | 0.447 | 9007.60 | 9015.87 | +0.09%
few_blocks | - | - | 666.92 | 664.97 | -0.29%
multi_return_seq | - | - | 1610.03 | 1627.67 | +1.10%
rollouts_1024 | - | - | 3546.62 | 3550.29 | +0.10%
rollouts_2048 | - | - | 3371.13 | 3373.68 | +0.08%
rollouts_4096 | - | - | 2973.00 | 2974.99 | +0.07%
rollouts_8192 | - | - | 2361.10 | 2362.95 | +0.08%
rollouts_16384 | - | - | 1549.11 | 1549.40 | +0.02%

No performance degradation.

## Tests ✅ 

All tests pass

## AI Reviewed ✅ 

Done and addressed

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

**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46660)
fix(t5): use "decoder's " prefix in error messages when called on decoder stack
Author: adhavan18
Pull request: yes
Labels: name: Code agent slop

Fixes #46463.

**Problem**

When `T5Stack` (or any T5-variant stack) is used as a standalone decoder and called with `input_ids`, the error message reads:

```
You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time
```

The `decoder_` prefix is concatenated directly onto `input_ids`, producing `decoder_input_ids` instead of `decoder's input_ids`. This is confusing because `decoder_input_ids` looks like a valid parameter name and misleads users into thinking they passed a wrong keyword argument.

**Fix**

Change `"decoder_"` → `"decoder's "` in the `err_msg_prefix` assignment inside `T5Stack.forward()`. Applied to all T5-family stacks that share the same pattern: T5, LongT5, mT5, UMT5, Pop2Piano, UDOP.

**Test**

No code logic changed — error messages only. Existing tests unaffected.

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

run-slow: longt5, mt5, pop2piano, t5, udop, umt5

**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46663)

Blocked for opening a code agent PR on an issue where a maintainer had already said they didn't want it. Sorry, but we have to ban quickly in these cases or we get flooded by slop!
fix(generation): honor cache_config.max_cache_len for static cache
Author: KirtiRamchandani
Pull request: yes
Labels: name: Code agent slop

## Summary
- Apply `generation_config.cache_config["max_cache_len"]` when allocating `StaticCache`, not only on the quantized cache path
- Use `max(auto_max_cache_length, user_max_cache_len)` so the cache is always large enough for the current call while allowing callers to pin a larger ceiling for subsequent `generate()` calls (avoids realloc + torch.compile recompile)

Fixes #46424

## Test plan
- [x] Manual repro with `hf-internal-testing/tiny-random-LlamaForCausalLM`: `cache_config={"max_cache_len": 2048}` now yields `StaticCache.max_cache_len == 2048` (was 47)
- [x] Added `test_prepare_cache_for_generation_static_cache_config_max_cache_len` in `tests/generation/test_utils.py`

/cc @ArthurZucker @Cyrilvallez

Comments:
View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=46666&sha=f51c0d

**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46666)
[model] Support MiniCPM-V 4.0
Author: tc-mb
Pull request: yes

This pull request supports the MiniCPM-V 4.0 model, which will be released soon.

Comments:
Great! LMK if you need an early review or would like the PR to be merged before the release

> Great! LMK if you need an early review or would like the PR to be merged before the release

Well, we released this [MiniCPM-V 4](https://huggingface.co/openbmb/MiniCPM-V-4) a few hours ago. We want to merge it into transformers. We'd be happy to have your help.


Yep, just saw, congrats on the release! Sure, I will do a preliminary review now and lmk if you need assistance with addressing comments/cleaning up the PR

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

run-slow: auto, minicpm_v_4

What's the current state @tc-mb? :hugs: 

> What's the current state @tc-mb? 🤗

This is too old; I'll get a new one when I have the chance.
Fix AttributeError in auto_factory when model_class lacks config_class
Author: atharv1945
Pull request: yes

Fixes #46661

## Problem
When loading a `trust_remote_code=True` model a second time in the same session, `AutoModel.from_pretrained` raises:

AttributeError: type object 'JinaEmbeddingsV5Model' has no attribute 'config_class'

The first call registers the remote model class into `cls._model_mapping`. On a second call, `_get_model_class` resolves via this registration, `has_local_code` becomes `True`, and the composite-config check `model_class.config_class == config.sub_configs.get("text_config", None)` crashes because remote-code classes aren't guaranteed to define `config_class`.

## Fix
Guard the comparison with `getattr` and short-circuit when the config has no `text_config` sub-config:

```python
text_config_class = config.sub_configs.get("text_config", None)
# getattr avoids AttributeError, as registered remote-code model classes may lack config_class
if text_config_class is not None and getattr(model_class, "config_class", None) == text_config_class:
```

Applied identically in `from_config` and `from_pretrained`.

## Testing
- Two-call reproducer (see #46661): second call now produces the same `ValueError: EuroBertModel does not support Flash Attention 2` as the first call, instead of `AttributeError`. That `ValueError` is a separate, pre-existing issue in jinaai's bundled remote code (out of scope here).
- `pytest tests/models/auto/ -v` → 115 passed, 25 skipped, 0 failed.

## AI assistance disclosure
Used Claude for diagnosis discussion, root-cause analysis, and reproducer drafting. I wrote, applied, and tested the fix and tests myself.

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

run-slow: auto

**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46669)

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=46669&sha=58cb11

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

# What does this PR do?

Same as https://github.com/huggingface/transformers/pull/40962 but cleans up the code to match transformers API. Couldn't test due to errors, the integration test is failing atm. Still need to clean the testing file 

Ideally this should be working with the following snippet, so users don't need to load image or add imaga tokens themselves

```python
import torch
from transformers import AutoProcessor, IsaacForConditionalGeneration

model_id = "PerceptronAI/Isaac-0.1"
processor = AutoProcessor.from_pretrained(model_id, revision="refs/pr/3",)
model = IsaacForConditionalGeneration.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="cuda",
    revision="refs/pr/3",
)


conversation = [
    {

        "role": "user",
        "content": [
            {"type": "text", "text": "Compare the two figures and explain what changed."},
            {"type": "image", "path": "first_image.png"},
            {"type": "image", "path": "second_image.png"},
            ],
    },
]

inputs = processor.apply_chat_template(
    conversation,
    tokenize=True,
    return_dict=True,
    add_generation_prompt=True,
    return_tensors="pt",
).to(model.device)

generated_ids = model.generate(
    **inputs,
    max_new_tokens=256,
    do_sample=False,
)

generated_ids = generated_ids[:, inputs["input_ids"].shape[1] :]
response = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)
```


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

run-slow: auto, isaac

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45186&sha=a44952
feat(generation): allow user to keep input tensors on cpu
Author: dacorvo
Pull request: yes

The tensors actually consumed by forward are only moved to the target device once they have been prepared.
This allows to keep some operations performed on growing tensors in the generation loop off the device, avoiding retracing on Neuron/TPU devices.

Fixes #44742

## Code Agent Policy

- [X] I confirm that this is not a pure code agent PR.

## Who can review?

@ArthurZucker @Cyrilvallez @vasqu

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_46590). 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=46590&sha=16d204

Merging now, thanks for bearing with me! (and sorry for the delays)

**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46590)
[`docs`] PULL_REQUEST_TEMPLATE.md has broken link to non-existent CONTRIBUTING.md section
Author: tomaarsen
Pull request: no

Hello!

## Details
This line in the PULL_REQUEST_TEMPLATE.md links to https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request, but this section doesn't exist in `CONTRIBUTING.md` (anymore?):

https://github.com/huggingface/transformers/blob/a14eae2b54c19cb427c919a99c75db07afbeb7a0/.github/PULL_REQUEST_TEMPLATE.md?plain=1#L35

cc @stevhliu Do you know what happened here? Could you perhaps pick this up?
cc @kurtmckee as I noticed this via your https://github.com/huggingface/transformers/pull/46596

- Tom Aarsen

Comments:
Hi @tomaarsen, happy to help with this if it's still available to work on.
[pr template] update
Author: stevhliu
Pull request: yes

fixes #46597 with new links

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

**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46606)
mistral common backend fix
Author: itazap
Pull request: yes

alt fix for  https://github.com/huggingface/transformers/pull/46622 (reproducer there)



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

**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46667)

run-slow: auto

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/27558199873)

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

models: ["models/auto"]
quantizations: []

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

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [4670fae2](https://github.com/huggingface/transformers/commit/4670fae2ef323010f3808c6f93b664dee482958b) | workflow commit (merge commit) |
| PR | [4bbe2a3f](https://github.com/huggingface/transformers/commit/4bbe2a3fee5270016e0ff699c4131071c7f3fe9a) | branch commit (from PR) |
| main | [920878b4](https://github.com/huggingface/transformers/commit/920878b452d139e564da2e5daa364dfec8750238) | base commit (on `main`) |

✅ No failing test specific to this PR 🎉 👏 !