noamaanMulla-03/transformers-issues huggingface dataset:
Fix DocQA max_answer_len validation error message
Author: antznette1
Pull request: yes

Summary
This PR fixes a small typo in DocumentQuestionAnsweringPipeline._sanitize_parameters() where the ValueError raised for invalid max_answer_len was missing a closing parenthesis in the "(got ...)" portion of the message.

Changes
- Fix malformed ValueError message for max_answer_len validation in:
  - src/transformers/pipelines/document_question_answering.py
- Add a lightweight regression test (no model downloads) that asserts the error message is well-formed:
  - tests/pipelines/test_pipelines_document_question_answering.py

Testing
- python -m pytest tests/pipelines/test_pipelines_document_question_answering.py -k sanitize_parameters_max_answer_len_error_message -q

Comments:
Thanks for the typo fix, but I don't think we need a test for that! :sweat_smile: Can you revert the test and just keep the typo fix?

Also if possible can you roll #42949 into this one, since they're the same issue?

> Also if possible can you roll #42949 into this one, since they're the same issue?

Okay, I'll implement that immediately

Done, I removed the tests from this PR and kept only the typo fixes.
 
I also rolled the corresponding QA typo fix from #42949 into this PR, so everything is consolidated here. I have closed #42949.

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42948). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
QwenVL: add skipped keys in `setattr` as well
Author: zucchini-nlp
Pull request: yes
Labels: name: for patch

# What does this PR do?

As per title, getattr and setattr skip different set of keys now 


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

run-slow: qwen2_5_vl, qwen2_vl

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

# What does this PR do?

Seems that the TP/dist integ refactor broke a method to count bytes, which is in from_pretrained. cc @3outeille as well if needed (I'm setting a 1 world size by default without initializing dist :shrug: )

Comments:
Referencing https://github.com/huggingface/transformers/pull/43003 and https://github.com/huggingface/transformers/pull/42809 for reference

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_43008). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Small fixes for `make fixup` to run without error
Author: ebezzam
Pull request: yes

# What does this PR do?

Small changes so that `make fixup` runs without error


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_43002). 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: siglip, siglip2
Fix: Handle missing safetensors gracefully to prevent import errors
Author: Pranavi125
Pull request: yes

This PR adds a safeguard for environments where `safetensors` is not installed.
It prevents import errors during dependency checks and allows transformers to load normally.

Changes made:
- Updated `setup.py` to conditionally check for safetensors
- Improved dependency handling logic

Tested locally: verified that transformers imports correctly with and without safetensors.


Comments:
Hi, this PR addresses the dependency handling for safetensors.
It ensures that transformers installs and runs correctly even when safetensors isn’t present.
I’ve verified imports and functionality both with and without the package installed.

Please review when possible — happy to make any adjustments if needed.

Thanks for the PR, but `safetensors` is a pretty hard dependency for `transformers` at this point - I don't think we want alternate code paths where it isn't available!
Fix: add missing SAFE_WEIGHTS_INDEX_NAME to __all__ in constants.py
Author: Pranavi125
Pull request: yes

This PR adds the missing SAFE_WEIGHTS_INDEX_NAME constant to the __all__ list in constants.py.

Why:
Without this, the constant isn’t exported when using
from transformers.utils.constants import *.

Impact:
- Keeps the constants module consistent.
- No functional changes or breaking impact.

Comments:
Do not use accelerate hooks if the device_map has only 1 device
Author: Cyrilvallez
Pull request: yes

# What does this PR do?

As per the title. In case of a single device, it's much easier and safer to simply move everything to the correct device, rather than to add hooks so that non-persistent buffers etc can be correctly used

From my benchmarks, this ends up being more efficient at forward-time, as expected (not crazy acceleration, but it's free anyway)

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_43019). 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=43019&sha=a8e1cd
Fix audio pipelines
Author: zucchini-nlp
Pull request: yes

# What does this PR do?

Attribute `_processor_class` was deleted from subprocessors but there are still places where we try to access it. This PR deletes  `_processor_class` everywhere and fixes failing audio pipeline tests

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

As commented in Slack, I would support merging this with my suggestion (and iterating later, if we need to) because it fixes the ASR pipelines in `main` and allows #42823 to proceed.

cc @eustlb too.

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

run-slow: wav2vec2_bert

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=42920&sha=30548c
[Model] Support Deepseek-V3.2-Exp
Author: hnyls2002
Pull request: no
Labels: name: Feature request

### Feature request

At least support the config, which can be found in https://huggingface.co/deepseek-ai/DeepSeek-V3.2-Exp/blob/main/config.json

### Motivation

So we can natively use the model config from HF to deploy DeepSeek-V3.2 in SGLang without a hacky patch.

### Your contribution

Only support the config class in #41197 

Comments:
cc @arthurzucker for text models

#41251 incoming!

Hi @ArthurZucker , may I ask how is the work going on now? Thanks!

Hi @ArthurZucker , may I ask how is the work going on now? Thanks!

Oupsy we had the rush for v5, I am hoping to pick this up next week everyone, really sorry

@ArthurZucker  hello， Any progress?
GLM-ASR  Support
Author: zRzRzRzRzRzRzR
Pull request: yes

Adapting GLM-ASR-Nano-2512 for the new version of transformers

Comments:
cc @eustlb @ebezzam for vis

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_42875). 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: audioflamingo3, auto, glmasr

🚨 Exceptionally merging without a core maintainer’s review, as discussed offline with @ArthurZucker (this is basically the same as Voxtral/AudioFlamingo3, with nothing fundamentally new introduced here)
Perf: Enable pin_memory in DataLoader for no_trainer examples
Author: RinZ27
Pull request: yes

### What does this PR do?

This PR enables `pin_memory=True` when initializing `DataLoader` in `examples/pytorch/language-modeling/run_clm_no_trainer.py`.

### Why is this change important?

Currently, the data loaders in this example manually collate tensors but miss the `pin_memory` flag. According to PyTorch best practices, enabling pinned memory significantly speeds up the host-to-device transfer (CPU to GPU), especially for larger datasets.

This is a low-risk optimization that helps utilize GPU resources more efficiently during training loops in these standalone examples.

### Checklist
- [x] Confirmed the change aligns with PyTorch documentation regarding data loading performance.


Comments:
Can we disable IPython progress bar and use normal tqdm bar?
Author: weathon
Pull request: no

I like the normal tqdm bar much better, it is lighter, cleaner, simpler, and less stress on my eyes (no green color). I would love to have an option to use tqdm bar and not IPython bar. 

Comments:
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.
Clarification needed: patch for CVE-2025-3777 (improper URL validation in image_utils.py)
Author: Archana-Shinde1
Pull request: no

The advisory for CVE-2025-3777 states that versions up to 4.49.0 of Transformers are affected by an “improper input validation vulnerability in image_utils.py file. The vulnerability arises from insecure URL validation using the startswith() method, which can be bypassed through URL username injection.” 

**Fixed version:** 4.52.1 according to the advisory. 

**Commit referenced:** 
https://github.com/huggingface/transformers/commit/4dda5f71b35fb70cf602187eef84bb17a50b9082

**Issue:**
We were reviewing the changes in that commit and are uncertain exactly which lines and logic changes in [src/transformers/image_utils.py](https://github.com/huggingface/transformers/blame/v4.52.1/src/transformers/image_utils.py) (or other related files) correspond to the fix for this CVE. The commit is large, touches many files, but the diff shown for image_utils.py appears 

```
- PILImageResampling.NEAREST: InterpolationMode.NEAREST,
+ PILImageResampling.NEAREST: InterpolationMode.NEAREST_EXACT,
```


This appears unrelated to URL validation.

Could you please clarify:

1. Which file(s) and which lines implement the tighter URL validation to prevent the startswith() bypass?
3. For users still on v4.38.0, what minimal backport or patch should be applied to mitigate the vulnerability?

Comments:
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.
`num_query_tokens` of blip2 might be None
Author: HYLcool
Pull request: no
Labels: name: bug

### System Info

transformers>=4.55.0

### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [x] 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

Hi, the code below did not check if the `self.num_query_tokens` is None, but in the `__init__` method, the default value for this variable is None, which might cause error like:
```
TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'
```

https://github.com/huggingface/transformers/blob/6f6095e0cf509f7384d3ce0c1804013ef6cafd5f/src/transformers/models/blip_2/processing_blip_2.py#L109-L110

I tried kpyu/video-blip-opt-2.7b-ego4d in transformers>=4.55.0 and it failed.

### Expected behavior

The model can be successfully used.

Comments:
hey @HYLcool, can you paste the code you ran that crashed, and the error you saw?

@HYLcool the `num_query_tokens` is a required argument, so I think we should remove the default `None`. That way people can see clearly if any inputs are missing from config

Might be that the crashing code uses an out-dated config file?

```python
import torch
from transformers import AutoProcessor, AutoModelForVision2Seq
model_id = "kpyu/video-blip-opt-2.7b-ego4d"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForVision2Seq.from_pretrained(model_id)
print("num_query_tokens =", getattr(processor, "num_query_tokens", None))
random_pix = torch.randn(1, 3, 224, 224)
try:
    out = model.generate(
        pixel_values=random_pix,
        max_length=20
    )
except Exception as e:
    print("Caught error:")
    raise
```

<img width="1371" height="281" alt="Image" src="https://github.com/user-attachments/assets/93056b4f-d9c1-4b47-be2e-7f9b7f2f3012" />

The above code reproduces the stated error. I've also raised a small PR proposing a fix, please let me know what else needs to be done here.

Thanks for your responses and fixing. I believe it will be OK after the PR is merged. 🎉

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.
Move missing weights and non-persistent buffers to correct device earlier
Author: Cyrilvallez
Pull request: yes

# What does this PR do?

As per the title. Better to send everthing directly to the correct device, rather than cpu, then initialize, then move to device

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_43021). 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=43021&sha=a75715
v4.41.2 default_data_collator import torch bug
Author: AdrianMoen
Pull request: no
Labels: name: bug

### System Info

Transformers v4.41.2
Python v3.11.9
Linux (wsl2)

Discovered when finetuning phi3-mini-128k-instruct and doing custom masking of the dataset

There seems to be a hanging debug check in the default_data_collator method that is not present in the v4.41-release branch code, where it has been removed.
This debug check uses the torch module, but it is not imported at that point during runtime.

Nevertheless its present in at least v4.41.2

Couldn't find the source code for v4.41.2 specifically so creating this issue instead

### Who can help?

@Rocketknight1 
@sgugger 
@sdwalker62 
@aromans

### Information

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

### Tasks

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

### Reproduction

1. Setup a finetuning environment, with arbitrary training data
2. Create labels with masking
3. The batch should then include "labels" as a key, and it should have one or more values
4. use the default_data_collator from transformers library
5. you should get a NameError: name 'torch' is not defined

### Expected behavior

The debug check should be removed as it does not influence the outcome at all, as we can see in the official v4.41-release branch

Source of bug found at line 93 to 106 in transformers/data/data_collator.py under the default_data_collator method

Comments:
Hi @AdrianMoen, v4.41 is quite old at this point! Have you checked with the most recent version?

Hello @Rocketknight1, thanks for your response.
When Dealing with finetuning phi3-mini, v4.41.2 is listed as the recommended transformers version, and i found other versions troublesome to do finetuning with.
In my setup i simply removed the debug lines, and all was well.
I could not find a way to create a pull request for v4.41.2 specifically (v.41.x branch code does not have the debug lines) so i thought to share my findings here.

Hmm, that's awkward. We don't have a way to patch old versions like that - we make updates on `main` only, and release new versions as we go. It seems like we might need to find a way to update the modern code so that phi3-mini works well with it.

Yhe I can understand that it might be slightly awkward, but thank you for looking into it atleast even if nothing can be done.
I do think this will happen to everyone who adds labels to samples in batches when using default_data_collator on this version, might not just be phi3-mini.

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 documentation for Trainer.place_model_on_device parameter
Author: Yuyutsu01
Pull request: yes

This PR improves the documentation for the `place_model_on_device` parameter
in the Trainer class.

The previous description was ambiguous and did not reflect the actual behavior.
This update clarifies that:

- When True (default), the Trainer automatically places the model on the target device.
- When False, the user must manually move the model (e.g., model.to(device)).

Fixes #29469.


Comments:
I'm not sure why this PR exists! That issue was closed over a year ago. Closing for now.

It was My first PR for hugging face :) ... But no worries looking
forward for more.

On Tue, 2 Dec 2025, 7:06 pm Matt, ***@***.***> wrote:

> Closed #42534 <https://github.com/huggingface/transformers/pull/42534>.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/huggingface/transformers/pull/42534#event-21306296721>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/BLVYPKSLR4TQQYEG25NDAA337WIXVAVCNFSM6AAAAACNWQJ64OVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMRRGMYDMMRZGY3TEMI>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>


Haha, don't be discouraged from contributing more, in that case! Just check when an issue was created - most older issues, even if they're still open, probably aren't relevant anymore.
Remove "Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation."
Author: yanan1116
Pull request: no

When using GPT2 for generation, there is always info:

> Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation

I find this message hides in https://github.com/huggingface/transformers/blob/master/src/transformers/generation_utils.py
It seems redundancy. Can it be removed for simplicity ?

@patrickvonplaten @patil-suraj 

Comments:
+1, it seems like this method gets triggered on each call to open-ended generation, which pollutes logs quite a bit :/ Is there a way to have it run just once on `pipeline` creation?

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/master/CONTRIBUTING.md) are likely to be ignored.

You can manually set the pad_token_id to prevent this error message before running the pipeline, e.g.

```python
gen_pipe = pipeline("text-generation")
gen_pipe.model.config.pad_token_id = gen_pipe.model.config.eos_token_id
```

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/master/CONTRIBUTING.md) are likely to be ignored.

@patrickvonplaten Hello, I have set

model.config.pad_token_id = tokenizer.eos_token_id

but still got this warning, is it an error? How to disable it totally、

This error still persists and with other models too. This doesn't work

> You can manually set the pad_token_id to prevent this error message before running the pipeline, e.g.
> 
> ```python
> gen_pipe = pipeline("text-generation")
> gen_pipe.model.config.pad_token_id = gen_pipe.model.config.eos_token_id
> ```



Which version of `transformers` are you using? COuld you pass a reproducer? Both of you are not passing a full reproducer. 

This worked for me.

`output = pipeline(query_prompts, pad_token_id=pipeline.model.config.eos_token_id)`

Looks like both the model and the tokenizer pad token have to be set to eradicate this error.
```
pipeline.model.config.pad_token_id = pipeline.model.config.eos_token_id
pipeline.tokenizer.pad_token = pipeline.tokenizer.eos_token
```

If you are ok with disabling all info messages, setting the verbosity level to error would also work
```py
import transformers
transformers.logging.set_verbosity_error()
```

FYI: For newer versions of `transformers`, you need to set `model.generation_config.pad_token_id` instead of the one from `model.config` to suppress the warning message
Ray Tune trials fail importing datasets
Author: filbeofITK
Pull request: no
Labels: name: bug

### System Info

Hyperparameter search with Ray Tune backend fails, because ray workers try to use the `init_dynamic_modules()` function during setup, which doesn't exist (anymore?).

```python
File .../integration_utils.py", line 426, in  dynamic_modules_import_trainable
dynamic_modules_path = os.path.join(datasets.load.init_dynamic_modules(), "__init__.py")
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'datasets.load' has no attribute 'init_dynamic_modules'
```

Transformers env results:
- `transformers` version: 4.57.1
- Platform: Linux-4.18.0-477.27.1.el8_8.x86_64-x86_64-with-glibc2.28
- Python version: 3.12.12
- Huggingface_hub version: 0.36.0
- Safetensors version: 0.6.2
- Accelerate version: 1.11.0
- Accelerate config: 	not found
- DeepSpeed version: not installed
- PyTorch version (accelerator?): 2.9.0+cu128 (NA)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: <fill in>





### Who can help?

@richardliaw, @amogkam 

### Information

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

### Tasks

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

### Reproduction

Start up any hyperparameter optimization job with ray tune as the backend.

### Expected behavior

I would have expected the ray processes to start up.

Comments:
May I ask why the fix merge request was closed without comment? @Rocketknight1 

We got multiple PRs from that user that were all just code agent output, and generally didn't work! I closed all of them.

Ah that makes sense. Sad turn of events, I was so excited to see the bug fixed so soon.

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.