noamaanMulla-03/transformers-issues huggingface dataset:
[modular] Follow global indexing and attribute setting, and their dependencies
Author: Cyrilvallez
Pull request: yes

# What does this PR do?

As per the title. See the new example to better understand the issue at hand. Before, any global indexing or attribute setting to a global variable would not be followed, because they are not a "simple and standard" variable assignment. This PR solves it.

This is needed in https://github.com/huggingface/transformers/pull/35891 as well


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_39180). 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 Gemma3n notes
Author: davanstrien
Pull request: yes

# What does this PR do?

Fixes # (issue)

fix typo in Gemma3n notes

## Before submitting
- [x] 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.

<!-- 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
- vision models: @amyeroberts, @qubvel
- speech models: @eustlb
- graph models: @clefourrier

Library:

- flax: @gante and @Rocketknight1
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Rocketknight1
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @zach-huggingface, @SunMarc and @qgallouedec
- chat templates: @Rocketknight1

Integrations:

- deepspeed: HF Trainer/Accelerate: @SunMarc @zach-huggingface
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc @MekkCyber

Documentation: @stevhliu

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @Rocketknight1
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


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

Thanks
Don't send new comment if the previous one is less than 30 minutes (unless the content is changed)
Author: ydshieh
Pull request: yes

# What does this PR do?

https://github.com/huggingface/transformers/pull/39100#issuecomment-3026536511

In #39100, the previous comment is deleted and a new one is sent. But without users refreshing the PR page, the previous comment still remains on the page (until page refresh) which seems annoying.



Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_39170). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Make _compute_dynamic_ntk_parameters exportable
Author: xadupre
Pull request: yes
Labels: name: ExecuTorch

# What does this PR do?

Function ``def _compute_dynamic_ntk_parameters`` is not exportable (with torch.export.export) due to a control flow, this PR rewrites it with torch.maximum.

Fixes # (issue)


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] 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.

<!-- 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
- vision models: @amyeroberts, @qubvel
- speech models: @eustlb
- graph models: @clefourrier

Library:

- flax: @gante and @Rocketknight1
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Rocketknight1
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @zach-huggingface, @SunMarc and @qgallouedec
- chat templates: @Rocketknight1

Integrations:

- deepspeed: HF Trainer/Accelerate: @SunMarc @zach-huggingface
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc @MekkCyber

Documentation: @stevhliu

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @Rocketknight1
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


Comments:
[modular] Simplify logic and docstring handling
Author: Cyrilvallez
Pull request: yes

# What does this PR do?

Simplify a lot `replace_class_node` logic (I wanted to do it from a long time ago as it was all bloated and super hard to read) and simplify the docstring handling at the same time.

Basically, the idea is now to use the parent docstring if there are no docstrings, or to use the docstring in modular if any. Previously, we were doing some kind of merging between the 2 docstrings, which was bugged (see a few places in the diff where there are arg explanations after examples or similar issues), inconsistent (i.e. adding a simple arg for a Config, while convenient, was always inconsistent because the checkpoints link was never updated correctly) and surprising (this is some kind of magic that contributors were very rarely understanding (which makes sense at it had a lot of issues as explained). Moreover, with `auto_docstring` now, we should not have to redefine the parameters explanations everytime, so it makes sense to relax docstring handling.


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_39185). 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: d_fine, diffllama, dinov2_with_registers, emu3, falcon_h1, gemma, gemma2, gemma3, gemma3n, glm4v, helium, instructblipvideo, internvl, mlcd, sam_hq, smolvlm
[masking] fix Aggressive boolean conversion breaking packing implementations
Author: kashif
Pull request: yes

# What does this PR do?

Fix Aggressive boolean conversion in the masking_utils that is breaking packing implementation


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] 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.

<!-- 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
- vision models: @amyeroberts, @qubvel
- speech models: @eustlb
- graph models: @clefourrier

Library:

- flax: @gante and @Rocketknight1
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Rocketknight1
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @zach-huggingface, @SunMarc and @qgallouedec
- chat templates: @Rocketknight1

Integrations:

- deepspeed: HF Trainer/Accelerate: @SunMarc @zach-huggingface
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc @MekkCyber

Documentation: @stevhliu

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @Rocketknight1
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


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

Superseded by https://github.com/huggingface/transformers/pull/39194! Closing!
fix `fastspeech2_conformer` tests
Author: ydshieh
Pull request: yes

# What does this PR do?

The 2 tests are failing for long time. I also need to update one expected output values

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

>  self-contained reproducer for the integration tests expected outputs

May I know why such reproducer script is preferred over the test itself?

run-slow: fastspeech2_conformer

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

run-slow: fastspeech2_conformer

run-slow: fastspeech2_conformer

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

models: ['models/fastspeech2_conformer']
quantizations: [] ...

Merge (the failing slow CI is only multi-gpu related)
RotaryEmbeddings change `is not None` -> `isinstance(..., dict)`
Author: qubvel
Pull request: yes

# What does this PR do?

Small quality improvement of if/else statement for RotaryEmbeddings, motivated by static typechecking

The behaviour has slightly changed in case `rope_scaling` has an unexpected type:

| **Condition**                              | **Before (Previous Behavior)**                                      | **After (Updated Behavior)**           |
|-------------------------------------------|-----------------------------------------------------|----------------------------------------|
| `rope_scaling` is a `dict`                | `rope_type` retrieved from dict                |`rope_type` retrieved from dict        |
| `rope_scaling` is `None`                  | `rope_type = "default"`                                             | `rope_type = "default"`                |
| `rope_scaling` is an unexpected type      | Raises `AttributeError: '<type>'`<br>`object has no attribute 'get'`     | `rope_type = "default"`                |

cc @gante 


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

# What does this PR do?

Since it's for a patch there should not be a -1

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_39216). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Standardize FSMT class naming: PretrainedFSMTModel → PreTrainedFSMTModel
Author: VXXXO
Pull request: yes

This PR addresses the naming inconsistency for the FSMT base model class, as described in issue #39202.

### Changes
Renamed PretrainedFSMTModel to PreTrainedFSMTModel to match the naming convention used across the library (e.g., PreTrainedModel, PreTrainedTokenizer)
Updated all usages and exports accordingly
Added a comment to the class definition for clarity

### Testing
✅ All imports work correctly
✅ Python syntax is valid
✅ No breaking changes to functionality
✅ All FSMT classes import successfully

This change improves code consistency and readability without affecting functionality.

Fixes: #39202

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

run-slow: fsmt
Update tiny-agents example
Author: Wauplin
Pull request: yes

Fix docs example after https://github.com/huggingface/huggingface_hub/pull/3166 / https://github.com/huggingface/huggingface.js/pull/1556. Since release [0.33.2](https://github.com/huggingface/huggingface_hub/releases/tag/v0.33.2) `tiny-agents` config follow VSCode format. We made the change without a proper deprecation warning as it's still experimental and we wanted to harmonize with VSCode as quickly as possible (to avoid future conflicts).  

Related PRs:
- https://github.com/huggingface/hub-docs/pull/1816
- https://github.com/huggingface/transformers/pull/39245
- https://github.com/huggingface/huggingface_hub/pull/3205
- https://github.com/huggingface/huggingface.js/pull/1599

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_39245). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Add mobilenet_v5 stub implementation to fix "Unknown Model" error
Author: VXXXO
Pull request: yes

# What does this PR do?

This PR addresses issue #39208: "Unknown Model (mobilenetv5_300m_enc) when loading Gemma 3n".

## Problem
When loading Gemma 3n models, the default vision architecture is set to "mobilenetv5_300m_enc", but this architecture was not implemented in Transformers, causing an "Unknown Model" error that prevents users from using Gemma 3n.

## Solution
- Added minimal mobilenet_v5 implementation with proper structure:
  - `MobileNetV5Config` - configuration class with standard parameters
  - `MobileNetV5Model` - stub model implementation (inherits from PreTrainedModel)
  - `MobileNetV5ImageProcessor` - stub image processor
- Registered mobilenet_v5 in all auto classes (AutoConfig, AutoModel, AutoImageProcessor)
- Used lazy loading to avoid circular dependencies
- Added proper docstrings and warnings about stub nature

## Benefits
- Eliminates "Unknown Model" error when loading Gemma 3n
- Provides foundation for future full implementation of mobilenet_v5
- Maintains backward compatibility
- Follows Transformers architecture standards

## Testing
- Verified that AutoConfig.for_model('mobilenet_v5') works
- Verified that AutoModel.from_config works for mobilenet_v5
- Verified that Gemma3nVisionConfig with architecture='mobilenetv5_300m_enc' works
- All components compile without syntax errors

**Note:** This is a stub implementation that prevents crashes. Full implementation of mobilenet_v5 architecture is left for future contributions.

Fixes #39208

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

run-slow: auto, fsmt

cc @qubvel !

Hey @VXXXO, thanks for your contribution, but we just need a check for the `timm` version for gemma3n, it would be much simpler. I mean transformers need `timm >= 1.0.16` to instantiate gemma3n with mobilenetv5 vision encoder
Remove the redundant shift during the loss computation in the Moshi m…
Author: glynpu
Pull request: yes

# What does this PR do?

Correct the loss computation process in the Moshi model to apply the shift only once, as it is currently being applied twice.

Because the class name **MoshiForCausalLM** contains '**ForCausalLM**', according to the mapping rules in **LOSS_MAPPING**, the **self.loss_function** used in the forward function of **MoshiForCausalLM** should be **ForCausalLMLoss**. As a result, logits and labels are shifted **twice**: once before calling self.loss_function and once inside self.loss_function. This leads to **tokens < n - 1 predicting n** instead of the expected behavior where **tokens < n predict n**.

This PR removes the shift before the self.loss_function call.

**References:**
**LOSS_MAPPING**:
https://github.com/huggingface/transformers/blob/9e125d9a2e696967b4d401dbfea24a4d40058017/src/transformers/loss/loss_utils.py#L130-L135

ForCausalLMLoss:
https://github.com/huggingface/transformers/blob/9e125d9a2e696967b4d401dbfea24a4d40058017/src/transformers/loss/loss_utils.py#L33-L57



Comments:
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. When it is ready for review, please click the `Ready for review` button (at the bottom of the PR page).

cc @eustlb!

Hey @glynpu, thank you so much for your patience. 
I am allocating time this week to a bug fixing sprint on Moshi, I'll review this PR at the same time 🤗
1/2 Last step cleaning the `LlamaModel` codebase
Author: ArthurZucker
Pull request: yes

# What does this PR do?
Output attention and hidden states logic can be reduced to basically attaching hooks to the `GradientCheckpointing` layer. 

Refactored `can_return_tuple` as it can be much simpler :) only top level will receive `False`

This makes the code simpler and cleaner! 

Comments:
Just want to trigger the tests!

Hey @ArthurZucker, great work 🚀 🚀 🚀 

I also started working on removing `return_dict` from the models in this PR
 - https://github.com/huggingface/transformers/pull/38991

while Lysandre shared your PR, so I'm curious if you going to include all the changes in this PR? I think it might be too huge to apply all at once, WDYT?

I was also previously looking into removing `output_attention` and `output_hidden_states` and had similar idea of utilizing hooks. For intermediate `hidden_states`, however, it might be harder to apply because it not that consistent across the repo. For example, in some cases we collect the last `hidden_state` after the norm layer, but there might be no final layer_norm (as in bart or vit) or an additional layer(s) (as in opt). It might be tricky to manage all the cases, and it feels like we should strongly maintain backward compatibility for `output_hidden_states` because some models are built on these intermediate features. I'm just curious if you have any ideas in mind. Maybe we can have some patterns for the layer to apply hooks to or keep the intermediate hidden_states collection as is and remove just `output_attentions`. Anyway, I would be happy to help 🤗

Hey @qubvel the hooks are gonna be attached to the layer class, and we will register explicitly which layers are expected to return what! This way we can deal with any cases!

It is easier for me to change return dict as well TBH! 


#39120 did it!
Fix to tuple conversion with config
Author: qubvel
Pull request: yes

# What does this PR do?

setting `return_dict=False` with config fails for models with sub-models wrapped with `can_return_tuple` or `check_model_inputs` 

```py
import torch
from transformers import LlamaConfig, LlamaForCausalLM

config = LlamaConfig(vocab_size=256, hidden_size=128, num_hidden_layers=2, num_attention_heads=4, intermediate_size=256)
model = LlamaForCausalLM(config)

# default: ModelOutput
input_ids = torch.tensor([[0, 1, 2, 3]])
with torch.no_grad():
    output = model(input_ids)

print(output)


# passing return_dict=False as a kwarg 
input_ids = torch.tensor([[0, 1, 2, 3]])
with torch.no_grad():
    output = model(input_ids, return_dict=False)

print(output)


# ERROR: setting return_dict=False in the config
model.config.return_dict = False
with torch.no_grad():
    output = model(input_ids)

print(output)

# Traceback (most recent call last):
#   File "/home/ubuntu/projects/transformers/test_llama_small.py", line 17, in <module>
#     output = model(input_ids)
#   File "/home/ubuntu/projects/transformers/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
#     return self._call_impl(*args, **kwargs)
#   File "/home/ubuntu/projects/transformers/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
#     return forward_call(*args, **kwargs)
#   File "/home/ubuntu/projects/transformers/src/transformers/utils/generic.py", line 962, in wrapper
#     output = func(self, *args, **kwargs)
#   File "/home/ubuntu/projects/transformers/src/transformers/models/llama/modeling_llama.py", line 506, in forward
#     hidden_states = outputs.last_hidden_state
# AttributeError: 'tuple' object has no attribute 'last_hidden_state'
```


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_39257). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Improve RoBERTa documentation with explanations and helpful links
Author: PrakyathMC
Pull request: yes

## What does this PR do?

Improves the RoBERTa model documentation following the standardized format outlined in #36979.

## Changes Made
- ✅ Added explanatory comments to Pipeline and AutoModel code examples
- ✅ Added "Quick Links" section with popular RoBERTa models on HuggingFace Hub  
- ✅ Included additional resources (paper links, model collection)
- ✅ Improved accessibility for beginners learning to use RoBERTa

## Before and After
**Before**: Basic code examples without explanations
**After**: Commented code that teaches users what each line does + easy access to models

#36979

Comments:
Hi, RoBERTa was already updated in #38777. Please feel free to choose another model!