noamaanMulla-03/transformers-issues huggingface dataset:
Minor fix in docker image build workflow
Author: ydshieh
Pull request: yes

# What does this PR do?

A minor mistake left before merge in #41892

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_41949). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Fix: Skip weight initialization for quantized int8 models
Author: Pranavi125
Pull request: yes
Labels: name: Code agent slop

What does this PR do?
This PR fixes an issue where quantized models (e.g., RedHatAI/Qwen2.5-VL-7B-Instruct-quantized.w8a8) fail to load due to a dtype incompatibility during weight initialization.

Problem
When loading quantized models (dtype=torch.int8), the method _load_pretrained_model() still calls initialize_weights().
Since PyTorch’s normal_() operation is unsupported for integer tensors, this leads to:
RuntimeError: expected a floating-point or complex dtype, but got dtype=torch.int8

Fix
Added a condition to skip weight initialization when the model is quantized:
if not is_quantized:
    self.initialize_weights()
This ensures that quantized models bypass floating-point initialization safely.

Impact
✅ Prevents reinitialization of quantized weights
✅ Allows quantized models to load successfully using llmcompressor or compressed-tensors
✅ No change or performance impact for standard (float/bfloat) models

Checklist
 Fixes dtype initialization crash for quantized models
 Tested locally with Qwen2.5-VL-7B-Instruct-quantized.w8a8
 Maintains full compatibility with non-quantized models

Comments:
Fix rope_parameters for gemma3 weights conversion script
Author: douglas-reid
Pull request: yes

# What does this PR do?

Fixes the rope_parameters in the weights conversion script for Gemma 3.

These should be:

```
local => default @ 10_000.0
global => linear(8.0) @ 1_000_000.0
```

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

run-slow: gemma3

cc @zucchini-nlp 

Yes, good fix - `rope_parameters` is assumed to be keyed by layer type in the `modeling` file, so this conversion script would generate a broken config in at least some cases.

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

# What does this PR do?

Fixes #41738 


## 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?

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.
@zucchini-nlp

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

run-slow: florence2

@vasqu  I don't know who to ping lol can you please look into this 

@zucchini-nlp is the right person but she's out for a bit. Maybe checking in with the original author @ducviet00 

Looks simple enough 

>Thx, just to be sure: Do we need the if check or shouldn't it always default to bart?

Atm we don't really need the if check , but I've added it just in case . Should I remove it? 

Nah it's fine, let's see if different remote models come along with a different text backbone and fix then if needed

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

# What does this PR do?

Related to https://github.com/huggingface/transformers/pull/41922, this PR corrects the assignment of the `rope_scaling` dictionary present on some Gemma 3 pre-trained models on HF Hub when normalizing to the new `rope_parameters` value.

## 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.

@zucchini-nlp PTAL since you have been handling the RoPE changes. 

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

run-slow: gemma3

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

> I'm guessing the context for this is that `rope_scaling` clobbering `rope_parameters` (the old behaviour) gave the right config for older models but breaks on upcoming models that might have specific configs for e.g. `sliding_attention`?

Yes, we've observed that `rope_scaling` was being applied to both `full_attention` _and_ `sliding_attention` for the Gemma 3 checkpoints on HF Hub and in our attempts to re-convert them from the original Orbax checkpoint. The correct behavior is for `rope_scaling` to only be applied to `full_attention` if it exists in the config, and the `sliding_attention` config should always be default RoPE @ 10k.

Got it, thanks for the fix!
feat: add gradient_accumulation_steps argument to image classificatio…
Author: Priyanshjain10
Pull request: yes

## What does this PR do?

Adds `--gradient_accumulation_steps` argument to the image classification no_trainer example script, addressing issue #18436.

## Motivation

Gradient accumulation allows training with larger effective batch sizes by accumulating gradients over multiple batches before performing an optimizer step. This is especially useful when GPU memory is limited.

## Changes

- Added `--gradient_accumulation_steps` argument parser in `run_image_classification_no_trainer.py`
- Default value: 1 (no accumulation, maintains backward compatibility)
- Type: int
- Includes help text explaining the feature

## Related Issue

Fixes #18436

---

**Submitted for Hacktoberfest 2025** 🎃

Comments:
Request for InternVL3_5_Flash
Author: YanxingLiu
Pull request: no
Labels: name: New model

### Model description

InternVL3_5_Flash employ an additional router to use dynamic resolution of input images and this is not compatible with previous class "InternVLForConditionalGeneration". As a result, I would like to inquire whether it is possible to support the Flash version of InternVL3-5.

<img width="430" height="500" alt="Image" src="https://github.com/user-attachments/assets/f06aaf71-927f-4b55-a2a3-63e16a1c8103" />

### Open source status

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

### Provide useful links for the implementation

https://huggingface.co/OpenGVLab/InternVL3_5-8B-Flash/blob/main/modeling_internvl_chat.py

Comments:
Yes, but we'd need someone to make a PR to add a new model class for it! If you use [modular style](https://huggingface.co/docs/transformers/en/modular_transformers) then it should be a short PR because most of the code can be imported from existing models.

Hi @Rocketknight1,

Thank you for the confirmation and the helpful suggestion!

I would like to take this on and will start working on a PR to add the new model class for InternVL3_5-8B-Flash. I'll be sure to follow the modular style and import from the existing InternVL model code to keep the PR concise.

Could you please assign this issue to me?

Thanks!

We don't do issue assignment, but feel free to open a PR!
Merge Text2Text pipeline into TextGeneration
Author: Rocketknight1
Pull request: yes

We've already merged ConversationalPipeline into TextGenerationPipeline, so now it's time to do the same with Text2TextGenerationPipeline, which is also just a wrapper around `model.generate()`.

This one is a little trickier, though, because of some differing expectations about special tokens between the two cases, but I'm pretty sure I can figure out a solution! Draft PR for now.

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

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.

Should we pick that up @Rocketknight1?

Reawakening this one - I delayed it because it broke backward compatibility, but `v5` is the time to do it I think!

Starting a fresh PR - this branch is way too divergent from `main` at this point
Fixes wrong epoch count in trainer under some conditions 
Author: i3hz
Pull request: yes

# What does this PR do?
When using an iterable dataset, the Trainer incorrectly calculates `steps_in_epoch` as `max_steps`, 
causing epoch values to be 2x smaller than expected.


Fixes #41913 



## 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. https://github.com/huggingface/transformers/issues/41913
- [ ] 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  @SunMarc @nzw0301 

members/contributors who may be interested in your PR.



Comments:
heh not sure why it shows a lot of older commit?
LlamaAttention num_heads
Author: shanhx2000
Pull request: no
Labels: name: bug

### System Info

In older version of transformers, LlamaAttention init attribute num_heads. 

class LlamaAttention(nn.Module):
    def __init__(self, config):
        self.num_heads = config.num_attention_heads
        self.head_dim = config.hidden_size // config.num_attention_heads

However, in the recent versions, this attribute has been removed and thus causing mismatched when using previous codes. It ssems num_key_value_heads is also deprecated. This issue could be addressed by adding:
        self.num_heads = config.num_attention_heads # shanhx
        self.num_key_value_heads = config.num_key_value_heads

Is there any reasons why these attributes are removed? Is it intended or a bug?



### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

At least the num_heads stil remained at 4.44. But missed in 4.54. 

### Expected behavior

Missing many attributes in LlamaAttention. 

Comments:
It is not used in our modeling code as we do the following https://github.com/huggingface/transformers/blob/77e8b9f8dfc8e736ad2f603a5b2ae2b1076ed271/src/transformers/models/llama/modeling_llama.py#L261-L262

In essence, we do `bsz, seq_len, -1, head_dim` instead of `bsz, seq_len, num_heads, head_dim`. This is due to the fact that `num_heads` is split during multi-gpu scenarios like TP (tensor parallel) and we avoid recalculating the number of actual heads. 

Is there any specific use-case for you that used the `num_heads` attribute? You can also just access the config directly instead, e.g. `layer.config.num_heads` instead of `layer.num_heads`.

Thanks for the response. I met this issue when running this repo: "https://github.com/FasterDecoding/TEAL/tree/main", which uses num_heads for some settings. You are right. We are able to use layer.config.num_heads instead.
Fix Qwen3-VL Processor flattening multi-image batches (fix #41709)
Author: Elon7069
Pull request: yes


Fixes #41709

This PR fixes how Qwen3-VL Processor handles multiple images per sample.
Previously, all images were flattened across the batch, causing shape mismatches in model forward passes.

**Changes:**
- Updated Qwen3VLProcessor to preserve per-sample image grouping.
- Added test to verify batch dimension consistency.

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

run-slow: qwen3_vl

Hi, this PR fixes the issue where Qwen3VLProcessor was flattening multi-image batches. It now preserves per-sample grouping and passes the added unit test.

cc @zucchini-nlp
[kernels] update flash-attn kernel name to flash-attn2
Author: MekkCyber
Pull request: yes

# What does this PR do?

Simply updates all occurences of the kernel `kernels-community/flash-attn` with `kernels-community/flash-attn2`

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_41961). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Issues when updating the .gitignore file in run_clm_no_trainer.py
Author: wwt17
Pull request: no

https://github.com/huggingface/transformers/blob/1f0b490a2c42eb129dccc69031ccb537058689c4/examples/pytorch/language-modeling/run_clm_no_trainer.py#L311 `w+` mode will truncate the file to zero length. Also,
https://github.com/huggingface/transformers/blob/1f0b490a2c42eb129dccc69031ccb537058689c4/examples/pytorch/language-modeling/run_clm_no_trainer.py#L314 the file cannot be iterated over twice.

Comments:
Yes, agreed that block is very odd. Fixes appreciated!

Tried to fix on this PR https://github.com/huggingface/transformers/pull/41957 @Rocketknight1
Improve typing support and flexibility for RopeParameters
Author: RyanMullins
Pull request: no
Labels: name: Feature request

### Feature request

The new `RopeParameters` data structure is really improving the clarity of RoPE configurations across the library. However, I have noticed two areas for improvement: 

1.  Type hints and docstrings for key functions, such as [modeling_rope_utils.standardize_rope_params()](https://github.com/huggingface/transformers/blob/90d1b67db1ecf15a631b8020d412bfbee2f0206c/src/transformers/modeling_rope_utils.py#L30), to clarify and reflect their relationship to the `RopeParameters` structure.
2.  Loosening typing enforcement on `RopeParameters` such that you only need to specify the flags relevant for your model's RoPE needs by setting [`total=False` in the class definition](https://docs.python.org/3/library/typing.html#typing.TypedDict) and using the [`Required` type annotation](https://docs.python.org/3/library/typing.html#typing.Required) for the few parameters that really _do_ need to to be there.

### Motivation

1. Strong typing is almost always better, in my opinion.
2. Having to specify the every `RopeParameters` property is annoying when you only use a couple of them. Consider Gemma 3. Under the current definition of `RopeParameters`, it requires 28 lines to satisfy the type checker:
    ```python
    rope_params = {
        "full_attention": RopeParameters(
            rope_type="linear",
            rope_theta=1_000_000.0,
            factor=8,
            original_max_position_embeddings=None,
            attention_factor=None,
            beta_fast=None,
            beta_slow=None,
            short_factor=None,
            long_factor=None,
            low_freq_factor=None,
            high_freq_factor=None,
        ),
        "sliding_attention": RopeParameters(
            rope_type="default",
            rope_theta=10000.0,
            factor=None,
            original_max_position_embeddings=None,
            attention_factor=None,
            beta_fast=None,
            beta_slow=None,
            short_factor=None,
            long_factor=None,
            low_freq_factor=None,
            high_freq_factor=None,
        ),
    }
    ```
    When this could be expressed in 11 lines:
    ```python
    rope_params = {
        "full_attention": RopeParameters(
            rope_type="linear",
            rope_theta=1_000_000.0,
            factor=8,
        ),
        "sliding_attention": RopeParameters(
            rope_type="default",
            rope_theta=10000.0,
        ),
    }
    ```

### Your contribution

I'm willing to do all of this. Also, I've already been making some progress against these objectives in https://github.com/huggingface/transformers/pull/41934 and https://github.com/huggingface/transformers/pull/41963. 

Comments:
V4.57.1 training ci: Refactor `test_tensor_parallel.py`
Author: 3outeille
Pull request: yes

# What does this PR do?

Refactor  `test_tensor_parallel.py` by removing `subprocess`. This way we can easily debug with breakpoint the test if it fails. On top of that, I made the tests more robust by testing on more than `--nproc_per_node> 2.` `--nproc_per_nodes = 8` crashes because the llama model we use is too tiny so can't do TP. But since it works with  `--nproc_per_nodes = 4` already, no need to get a bigger llama (that may slow down the tests)

## Who can review?

@ArthurZucker @Cyrilvallez 


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

# What does this PR do?
Fix small typo. Without consequences, but still confusing.

Fixes https://github.com/huggingface/transformers/issues/41919

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

run-slow: lfm2_vl

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_41940). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
LFM2 image_processing_lfm2_vl_fast.py Mean Std swapped?
Author: florianvoss-commit
Pull request: no
Labels: name: bug

### System Info

In LFM2-VL image_processing_lfm2_vl_fast.py line 212 following the MEAN and STD from imagenet is used for preprocessing.
However it seems like they are swapped:
    image_mean = IMAGENET_STANDARD_STD
    image_std = IMAGENET_STANDARD_MEAN

or is this correct ?

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

Have a look at https://github.com/huggingface/transformers/blob/main/src/transformers/models/lfm2_vl/image_processing_lfm2_vl_fast.py

### Expected behavior

Not optimized VLM Behaviour

Comments:
I think you are right!. This certainly damages the normalization quality of the image.Are you planning to raise the pr? If not I can certainly help.  

cc @yonigozlan 

In the end IMAGENET_STANDARD_STD and IMAGENET_STANDARD_MEAN are the same, so it doesnt  matter for now.
It just a bit confusing.

Nice catch! It will be fixed here https://github.com/huggingface/transformers/pull/41940
fix prepare_config_and_inputs_for_common bug in llava test
Author: yao-matrix
Pull request: yes

@ydshieh, pls help review, thx very much.

Comments:
I think that was probably meant as a ping for @ydshieh :sweat_smile: 

> I think that was probably meant as a ping for @ydshieh 😅

yes, sorry 😅

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

run-slow: llava

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

seems there is some connection issue for hub tests. I will check later
make recurrent_gemma and voxtral cases pass on xpu
Author: yao-matrix
Pull request: yes

@ydshieh , pls help review, thx very much

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

run-slow: recurrent_gemma, voxtral

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

# What does this PR do?

This PR fixes an issue in `run_clm_no_trainer.py` where the `.gitignore` file was being truncated due to the use of `"w+"` mode when writing.  
Now, the script preserves existing `.gitignore` content, avoids duplicates, and safely appends the required ignore patterns for model outputs (`step_*` and `epoch_*`).


I have tested with:

1. no gitignore: file was created and populated with step_* and epoch_*
2. gitignore with additional content: step_* and epoch_* were added after previous content
3. blank gitignore: step_* and epoch_* were added to the file

Fixes #41896


## 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?

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.

wdyt @Rocketknight1?

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

Thanks @Rocketknight1!