noamaanMulla-03/transformers-issues huggingface dataset:
Fix TimesFM patch normalization instability
Author: AnMakc
Pull request: yes

This PR fixes patch normalization issue in TimesFM model:
- Numerical instability for low-variance data
- Incorrect clamping of calculated sigma to one instead of configured eps

Issue only affects data with low relative variance and results in incorrect prediction.
Variance is now calculated after mean removal to avoid catastrophic cancellation.

@kashif Please, take a look as you contributed this model.

## Bug demo

<img width="889" height="590" alt="image" src="https://github.com/user-attachments/assets/110bc961-333f-44fc-ae95-366172720271" />

<details>
<summary> Code to reproduce </summary>

```py
import random

import numpy as np
import matplotlib.pyplot as plt
import torch

from transformers import TimesFmModelForPrediction


seed = 42
np.random.seed(seed)
torch.manual_seed(seed)
random.seed(seed)


model = TimesFmModelForPrediction.from_pretrained(
    "google/timesfm-2.0-500m-pytorch",
    attn_implementation="sdpa",
    device_map="auto",
)

model.eval()


X_inp = np.arange(256)
X_pred = np.arange(256, 256 + 128)

fig, axs = plt.subplots(2, 2, figsize=(12, 12))

for ax, sigma in zip(axs.flatten(), [1e-0, 1e-1, 1e-2, 1e-3]):
    rng = np.random.default_rng(seed=seed)
    Y_inp = 1e3 + rng.normal(loc=0, scale=sigma, size=(256,)).cumsum()

    inputs = [
        torch.from_numpy(Y_inp).to(model.device, dtype=model.dtype)
    ]

    with torch.no_grad():
        pred = model(past_values=inputs)
        pred = pred.mean_predictions.cpu().numpy().squeeze()

    ax.plot(X_inp, Y_inp, label='Inputs')
    ax.plot(X_pred, pred, label='Mean Prediction')
    ax.set_title(f'Sigma={sigma}')
    ax.legend()

```
</details>


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

run-slow: timesfm

@kashif Kind ping :)

thanks @AnMakc checking! looks good overall

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

# What does this PR do?

Refactors torchao quantization method to use conversion ops instead of the classical `create_quantized_param`


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42289). 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: finegrained_fp8, torchao_integration
[`Attn Masks`] Add skip option for non-packed sequences
Author: vasqu
Pull request: yes

Given a non-packed sequence, no attn mask, and no cache: We currently still create a mask for this. Related to #41856 for example

This PR changes the behavior under non-compile. The compile-based versions are trickier, maybe a part 2 in the future.

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42367). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Add backward compatibility for `rope_theta` in the same way as `rope_scaling`
Author: hmellor
Pull request: yes

Custom models may still be using `rope_scaling` and `rope_theta`. If they are, we should also add a property for `rope_theta` for full backward compatibility.

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42390). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Auto convert tekken.json
Author: ArthurZucker
Pull request: yes
Labels: name: for patch

# What does this PR do?
1. If `mistral-common` is not installed, we can always convert to `tokenizer.json`
2. Don't convert if a tokenizer.json is here
3. Fix the tokenizer if its affected by the regex issue. 

```python
In [3]: tok = AutoTokenizer.from_pretrained("mistralai/Mistral-Small-3.1-24B-Instruct-2503")
The tokenizer you are loading from 'mistralai/Mistral-Small-3.1-24B-Instruct-2503' with an incorrect regex pattern: https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Instruct-2503/discussions/84#69121093e8b480e709447d5e.  This will lead to incorrect tokenization. You should set the `fix_mistral_regex=True` flag when loading this tokenizer to fix this issue.

In [4]: tok = AutoTokenizer.from_pretrained("mistralai/Mistral-Small-3.1-24B-Instruct-2503", fix_mistral_regex=True)
# no warning
In [2]: tok = AutoTokenizer.from_pretrained("mistralai/Mistral-Small-3.1-24B-Instruct-2503", fix_mistral_regex=False)
# no warning either
In [3]: tok.fix_mistral_regex
Out[3]: False

In [4]: tok = AutoTokenizer.from_pretrained("mistralai/Mistral-Small-3.1-24B-Instruct-2503")
The tokenizer you are loading from 'mistralai/Mistral-Small-3.1-24B-Instruct-2503' with an incorrect regex pattern: https://huggingface.co/mistralai/Mistral-Small-3.1-24B-Instruct-2503/discussions/84#69121093e8b480e709447d5e.  This will lead to incorrect tokenization. You should set the `fix_mistral_regex=True` flag when loading this tokenizer to fix this issue.

In [5]: tok.fix_mistral_regex
Out[5]: False
```

Superseed #41592 and #41718 for now, fixes #41553, fixes #42283

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42299). 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
Add granit speech doc
Author: Deep-unlearning
Pull request: yes

# What does this PR do?

Add usage example for the Granite Speech models

@eustlb



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

Closing this as #42125 supersedes it
Xcodec fix
Author: eustlb
Pull request: yes

# What does this PR do?

Before a deeper clean (#42039) on xcodec and to break things down a bit, this PR fixes some inefficient logic in X-codec, responsible for unnecessary memory spikes.

Makes me think that the whole `_get_output_length` when applying conv1d, which is repeated a lot throughout audio models, could benefit from some standardisation. In that objective, I've added a new audio util that I'll propagate in a subsequent PR.

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42095). 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: xcodec
[core] Fix mxfp4 model loading
Author: MekkCyber
Pull request: yes

# What does this PR do?



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

also another nit is that arthur prefer that we don't update the unexpected keys at all and deal with missing keys instead (even that it will be better if we don't touch that at all). Check the bnb PR.
'dict' object has no attribute 'model_type'
Author: wangby
Pull request: no
Labels: name: bug

### System Info

transformers == 4.57.2
vllm == 0.11.0

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

when loading `Qwen/Qwen3-235B-A22B-Thinking-2507` with `vllm.entrypoints.openai.api_server`, it's failed with
```
1849
   File "/root/vllm_env/lib/python3.10/site-packages/vllm/transformers_utils/tokenizer.py", line 217, in get_tokenizer
1850
     tokenizer = AutoTokenizer.from_pretrained(
1851
   File "/root/vllm_env/lib/python3.10/site-packages/transformers/models/auto/tokenization_auto.py", line 1156, in from_pretrained
1852
     return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
1853
   File "/root/vllm_env/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 2112, in from_pretrained
1854
     return cls._from_pretrained(
1855
   File "/root/vllm_env/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 2419, in _from_pretrained
1856
     if _is_local and _config.model_type not in [
1857
 AttributeError: 'dict' object has no attribute 'model_type'
```

### Expected behavior

_config.model_type -> _config.get("model_type")

Comments:
facing same error

same error

Installed 1 package in 4.21s
  transformers==4.57.2
  transformers==4.57.1

This is an issue caused by the transformers version update.  

same error

+1

This issue can be resolved just by replacing '_config.model_type' with '_config["model_type"]' in the transformers/tokenization_utils_base.py script.

Just downgrade the `transformers` library to version **4.57.1** and it will work fine：
```bash
pip install transformers==4.57.1
```

same error, just downgrade 4.57.1 will be ok

Same issue, resolved by replacing line 2419 in `tokenization_utils_base.py` with
```
if _is_local and _config["model_type"] not in [
```

We'll patch this asap sorry everyone

See #42389 for the fix
Fix _config attr error in tokenization_utils_base.py :)
Author: nil0x9
Pull request: yes

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes # ([issue](https://github.com/huggingface/transformers/issues/42378))



Comments:
Ty we are indeed fixing it in #42389!
Can't use local model (Solved)
Author: kabayan
Pull request: no
Labels: name: bug

### System Info

With v4.57.2, 


### Who can help?

I can't use local saved model(Qwen3-vl-2b).

File "/opt/venv/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 2419, in _from_pretrained
    if _is_local and _config.model_type not in [
AttributeError: 'dict' object has no attribute 'model_type'

So I changed below and works.
    if _is_local and _config.get("model_type") not in [

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

1. Load any model by any style (hf download, git etc)
2. Use AutoProcessor.from_pretrained(download_folder)
3. Error!

### Expected behavior

Just code is wrong.

Comments:
Hit the same issue. Bug introduced here https://github.com/huggingface/transformers/pull/42299/files#diff-85b29486a884f445b1014a26fecfb189141f2e6b09f4ae701ee758a754fddcc1R2471 in `v4.57.2`.

Fix:

```diff
-    if _is_local and _config.model_type not in [
+    if _is_local and _config['model_type'] not in [
```

For those who cannot wait. Changing `transformers_version" in `config.json` to `"4.57.2"` can also solve this issue, but there may be some risk depending on the model/tokenizer you are using.

+1

Reproducible on CI: https://github.com/microsoft/agent-lightning/actions/runs/19649153572/job/56271697604

I'm using Qwen/Qwen2.5-0.5B-Instruct.

> Hit the same issue. Bug introduced here https://github.com/huggingface/transformers/pull/42299/files#diff-85b29486a884f445b1014a26fecfb189141f2e6b09f4ae701ee758a754fddcc1R2471 in `v4.57.2`.
> 
> Fix:
> 
> -    if _is_local and _config.model_type not in [
> +    if _is_local and _config['model_type'] not in [
> For those who cannot wait. Changing `transformers_version" in `config.json`to`"4.57.2"` can also solve this issue, but there may be some risk depending on the model/tokenizer you are using.

This doesn't work for me when I'm using vllm(version 0.10.0) and I don't know why. Will this bug be fixed soon?

cc @ArthurZucker !

Yes we are on it! Fix is in #42389 we are patching in a bit
Corrected line 2471 from _config.model_type to _config["model_type"]
Author: Ankush-Balse
Pull request: yes

As per line 2467: _config = json.load(f)
In python, since config.json file read is usually a json, it is returned in dictionary format. thus the output of 'json.load(f)' is a <class: dict> object

However line 2471 tries to access the key "model_type" in a wrong manner. _config.model_type throws an error since _config is a 'dict' object. Hence corrected to _config["model_type"]

# What does this PR do?
This pr fixes the incorrect use of _config variable

Fixes # (issue)
As per line 2467: 
```
_config = json.load(f)
```
In python, since config.json file read is usually a json, it is returned in dictionary format. thus the output of 'json.load(f)' is a <class: dict> object

However line 2471 tries to access the key "model_type" in a wrong manner.
Hence _config.model_type will throw an error that
```
AttributeError: 'dict' object has no attribute 'model_type'
```

Thus in line 2471, changed _config.model_type to _config["model_type"]

Comments:
This bug breaks loading local fine tuned models. I tried fine tuning gemma3 and it loads fine, but I try and load the fine-tuned version from my local file system and it crashes complaining about `AttributeError: 'dict' object has no attribute 'model_type'` on this line. Tested this patch and it fixes my problem. Thanks for the patch! Hope this is merged soon!

Yes the fix is coming sorry everyone!
Add more items to migration guide
Author: Wauplin
Pull request: yes

PR on top of https://github.com/huggingface/transformers/pull/42386 cc @LysandreJik 

I have added parts I could help with. Let me know if you want me to change anything :) 

Feel free to merge anytime.

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42399). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
AutoTokenizer.from_pretrained crashed：AttributeError: 'dict' object has no attribute 'model_type' (fixed)
Author: skadiUnderTides
Pull request: no
Labels: name: bug

### System Info

**Environment**

* transformers==4.57.2
* python==3.10

**Problem**

In `tokenization_utils_base.py` (around line 2419), `_config` is loaded from `tokenizer_config.json` with:

```python
_config = json.load(f)
transformers_version = _config.get("transformers_version")
```

So `_config` is a **dict**.

A few lines below, the logic in 4.57.2 does:

```python
if transformers_version and version.parse(transformers_version) <= version.parse("4.57.2"):
    if _is_local and _config.model_type not in [
        "mistral",
        "mistral3",
        "voxstral",
        "ministral",
        "pixtral",
    ]:
        return tokenizer
```

Here `_config.model_type` assumes `_config` is an object, but it is actually a dict, which causes:

```text
AttributeError: 'dict' object has no attribute 'model_type'
```

**Suggested fix**

Replace `.model_type` with a dict-safe access, e.g.:

```python
if transformers_version and version.parse(transformers_version) <= version.parse("4.57.2"):
    if _is_local and _config.get("model_type") not in [
        "mistral",
        "mistral3",
        "voxstral",
        "ministral",
        "pixtral",
    ]:
        return tokenizer
```

### Who can help?

-

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

-

### Expected behavior

-

Comments:
I get this too: https://github.com/Blaizzy/mlx-vlm/issues/601#issue-3660949817

The models worked fine with 4.57.1


Sorry, so many simultaneous issues with essentially the same issue. We added a fix in #42389. It was also added to the patch release here https://github.com/huggingface/transformers/releases/tag/v4.57.3

I'll close this but lmk if this still persists

4.57.3 seems to have sorted my various breakages.  Thank you.
[SAM3] Fix precompute vision_embeds or text_embeds for inference
Author: yonigozlan
Pull request: yes
Labels: name: for_v5?

# What does this PR do?

Some checks in the processing were preventing inference with precomputed vision_embeds or text_embeds.
This fixes it, add examples and tests


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

run-slow: sam3

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42407). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Tokenizer fails to load from cache with local_files_only on 4.57.2
Author: chtruong814
Pull request: no
Labels: name: bug

### System Info

transformers==4.57.2

### Who can help?

@vasqu @ArthurZucker 

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

This call fails even if the tokenizer is in the cache:
```
AutoTokenizer.from_pretrained('meta-llama/Meta-Llama-3-8B', local_files_only=True)
```

It fails with this:
```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/venv/lib/python3.12/site-packages/transformers/models/auto/tokenization_auto.py", line 1149, in from_pretrained
    return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/transformers/tokenization_utils_base.py", line 2108, in from_pretrained
    remote_files = os.listdir(pretrained_model_name_or_path)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'meta-llama/Meta-Llama-3-8B'
```

It seems to be due to this change that is causing other issues:
https://github.com/huggingface/transformers/pull/42299

https://github.com/huggingface/transformers/pull/42299/files#diff-85b29486a884f445b1014a26fecfb189141f2e6b09f4ae701ee758a754fddcc1R2108



### Expected behavior

It should succeed in loading the tokenizer

Comments:
Do you mean if you do: 
```python 
from transformers import AutoTokenizer
AutoTokenizer.from_pretrained('meta-llama/Meta-Llama-3-8B')
AutoTokenizer.from_pretrained('meta-llama/Meta-Llama-3-8B', local_files_only=True)
```


@ArthurZucker correct.  Sorry for not being clear.  We may load the files into the cache ahead of time and only load locally after that.  

Yeah we're patching this in max 1h

Should be fixed in #42389, forgot to add this in the description

Thanks so much!
Replace Optional and Union typing with | in some source files
Author: cyyever
Pull request: yes

# What does this PR do?

This PR uses Python 3.10 typing for `Optional` and `Union` types.

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42372). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
🚨 Delete deprecations with end-cycle in v4.xx and v5.0
Author: zucchini-nlp
Pull request: yes
Labels: name: for_v5?

# What does this PR do?

Deletes deprecation for the v5 release. cc @yonigozlan and @eustlb to verify that we can really delete them, since it is mostly deprecated stuff from processors

For core maintainers:
1. The max-size and pad-pixels args can't be deleted due to many models on the hub still using it. Instead I decided to stop raising warning and silently load max size if present. However users cannot anymore use these args when calling the processor
2. For SDPA attention weights, the warning is reworded to push us to update those models. Usually if model has the new attention API, the warning is raised internally in `sdpa_attention`, but for old models we have to manually duplicate the waning message 

Comments:
> Therefore, until those implementations rely on ALL_ATTENTION_FUNCTIONS

Ah, after looking I see that it's not going to raise any warning unless we use  `ALL_ATTENTION_FUNCTIONS`.  In that case I think we can reword the warning that "Attention weights will not be returned" and remove the workaround. Users have been warned about SDPA so I think it will not be a big problem

Also it will nudge us to incorporate `ALL_ATTENTION_FUNCTIONS`. WDYT?

Yep, totally agree!

Hub down? 😢 

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

Oke, now it is done I think. @yonigozlan @eustlb if you want to take another look, I will also request core mantainer's review

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

run-slow: aimv2, altclip, beit, blip_2, bloom, bridgetower, clap, conditional_detr, data2vec, deepseek_v2, deformable_detr, detr, grounding_dino
[v5] Delete legacy chat template saving
Author: zucchini-nlp
Pull request: yes
Labels: name: for_v5?

# What does this PR do?

As per title

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_41648). 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
[v5] Delete `videos` from image processing classes 
Author: zucchini-nlp
Pull request: yes
Labels: name: for_v5?

# What does this PR do?

As per title, it was deprecated for v5

Comments:
> I assumed the removed files were fully redundant with the corresponding video processors?

Yeah, they are same in terms of functionality. But the deleted ones inherit from slow image processors while the video processor cannot be "slow". So the only diff is that we're making `torchvision` the only option 

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_41607). 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, glm4v, instructblipvideo, llava_next_video, qwen2_5_omni, qwen2_5_vl, qwen2_vl, qwen3_omni_moe, video_llama_3, video_llava

@Cyrilvallez do you have any comments to address?