noamaanMulla-03/transformers-issues huggingface dataset:
Prepare inputs for generation is called from `super()`
Author: zucchini-nlp
Pull request: yes

# What does this PR do?

As per title, less custom code and more standardization. There are still a few models with completely custom `prepare_inputs_for_generation`, I can't make those models happy with `super().prepare_inputs_for_generation` (musicgen, xlm, reformer)

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

run_slow: bert,  encoder_decoder, bamba, mamba, mamba2, falcon_h1, falcon_mamba, roformer, git

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

models: ["models/bamba", "models/bert", "models/encoder_decoder", "models/falcon_h1", "models/falcon_mamba", "models/git", "models/mamba", "models/mamba2", "models/roformer"]
quantizations: []

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

### Model CI Report

#### ❌ Failed tests

- [git](https://github.com/huggingface/transformers/actions/runs/20998808624/job/60363687529):
    tests/models/git/test_modeling_git.py::GitModelIntegrationTest::test_batched_generation
    tests/models/git/test_modeling_git.py::GitModelIntegrationTest::test_inference_image_captioning



run-slow: kosmos2_5

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

models: ["models/kosmos2_5"]
quantizations: []

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

### Model CI Report

#### ❌ Failed tests

- [kosmos2_5](https://github.com/huggingface/transformers/actions/runs/21028058698/job/60457869526):
    tests/models/kosmos2_5/test_modeling_kosmos2_5.py::Kosmos2_5ModelIntegrationTest::test_eager
    tests/models/kosmos2_5/test_modeling_kosmos2_5.py::Kosmos2_5ModelIntegrationTest::test_sdpa



CI failures are unrelated :eyes: 

Huh, interesting, the kosmos tests are still fine in dgx. Let me try runners as well

Passes inside the runners, what!? 🫠 

run-slow: kosmos2_5

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

models: ["models/kosmos2_5"]
quantizations: []

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

✅ No failing test specific to this PR 🎉 !


Super weird, maybe something broke in main temporarily? 

It might have grabbed incorrect commit prob, I pushed two commits at the same time 🙈 

View the CircleCI Test Summary for this PR:

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

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

run-slow: bamba, bert, big_bird, ctrl, ernie, falcon_h1, falcon_mamba, git, granitemoehybrid, kosmos2_5, mamba, mamba2, megatron_bert, prophetnet, rembert, roc_bert
Move hardcoded time_step params to config for Bamba, FalconH1, GraniteMoeHybrid
Author: raimbekovm
Pull request: yes

# What does this PR do?

Moves `time_step_min`, `time_step_max`, and `time_step_limit` from hardcoded values to configurable parameters in Bamba, FalconH1, and GraniteMoeHybrid models.

These parameters were previously hardcoded with a `# FIXME:` comment. This follows the pattern already established in Zamba2 where they are properly configurable.

**Before:**
```python
# FIXME:
self.time_step_limit = (0.0, float("inf"))
self.time_step_min = 0.001
self.time_step_max = 0.1
```

**After:**
```python
self.time_step_limit = config.time_step_limit
self.time_step_min = config.time_step_min
self.time_step_max = config.time_step_max
```

**Models affected:** Bamba, FalconH1, GraniteMoeHybrid

## 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).
- [ ] Did you write any new necessary tests?

## Who can review?

@vasqu

Comments:
View the CircleCI Test Summary for this PR:

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

run-slow: bamba,falcon_h1,granitemoehybrid

Resolved merge conflicts - rebased on main with the new type hint syntax

CI is complaining, can you check / fix

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

run-slow: bamba, falcon_h1, granitemoehybrid

Fixed, CI is green now

run-slow: bamba,falcon_h1,granitemoehybrid

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

models: ["models/bamba", "models/falcon_h1", "models/granitemoehybrid"]
quantizations: []

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

✅ No failing test specific to this PR 🎉 !
Revert utils files changes from db1e6f1e
Author: ydshieh
Pull request: yes

# What does this PR do?

PR #42845 fails some workflow runs

```
File "/home/runner/work/transformers/transformers/utils/get_ci_error_statistics.py", line 29, in get_jobs
    result = httpx.get(url + f"&page={i + 2}", headers=headers).json()
  File "/home/runner/.local/lib/python3.10/site-packages/httpx/_api.py", line 195, in get
    return request(
  File "/home/runner/.local/lib/python3.10/site-packages/httpx/_api.py", line 109, in request
    return client.request(
  File "/home/runner/.local/lib/python3.10/site-packages/httpx/_client.py", line 825, in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/home/runner/.local/lib/python3.10/site-packages/httpx/_client.py", line 914, in send
    response = self._send_handling_auth(
  File "/home/runner/.local/lib/python3.10/site-packages/httpx/_client.py", line 942, in _send_handling_auth
    response = self._send_handling_redirects(
  File "/home/runner/.local/lib/python3.10/site-packages/httpx/_client.py", line 979, in _send_handling_redirects
    response = self._send_single_request(request)
  File "/home/runner/.local/lib/python3.10/site-packages/httpx/_client.py", line 1014, in _send_single_request
    response = transport.handle_request(request)
  File "/home/runner/.local/lib/python3.10/site-packages/httpx/_transports/default.py", line 249, in handle_request
    with map_httpcore_exceptions():
  File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/runner/.local/lib/python3.10/site-packages/httpx/_transports/default.py", line 118, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout: The read operation timed out
```

revert some changes from that PR for now

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

didn't check with a full run (so don't know if it would work if the run has many jobs), but a dummy run is working.

Anyway, no time to trigger a full run and wait it to finish to know. I will merge and let's see tomorrow.
Qwen3-VL can't be loaded in transformers dev: AttributeError: 'Qwen3VLTextConfig' object has no attribute 'pad_token_id'
Author: albertvillanova
Pull request: no
Labels: name: bug

Qwen3-VL can't be loaded in transformers dev branch (5.0.0.dev0 at commit 24807bfcf4a21286fa2a7e728f381ddaaca7bbc7): 
> AttributeError: 'Qwen3VLTextConfig' object has no attribute 'pad_token_id'

After investigation, the issue appeared after the merge of this PR:
- https://github.com/huggingface/transformers/pull/41541

As @zucchini-nlp pointed out, there are no slow tests for `qwen3VL`, which could have prevented this.

See related issue in TRL:
- https://github.com/huggingface/trl/issues/4842

### Reproduction

```python
from transformers import AutoModel

AutoModel.from_pretrained('Qwen/Qwen3-VL-2B-Instruct')
```

Traceback:
```python
  File "<string>", line 1, in <module>
  File "transformers/src/transformers/models/auto/auto_factory.py", line 372, in from_pretrained
    return model_class.from_pretrained(
  File "transformers/src/transformers/modeling_utils.py", line 4020, in from_pretrained
    model = cls(config, *model_args, **model_kwargs)
  File "transformers/src/transformers/models/qwen3_vl/modeling_qwen3_vl.py", line 938, in __init__
    self.language_model = Qwen3VLTextModel._from_config(config.text_config)
  File "transformers/src/transformers/modeling_utils.py", line 1464, in _from_config
    model = cls(config, **kwargs)
  File "transformers/src/transformers/models/qwen3_vl/modeling_qwen3_vl.py", line 807, in __init__
    self.padding_idx = config.pad_token_id
  File "transformers/src/transformers/configuration_utils.py", line 164, in __getattribute__
    return super().__getattribute__(key)
AttributeError: 'Qwen3VLTextConfig' object has no attribute 'pad_token_id'. Did you mean: 'bos_token_id'?
```

### Who can help?

@zucchini-nlp, who created the PR

Comments:
I tested Qwen3-VL-2B-Thinking in huggingface just now, and then occurred:
> AttributeError: 'Qwen3VLTextConfig' object has no attribute 'pad_token_id'. Did you mean: 'bos_token_id'? 

then i tried to see model file, and copy line `"pad_token_id": 151643,` in file "generation_config.json" to "config.json", i found it run.
i dont know why =_= ...

![Image](https://github.com/user-attachments/assets/55d57fcf-5af1-4773-b679-1c8db474d5d6)


> I tested Qwen3-VL-2B-Thinking in huggingface just now, and then occurred:
> 
> > AttributeError: 'Qwen3VLTextConfig' object has no attribute 'pad_token_id'. Did you mean: 'bos_token_id'?
> 
> then i tried to see model file, and copy line `"pad_token_id": 151643,` in file "generation_config.json" to "config.json", i found it run. i dont know why =_= ...
> 
> ![Image](https://github.com/user-attachments/assets/55d57fcf-5af1-4773-b679-1c8db474d5d6)

This worked for me, seems the issue is just a missing config param? 

cc @zucchini-nlp not sure if a transformers bug or a malformed config.json, but seems related to #41541

I think this can be closed as well coz the PR to add `pad_token_id` is merged. cc @Rocketknight1 @zucchini-nlp 

All models to be fixed in https://github.com/huggingface/transformers/pull/43453
Fix Llama4 vision attention scaling for TP compatibility
Author: raimbekovm
Pull request: yes

# What does this PR do?

Fixes a bug where `vision_eager_attention_forward` ignored the passed `scaling` parameter and used `module.head_dim**-0.5` instead. This causes incorrect attention scores under Tensor Parallelism (TP) where head dimensions may differ from the original config.

**Changes:**
- Use passed `scaling` parameter in `vision_eager_attention_forward` instead of computing it internally
- Pass `self.scaling` at call site instead of `None`

**Test showing the bug:**
```python
# With different head_dim (simulating TP split)
original_head_dim = 64  # correct scaling = 0.125
tp_head_dim = 32        # buggy scaling = 0.177

# Output difference up to 0.55 between correct and buggy versions
```

## 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?
- [ ] Did you write any new necessary tests?

## Who can review?

@zucchini-nlp @ArthurZucker @molbap

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

run-slow: llama4

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=43481&sha=7c9cc5

TP should not split on head dim (but on the number of available heads). Hence, it doesn't really make sense imo

cc @molbap (since you added this iirc)

Yeah you're right, I checked - colwise shards on the output dim so it's num_heads that gets split, not head_dim. The TODO comment was misleading.

Still think the fix makes sense though - the function accepts `scaling` but ignores it, which is kinda weird. Better to use what's passed in imo.

Hey! I agree with the theory (that it does not make sense) but from what I remember of this (complicated) release, it was computed like this in the original code perhaps? I added the `None` (If I remember) to bypass this. Let's please take a look at the slow tests in `eager` and `sdpa` both before merging in case there's something off. 

Not feeling strongly here and since it seems to work I'd rather go "don't fix what's working" - if there is an instance where you can see something not working then I'm all up for it!

fair enough, I was mass-fixing TODOs and got carried away lol

No worries, appreciate it! :hugs: :heart: 

Closing this for now as discussed but feel free to reopen if you notice something (that could be added with a test)
Fix loading of Qwen3 FP8
Author: githubnemo
Pull request: yes

The Qwen3 MoE config was missing the mapping attribute for the num_expert_local config variable which made it impossible to load FP8 quantized models, due to the following exception:

```
Traceback (most recent call last):
  File ".../exps/train-qwen3-lora.py", line 4, in <module>
    base_model = AutoModelForCausalLM.from_pretrained('Qwen/Qwen3-30B-A3B-Thinking-2507-FP8')
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../transformers/src/transformers/models/auto/auto_factory.py", line 372, in from_pretrained
    return model_class.from_pretrained(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../transformers/src/transformers/modeling_utils.py", line 4075, in from_pretrained
    hf_quantizer.preprocess_model(
  File ".../transformers/src/transformers/quantizers/base.py", line 167, in preprocess_model
    self._process_model_before_weight_loading(model, **kwargs)
  File ".../transformers/src/transformers/quantizers/quantizer_finegrained_fp8.py", line 106, in _process_model_before_weight_loading
    model = replace_with_fp8_linear(
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../transformers/src/transformers/integrations/finegrained_fp8.py", line 617, in replace_with_fp8_linear
    new_module = FP8Expert(
                 ^^^^^^^^^^
  File ".../transformers/src/transformers/integrations/finegrained_fp8.py", line 496, in __init__
    self.num_experts = config.num_local_experts
                       ^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../transformers/src/transformers/configuration_utils.py", line 164, in __getattribute__
    return super().__getattribute__(key)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Qwen3MoeConfig' object has no attribute 'num_local_experts'
```

A small reproducer is added in the form of a unit test.

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

cc @MekkCyber for quants

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

run-slow: qwen3_moe, qwen3_omni_moe, finegrained_fp8

Merging since I verified locally that it works
update aria to remove wrong attention usage
Author: ArthurZucker
Pull request: yes

# What does this PR do?
Not sure how this got in here, but adapt aria cross attention to our standards

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_40452). 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: aria
does this fix?
Author: ArthurZucker
Pull request: yes

# What does this PR do?
Devstral

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

run-slow: auto

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

# What does this PR do?
This ensures that the naming is always the same across MoEs

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_40156). 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: aria, dbrx, deepseek_v2, deepseek_v3, doge, dots1, glm4_moe, glm4v_moe, gpt_oss, granitemoe, granitemoehybrid, granitemoeshared, jamba, jetmoe, llama4, minimax
[executorch] Update pytree registration for DynamicCache
Author: justinchuby
Pull request: yes

# What does this PR do?

Update pytree registration for DynamicCache. Before this change the cache values are flatten as `(key0, key1, ..., value0, value1, ...)`. This change matches the old cache interface by flattening to `(key0, value0, key1, value1, ...)`. This ordering matches transformers conversion and is consistent with expectation of downstream tools when they see ky caches.

The change is BC breaking in that it will change the signature of the exporter program. But this is ok since (1) there is going to be transformers 5.0 (2) executorch doesn't rely on this api. Only ONNX does at this point. (3) the original implementation was wrong (https://github.com/pytorch/pytorch/issues/165395)

Also fixes https://github.com/pytorch/pytorch/issues/165395. 

cc @titaiwangms @xadupre @jackzhxng @tugsbayasgalan 

Comments:
cc @gante for cache as well
Fix issue #39191 respect accelerate config to disable torch.dynamo compilation
Author: bonpiedlaroute
Pull request: yes

# Description

Fixes #39191 where transformers ignored accelerate configuration to disable torch.dynamo, leading to unexpected compilation and `FailOnRecompileLimitHit` errors.


## Problem

When users configure accelerate to disable torch.dynamo, transformers' automatic compilation in `_valid_auto_compile_criteria()` was not respecting this setting, causing:
- Unwanted torch.compile activation
- Excessive recompilations  
- `FailOnRecompileLimitHit` crashes in distributed training scenarios

## Solution

- Added `_is_dynamo_compilation_disabled()` method that checks standard environment variables
- Modified `_valid_auto_compile_criteria()` to respect these environment variables before enabling compilation


## Environment Variables Supported

- `TORCHDYNAMO_DISABLE=1`

## Tests done

- Compilation disabled when env var set
- Normal behavior preserved when no env var
- Backward compatible - no breaking changes

## Usage

Users experiencing the issue can now use:

```bash
export TORCHDYNAMO_DISABLE=1
python training_script.py
```
## Who can review?

@SunMarc @gante @zach-huggingface and @qgallouedec





Comments:
Please note that the failing test `tests/models/perceiver/test_modeling_perceiver.py::PerceiverModelTest::test_pipeline_image_classification_fp16 - PIL.UnidentifiedImageError: cannot identify image file ` 
is unrelated to this change. It seems to be an image file corruption or download issue, no link with torch.dynamo compilation fix.
All other pipeline tests (148) passed successfully
Thanks,
Noël

> Please note that the failing test tests/models/perceiver/test_modeling_perceiver.py::PerceiverModelTest::test_pipeline_image_classification_fp16 - PIL.UnidentifiedImageError: cannot identify image file 
> is unrelated to this change. It seems to be an image file corruption or download issue, no link with torch.dynamo compilation fix.

Yeah don't worry ! I'll rerun the CI to merge this 

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

@bot /style 

Style fix is beginning .... [View the workflow run here](https://github.com/huggingface/transformers/actions/runs/21001839883).

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=39683&sha=824bdc
fix: initialize BatchNorm2d buffers only on meta
Author: tarekziade
Pull request: yes

# What does this PR do?

Commit 8dd9c999a6262d6ceb48f4a2da7acaccfa80e3bc introduced a regression by unconditionally reinitializing BatchNorm2d buffers (running_mean, running_var, num_batches_tracked) in the _init_weights() method.

The problem: When loading pretrained timm models, the flow is:
1. timm.create_model(pretrained=True) correctly loads pretrained BatchNorm statistics
2. post_init() calls _init_weights() on all modules
3. _init_weights() overwrites the pretrained BatchNorm buffers with zeros/ones
4. Model produces incorrect results because normalization uses wrong statistics

The error shows a mismatch at index (0, 178, 0, 0) with a difference of 80224.0 on CircleCI on AVX 512 CPUs

The fix: added a check to only initialize BatchNorm2d buffers when they're on the meta device (uninitialized): This ensures pretrained buffers are preserved while still handling the meta device initialization case.


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

run-slow: timm_backbone, timm_wrapper

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

models: ["models/timm_backbone", "models/timm_wrapper"]
quantizations: []

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

✅ No failing test specific to this PR 🎉 !
[GLM-OCR] GLM-OCR Support
Author: zRzRzRzRzRzRzR
Pull request: yes
Labels: name: New model

Need reivew for @zucchini-nlp 

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

This PR also removes all restrictions on image sizes smaller than 28 in GLM-V (support in all GLM-V models)

Oke, will fix tests and then can merge

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

run-slow: auto, glm46v, glm4v, glm4v_moe, glm_ocr