noamaanMulla-03/transformers-issues huggingface dataset:
Fix Mac mps dataloader_num_workers > 1 causes RuntimeError: _share_filename_: only available on CPU
Author: AmitMY
Pull request: yes

# What does this PR do?

I have encountered an error during training on an M1 mac, similar to:
https://github.com/pytorch/pytorch/issues/87688

I have implemented the suggested fix, and it works.


## 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?

- trainer: @zach-huggingface, @SunMarc and @qgallouedec



Comments:
Confirming that this PR allows me to use `dataloader_num_workers=2` (or any number > 1) on my Mac M1 without hitting the `RuntimeError: _share_filename_: only available on CPU` mentioned in these bugs:
- https://github.com/huggingface/sentence-transformers/issues/3014
- https://github.com/pytorch/pytorch/issues/87688

Please review and merge when you get a chance!

- - -

For anyone who needs a workaround until this PR is merged, [this workaround](https://github.com/huggingface/sentence-transformers/issues/3014#issuecomment-2442024506) didn't work for me, but this did:
```py
from torch import multiprocessing
multiprocessing.set_start_method('fork', force=True) 
```

Just call it somewhere before you call `trainer.train()`.

- - -

@AmitMY thanks for creating this PR! To help get some attention from hf maintainers, since I see you opened this 5 months ago without any reviews yet, consider renaming it to something like `Fix Mac mps dataloader_num_workers > 1 causes RuntimeError: _share_filename_: only available on CPU` to emphasize that this is a bugfix and not just a random feature/change.

@bot /style 

Thanks a lot for the fast fix @AmitMY ! Will merge this asap

Style bot fixed some files and pushed the changes.

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

# What does this PR do?

Experts initalization was currently done in the general `_init_weights`, but it's cleaner to keep it in each separate models as only very few use it

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

run-slow: deepseek_v2, deepseek_v3, dots1, ernie4_5_moe, glm4_moe, glm4v_moe, hunyuan_v1_moe, jamba, lfm2_moe, longcat_flash, olmoe

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42306). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Update conversion mapping to separate renaming from converting
Author: ArthurZucker
Pull request: yes
Labels: name: Core: Modeling

name: for_v5?

Update the conversion: 
<img width="2324" height="1088" alt="image" src="https://github.com/user-attachments/assets/3db7f2fe-3b8f-466f-a616-19b65d58a9d2" />


<img width="1622" height="976" alt="image" src="https://github.com/user-attachments/assets/eb89ba28-f3f4-49eb-9145-a8c10352e895" />

to support torchao 
<img width="1740" height="1198" alt="image" src="https://github.com/user-attachments/assets/4c26d6bd-0e88-4a0b-900f-4cfaa936df6d" />


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

Taken from my first attempt at [NyxKrage/moondream3-preview-hf](https://huggingface.co/NyxKrage/moondream3-preview-hf), however it needed some changes to work properly with the latest transformers from git, and so the model with the proper config json files can be found at [NyxKrage/moondream3-preview-hf-git](https://huggingface.co/NyxKrage/moondream3-preview-hf-git), though the weights stay the same.

[Moondream3](moondream/moondream3-preview) modeling code ported over to follow more proper HuggingFace conventions, code is mostly functional, though there are currently some pretty glaring issues.  

1. The whole loop to decode points/regions in the forward pass is obviously not something that should be stay, but I wanted to get the functionality in correctly, so that the flow of how points/bounding boxes are calculated are there as a reference point at least.  
2. The code as is currently does not work without caching being enabled (due to simply running the image embeds through the model separately and relying on the kv cache to "store them").  
3. Batching with differently sized images does not work, batching with different objectives (query/point/detect) does not work.  
4. I was pretty unsure in general on how to properly handle the processor, should it prepend some bogus token to make space for the image embeddings (even though the tokenizer used does not have a dedicated image placeholder token).  

Opening this as a draft PR to get some initial feedback on the proper way to handle a most of these as I'm generally unfamiliar with the specifics in terms of how image models should be implemented.  
Also the code has the full modeling code rather than using the modular setup for now, because I felt that it would be easier to "fix" the issues, and then identify which parts can be modularized afterwards.  

For point 1, from what I couldn't tell if the proper way would be to override the generate method and handle it there, or just have the model handle generation and let the end user worry about the point/bounding box functionality?  
For point 2, I think the main pain point, comes from the fact that I ended up handling the image embeddings and shifting around stuff in the modeling code, rather than adding padding for the space the image embeddings should take up in full input embeddings in the processor, but I ended up going for this way just because I was unsure what the correct approach was with the lack of an image token, and so if point 4 gets solved by moving that to the processor, this should come for free I believe.  
For point 3, the batching of differently sized images, should just require a bit of tweaking in the reconstruction path for the image projection to handle padding the number of crops, and for the query/point problem, that should hopefully be fixed by the way of solving point 1.  

Comments:
cc @zucchini-nlp for VLMs!
[SAM3 Video] Add support for multi prompts 
Author: yonigozlan
Pull request: yes

# What does this PR do?
Also fixes checkpoints in tests

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42293). 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: sam3, sam3_tracker, sam3_tracker_video, sam3_video

Thanks @molbap for the review! I made the changes that you suggested that are not too involved, and noted all the ones that are more involved for the post-release cleanup ;)
Add Pix2Struct fast image processor
Author: yonigozlan
Pull request: yes

# What does this PR do?
+ other improvements (docs for implementing fast image processors)


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

run-slow: auto, pix2struct

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

# What does this PR do?

Fixes https://github.com/huggingface/transformers/issues/42005.
Also fixes post processing functions in superglue and lightglue fast image processors, which were wrongly taken from efficientloftr

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

run-slow: efficientloftr, lightglue, superglue

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42018). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
ValueError: You current version of `autoawq` does not support module quantization skipping, please upgrade `autoawq` package to at least 0.1.8.
Author: EIIvy
Pull request: no

when I run, 
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
    "Qwen/Qwen2.5-VL-72B-Instruct-AWQ",
    torch_dtype=torch.float16,
    device_map="auto",
)
processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-72B-Instruct-AWQ")

I got this error, my package version:
torch==2.5.1
transformers==4.50.0


Comments:
when I pip install --upgrade autoawq
I meet this error:
ModuleNotFoundError: No module named 'transformers.models.qwen3'

@EIIvy `AutoAWQ` has been put into `archive` mode by maintainer meaning it will no longer get compat and bug fixes for upcoming model and transformat releases. Please switch to [GPT-QModel](https://github.com/modelcloud/gptqmoel) `main` branch for `awq` loading and try loading your model via our `gptqmodel.load()` api which calls `transformers` and is compatible with more model support and better transformer compat. 

Also, I will likely submit a Transformer PR to route autoawq calls and depend to gpt-qmodel soon. 



> [@EIIvy](https://github.com/EIIvy) `AutoAWQ` has been put into `archive` mode by maintainer meaning it will no longer get compat and bug fixes for upcoming model and transformat releases. Please switch to [GPT-QModel](https://github.com/modelcloud/gptqmoel) `main` branch for `awq` loading and try loading your model via our `gptqmodel.load()` api which calls `transformers` and is compatible with more model support and better transformer compat.
> 
> Also, I will likely submit a Transformer PR to route autoawq calls and depend to gpt-qmodel soon.

Do you have any resources on comparison between the two quantizations? I have been using both and interested to know why the community have decided to deprecate one.

> I have been using both and interested to know why the community have decided to deprecate one.

AWQ is not deprecated. AutoAWQ is a library that implements and appplies AWQ and the library was deprecated. GPT-QModel will most likely takeover awq handling via transfomer hooks. Right now our awq feature is `beta` quality only. Just use the one that applies best to your project. I prefer gptq but that's just me. 


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.
fix lerobot openpi
Author: Hukongtao
Pull request: yes

# What does this PR do?

https://github.com/huggingface/lerobot/issues/2372

## 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 @Cyrilvallez
- vision models: @yonigozlan @molbap
- audio models: @eustlb @ebezzam @vasqu
- multimodal models: @zucchini-nlp
- graph models: @clefourrier

Library:

- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- continuous batching: @remi-or @ArthurZucker @McPatate
- pipelines: @Rocketknight1
- tokenizers: @ArthurZucker and @itazap
- trainer: @SunMarc
- attention: @vasqu @ArthurZucker @CyrilVallez
- model loading (from pretrained, etc): @CyrilVallez
- distributed: @3outeille @ArthurZucker
- CIs: @ydshieh

Integrations:

- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization: @SunMarc @MekkCyber
- kernels: @MekkCyber @drbh
- peft: @BenjaminBossan @githubnemo

Devices/Backends:

- AMD ROCm: @ivarflakstad
- Intel XPU: @IlyasMoutawwakil
- Ascend NPU: @ivarflakstad 

Documentation: @stevhliu

Research projects are not maintained and should be taken as is.

 -->


Comments:
`find_adapter_config_file()` got an unexpected keyword argument `_adapter_model_path`
Author: avihu111
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.57.0.dev0
- Platform: Linux-5.14.0-503.23.1.el9_5.x86_64-x86_64-with-glibc2.34
- Python version: 3.10.15
- Huggingface_hub version: 1.0.0.rc5
- Safetensors version: 0.4.5
- Accelerate version: 1.10.1
- Accelerate config:    not found
- DeepSpeed version: 0.17.5
- PyTorch version (accelerator?): 2.7.1+cu126 (CUDA)
- Using distributed or parallel set-up in script?: No
- Using GPU in script?: Yes
- GPU type: NVIDIA H100 80GB HBM3

### Who can help?

Hey @Cyrilvallez @ArthurZucker and @Rocketknight1 

I tried loading Granite Speech 2B (a model with a LoRA adapter) with an updated transformers version (4.57.0.dev0). using the following code, which works in previous versions:
```
import torch
from transformers import AutoModelForSpeechSeq2Seq
model_name = "ibm-granite/granite-speech-3.3-2b"
model = AutoModelForSpeechSeq2Seq.from_pretrained(
    model_name, device_map="cuda", torch_dtype=torch.bfloat16
)
```
and got the following error:
```
    model = AutoModelForSpeechSeq2Seq.from_pretrained(
  File "/proj/speech/home/avihu/git_repos/10sep/transformers/src/transformers/models/auto/auto_factory.py", line 385, in from_pretrained
    return model_class.from_pretrained(
  File "/proj/speech/home/avihu/git_repos/10sep/transformers/src/transformers/modeling_utils.py", line 270, in _wrapper
    return func(*args, **kwargs)
  File "/proj/speech/home/avihu/git_repos/10sep/transformers/src/transformers/modeling_utils.py", line 4549, in from_pretrained
    model.load_adapter(
  File "/proj/speech/home/avihu/git_repos/10sep/transformers/src/transformers/integrations/peft.py", line 221, in load_adapter
    adapter_config_file = find_adapter_config_file(
TypeError: find_adapter_config_file() got an unexpected keyword argument '_adapter_model_path'
```

looks like `_adapter_model_path` is inserted [here](https://github.com/huggingface/transformers/blob/4e50b8459d981ddcbc9438e85cff8d83fe40a500/src/transformers/models/auto/auto_factory.py#L302C23-L302C24)



### Information

- [x] 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

```
import torch
from transformers import AutoModelForSpeechSeq2Seq
model_name = "ibm-granite/granite-speech-3.3-2b"
model = AutoModelForSpeechSeq2Seq.from_pretrained(
    model_name, device_map="cuda", torch_dtype=torch.bfloat16
)
```


### Expected behavior

Return the model without crashing

Comments:
CC: @gsaon 

See #41604.

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.
Fix typo from side_dict to size_dict
Author: nihui
Pull request: yes

# What does this PR do?
fix typo


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

run-slow: siglip2

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

# What does this PR do?

As per the title. We need to sort first by modules, then length otherwise we may not detect the correct device. 
I first wanted to add it in https://github.com/huggingface/transformers/pull/42242, but upstreaming in the meantime as this is an important one (otherwise, param do not follow the device_map, leading to OOMs everywhere potentially etc)

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42323). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Fix: make dataset_index optional for ViTPose+ MoE models
Author: rukundob451
Pull request: yes

## What does this PR do?
Fixes #42222 by making `dataset_index` optional for ViTPose+ models with MoE architecture.

## Changes
- Provide default `dataset_index = 0` (COCO dataset expert) when not specified
- Add batch size validation for explicit `dataset_index` values  
- Maintain full backward compatibility

## Testing
- ✅ Forward pass without dataset_index now works
- ✅ Forward pass with explicit dataset_index still works
- ✅ Batch processing works correctly
- ✅ All existing functionality preserved

## Notes
This allows users to use ViTPose+ models without needing to specify which expert to use, defaulting to the COCO dataset expert for convenience.

Fixes: #42222

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

run-slow: vitpose_backbone
Fix gpt2 modeling tests
Author: Abdennacer-Badaoui
Pull request: yes

Fixing gpt2 modeling tests : 

1. `test_batch_generation` & `test_batch_generation_2heads`:
Changed model.config.max_length → model.generation_config.max_length (GPT2Config doesn't have max_length)
2. `test_model_parallelism`:
Added `model_split_percents = [0.5, 0.6, 0.7]` to force model splitting across GPUs (default `[0.5,0.7, 0.9]` was too large). The model doesn’t split starting from 0.8.
3. `test_flash_attn_2_generate_padding_left`:
Updated expected output to match actual generation result


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

run-slow: gpt2

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

models: ["models/gpt2"]
quantizations: []

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

✅ No failing test specific to this PR 🎉 !


Thanks for the PR, there is one multi-gpu test failing but it was also failing before. Now we have less red :D
Allow LayoutLMV3Processor to accept rescale_factor
Author: Rocketknight1
Pull request: yes

`test_image_processor_defaults_preserved_by_image_kwargs` is flaky for models that use the `LayoutLMV3Processor`, which causes annoying intermittent CI failures, especially for `UDOP`. The cause is that `LayoutLMV3Processor` expects `rescale_value`, not the standard `rescale_factor`, but the test depends on `rescale_factor` being accepted. This PR allows `LayoutLMV3Processor` to accept `rescale_factor`, but I'm not sure if this is the optimal solution. cc @molbap @yonigozlan @zucchini-nlp 

Note that no other models use `rescale_value` - it's just LayoutLMV3! I suspect this issue was also the cause of several other flaky tests in `test_processing_common`

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

run-slow: layoutlmv3, udop

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

models: ["models/layoutlmv3", "models/udop"]
quantizations: []

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

✅ No failing test specific to this PR 🎉 !


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

run-slow: layoutlmv3
Add Evo2 Genomic foundation model
Author: McClain-Thiel
Pull request: no
Labels: name: New model

### Model description

[Evo2](https://github.com/ArcInstitute/evo2) is a Decoder only StripedHyena2-based causal LM that models DNA in the same fashion frontier models are based on pretrained only models. Huggingface has similar models available but Evo2 is state of the are on long range dependency modeling and down stream variant prediction.

Evo2 in huggingface would allow Bio x ML folks to experiment with  many down stream tasks such as variant prediction, cancer modeling, genomic design and more. 

Evo2 uses a DNA base pair tokenizer. 

### Open source status

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

### Provide useful links for the implementation

@ArcInstite originally implemented a non HF compatible version here: https://github.com/ArcInstitute/evo2

Comments:
Hi @McClain-Thiel, definitely interested! Linking the PR at #42210 as well

- [ ] Adding Evo2 to transformers would be valuable for the computational biology and bioinformatics community. Genomic foundation models are a growing field and having HF-native support would lower barriers for researchers.

**Integration Considerations:**
- The DNA base pair tokenizer is unique compared to standard BPE/WordPiece tokenizers - ensure proper tokenizer abstraction
- Long-range dependency modeling (Evo2 handles long genomic sequences) may require special attention to memory optimization
- Document genomic-specific use cases (variant prediction, cancer modeling, genomic design) to help bio researchers discover the model

**Community Impact:**
This would bridge the ML and bio communities, similar to how ESM models for protein sequences gained traction through HF. The implementation would set a template for future genomic models.

If this issue is still open, I would like to work on it. I gave a read about Evo2 model and feels like it could be interesting to implement 

Hi @KarthikSundar2002, there's already a PR open at #42210!