noamaanMulla-03/transformers-issues huggingface dataset:
WeightRenaming doesn't allow more than one group to be matched
Author: sbucaille
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 5.0.0.dev0
- Platform: macOS-26.1-arm64-arm-64bit
- Python version: 3.12.11
- Huggingface_hub version: 1.3.1
- Safetensors version: 0.6.2
- Accelerate version: 1.11.0
- Accelerate config: 	not found
- DeepSpeed version: not installed
- PyTorch version (accelerator?): 2.8.0 (NA)
- Using distributed or parallel set-up in script?: <fill in>

### Who can help?

@Cyrilvallez 

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

Consider a model with 2 layers simply containing a linear.
For the following example, this works :
```python
weight_mapping = [
    WeightRenaming(r"layers.(\d+).lin", r"layers.\1.linear"),
]
missing, unexpected, mismatch, _, misc = convert_and_load_state_dict_in_model(
    model, state_dict, weight_mapping, tp_plan=None, hf_quantizer=None
)
print(missing)
print(unexpected)
print(mismatch)
```
Output : 
```
Loading weights: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 3677.06it/s, Materializing param=layers.2.linear.weight]
set()
set()
set()
```

But for the following example, this does not work : 
```python
weight_mapping = [
    WeightRenaming(r"layers.(\d+).lin.(weight|bias)", r"layers.\1.linear.\2"),
]
missing, unexpected, mismatch, _, misc = convert_and_load_state_dict_in_model(
    model, state_dict, weight_mapping, tp_plan=None, hf_quantizer=None
)
print(missing)
print(unexpected)
print(mismatch)
```
Output : 
```
Loading weights: 100%|Loading weights: 0it [00:00, ?it/s]
{'layers.2.linear.bias', 'layers.0.linear.bias', 'layers.1.linear.bias', 'layers.0.linear.weight', 'layers.2.linear.weight', 'layers.1.linear.weight'}
{'layers.1.linear.\\2', 'layers.0.linear.\\2', 'layers.2.linear.\\2'}
set()
```

I thought about using it for the convert script of RFDetr PR but I'm stuck with that 😅

### Expected behavior

Layers should be renamed no matter how many nested groups are included in the source and target patterns

Comments:
I dived a bit in the code and found this part of the code may be the problem : 

https://github.com/huggingface/transformers/blob/314f10929a2215b74c2ad6ecf7b2f380c9b7468a/src/transformers/core_model_loading.py#L513-L518

Replacing it with this made it work : 
```python
renamed_key = re.sub(source_pattern_that_matched, replacement, source_key)
```

I ran the tests and everything is still green, did you have edge cases in mind to not allow more nested groups ?
Maybe the use of this function is not appropriate for the case of a convert script but I thought I'd give a shot. I'd say it will make the code way cleaner by using `WeightTransform`'s.

#43205 should be very relevant to this!
Fix in-place modification of inputs_embeds in Kosmos-2.5 forward
Author: Neuro1729
Pull request: yes

# What does this PR do?

Fixes a PyTorch autograd error when fine-tuning `Kosmos2_5ForConditionalGeneration` with PEFT (LoRA).

The model forward pass performed an in-place assignment on `inputs_embeds`, which can be a leaf tensor with `requires_grad=True` during training. This caused the following runtime error:

RuntimeError: a leaf Variable that requires grad is being used in an in-place operation


This PR avoids the in-place modification by cloning the tensor before assignment, allowing training to proceed correctly while preserving existing behavior.

I have verified the fix using the reproduction script I provided in the issue; the RuntimeError is resolved and training proceeds as expected.

Fixes #43416

cc @zucchini-nlp


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

run-slow: kosmos2_5

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

# What does this PR do?

Fixes `test_inference_for_video_classification` failure in a multi-gpu environement.

See https://github.com/huggingface/transformers/actions/runs/21157884595/job/60846617284

The patch tweaks the values with reality



## 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:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_43406). 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: vivit

@ydshieh do we want to run vit/vivit on the gpu workers before merging? (I tried manually the fix in ssh)
Make `pr-repo-consistency-bot.yml` run complete list of fixes  
Author: ydshieh
Pull request: yes

# What does this PR do?

Happy for everyone if we can have such complete fixes from the bot instead of just `check_copies`.

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_43432). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
fix `pr-repo-consistency-bot.yml`
Author: ydshieh
Pull request: yes

# What does this PR do?

`check_modular_conversion` needs the repo. has the `main` branch info to compare against the PR changes.

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_43434). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Skip attention_mask.all() GPU-CPU sync during generation
Author: AmitMY
Pull request: yes

I guess there could be cases where people define a custom mask, but I don't know of any.

----

## Summary
- Adds a context variable `_attention_mask_all_true` to track if attention_mask is known to be all-True during generation
- Sets the context variable at the start of `generate()` based on the initial mask state
- Modifies `_ignore_causal_mask_sdpa()` to skip the expensive `.all()` check when the context variable indicates no padding

## Problem
During autoregressive generation, `_ignore_causal_mask_sdpa()` in `masking_utils.py` calls `padding_mask.all()` on every generated token to check if the mask contains any padding. This causes a GPU-CPU synchronization that adds ~2-3ms per token, significantly impacting generation latency.

## Solution
Since during generation we only append ones (1s) to the attention mask, if the mask starts all-True (no padding), it will remain all-True throughout generation. We check this once at the start and use a context variable to skip subsequent `.all()` checks.

## Results
- Reduces `.all()` calls from N+1 to 1 for N generated tokens
- Example: 201 calls → 1 call for 200 tokens generated
- Eliminates per-token GPU-CPU sync overhead (~2-3ms per token)

## Test plan
- [x] Verified outputs are identical with and without optimization
- [x] Verified `.all()` call count reduced from 201 to 1 for 200 tokens
- [ ] Run existing tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Comments:
Make bot don't fail the commands 
Author: ydshieh
Pull request: yes

# What does this PR do?

Let's not fail if bot can't fix

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

# What does this PR do?

It patches the following on Windows devices:
```python
from transformers import ChineseCLIPModel

model = ChineseCLIPModel.from_pretrained("OFA-Sys/chinese-clip-vit-base-patch16")
model.set_attn_implementation("eager")
print(model.config._attn_implementation)
```
```
Traceback (most recent call last):
  File "[sic]\demo_chinese_clip.py", line 4, in <module>
    model.set_attn_implementation("eager")
  File "[sic]\transformers\modeling_utils.py", line 1975, in set_attn_implementation
    if not submodule._can_set_attn_implementation():
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[sic]\transformers\modeling_utils.py", line 1921, in _can_set_attn_implementation
    code = f.read()
           ^^^^^^^^
  File "[sic]\transformers\Lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 44039: character maps to <undefined>
```

With this PR in place, it simply returns:
```
eager
```

Follow-up from https://github.com/huggingface/transformers/pull/42564#discussion_r2717965498

## 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.
- [ ] 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?

@vasqu
It would be very nice to include this in the v5. This caused test failures for my work on #42564 for ChineseCLIP and AyaVision, likely as those modeling files have characters that the default Windows `cp1252` encoding doesn't recognize. 

- Tom Aarsen

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

Fixed, turns out my `main` was behind locally.

- Tom Aarsen

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=43433&sha=f9f404
Fix tests to use LoadStateDictConfig
Author: gary149
Pull request: yes

## Summary
- Update `test_ernie4_5_vl_moe_conversion` and `test_ernie4_5_vl_moe_conversion_reversed` to use `LoadStateDictConfig` instead of passing `hf_quantizer` directly to `convert_and_load_state_dict_in_model`

## Test plan
- [x] Both tests pass locally

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_43444). 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=43444&sha=bf0887
Add aeva
Author: louzongzhi
Pull request: yes

# Add Aeva model support for causal language modeling

This PR adds support for **Aeva** model architecture to the transformers library. Aeva is a novel language model featuring a hybrid attention mechanism (DeepEmbed Sliding Window + Linear Suffix Attention) and Hierarchical Grouped Sparse Computation (HGSCMoE).

## What does this PR do?

### Model Features
This implementation includes the following core components:
- **Dual Attention Mechanisms**:
    - **DESWSA** (`AevaAttention`): DeepEmbed Sliding Window Suffix Attention for efficient local context modeling.
    - **DELSA** (`AevaLinearAttention`): DeepEmbed Linear Suffix Attention for handling long-range dependencies with linear complexity.
- **HGSCMoE**: Hierarchical Grouped Sparse Computation, which uses brain-inspired routing with anchor experts for efficient expert selection.
- **ROSA**: Rapid Online Suffix Automaton integration for fast autoregressive decoding with statistical fallback.
- **Manifold Constraints**: Multi-stream processing using Sinkhorn-Knopp projection for manifold-constrained hyper-streams.
- **DeepEmbed**: Token embedding scaling for enhanced representation.

### Technical Implementation
- Adds `AevaConfig`, `AevaModel`, and `AevaForCausalLM`.
- Implements `AevaDynamicCache` for efficient caching, supporting rolling buffers and recurrent states for linear attention.
- Integrates with `fla-core` (Flash Linear Attention) for optimized linear attention kernels.
- Integrates with `rosa_cpp` for the ROSA attention mechanism.
- Supports Grouped Query Attention (GQA) and RoPE.

### Dependencies
This model requires optional dependencies for optimal performance:
- `fla-core`: For Flash Linear Attention operations.
- `rosa-cpp`: For ROSA attention implementation (https://github.com/wjie98/rosa_soft).

The model can still be imported, but these dependencies are required for the actual forward pass.

## 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?
@ArthurZucker @CyrilVallez @vasqu

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

run-slow: aeva, auto

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=43390&sha=9f6c03

We are happy to support new models, not sure what happened here!
Fix per-sample nested label truncation in gather_for_metrics
Author: karthik-0306
Pull request: yes

This PR fixes an issue in `nested_truncate` that affects metric gathering
for models using per-sample nested label structures such as
`tuple[list[...], ...]` (e.g. Mask2Former).

Previously, truncation during metric gathering could occur at the wrong
nesting level, leading to tensor-dimension truncation or dropped label
components in last-batch edge cases (e.g. remainder == 1).

This change fixes the root cause by:
- Correctly truncating per-sample nested structures at the list (sample) level
- Preserving tuple structure and tensor contents
- Handling last-batch edge cases safely
- Adding a focused regression test that fails on main and passes with this fix

The fix avoids introducing task-specific logic into `Trainer` and does not
impact processor outputs.

Fixes #43388  
Related to #43395


Comments:
View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=43419&sha=8ebd8e

Sorry, these code agent PRs are really annoying to review - they sound useful at first but the logic is always very unclear, especially when it clashes with an existing open PR. I'm just gonna close this and we'll see if any issues remain after #43395 is merged
Add input validation to DataCollatorWithPadding
Author: karthik-0306
Pull request: yes

This PR adds minimal, safe input validation to `DataCollatorWithPadding` to provide
clearer error messages when malformed feature inputs are passed (e.g. empty batches
or non-dictionary samples).

This does not change behavior for valid inputs and preserves backward compatibility,
while preventing cryptic errors raised deeper inside tokenizer padding logic.


Comments:
The remaining failures are due to transient httpx.ReadTimeout errors in hub / torch test suites. Happy to retry or rebase if needed.

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=43221&sha=fafb43
Add regression test for ViT dynamic resolution with interpolate_pos_encoding
Author: SAURABHSALVE
Pull request: yes
Labels: name: Code agent slop

# What does this PR do?

This PR adds a regression test to [tests/models/vit/test_modeling_vit.py](cci:7://file:///c:/Users/HP/Downloads/huggingface/transformers/tests/models/vit/test_modeling_vit.py:0:0-0:0). 

It checks that [ViTModel](cci:2://file:///c:/Users/HP/Downloads/huggingface/transformers/tests/models/vit/test_modeling_vit.py:183:0-251:35) correctly handles input images with resolutions different from the model configuration when `interpolate_pos_encoding=True` is passed during the forward pass. This asserts that the model can dynamically interpolate position embeddings for larger or smaller images without error.

# Fixes
N/A (Adds missing test coverage for dynamic resolution support)

## 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?

@yonigozlan @molbap

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

run-slow: vit

Thanks for taking a look! Happy to make any changes if needed.
pin `torchcodec==0.9.1`
Author: ydshieh
Pull request: yes

# What does this PR do?

0.10 is out but we still have the pin torch==2.9.1

Let's pin torchcodec first and come back to check the new versions later

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

As per title, cleanup as this overwrite was not necessary

Can be verified by running (with and without this change)
```python
from transformers import AutoConfig


config = AutoConfig.from_pretrained("upstage/Solar-Open-100B")
print(config)
```

cc @oesni for viz

Comments:
run-slow: solar_open

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

models: ["models/solar_open"]
quantizations: []

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

✅ No failing test specific to this PR 🎉 !


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

run-slow: minimax_m2, solar_open

run-slow: minimax_m2

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

models: ["models/minimax_m2"]
quantizations: []

I've checked through all the models that overwrite it and only found minimax m2 

The other models need it to be BC with the already released models. 

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

✅ No failing test specific to this PR 🎉 !