noamaanMulla-03/transformers-issues huggingface dataset:
Fix device_map check for ggml files
Author: MekkCyber
Pull request: yes

# What does this PR do?
Fixing the device_map check for ggml files when device_map is not a dict


Comments:
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the `Ready for review` button (at the bottom of the PR page). This will assign reviewers and trigger CI.

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_37003). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
Avoid error when using `torch.compile` and `DataCollatorWithFlattening`
Author: efsotr
Pull request: yes

fix typerror in torch.compile: convert max_length to Python int

Fixes https://github.com/huggingface/transformers/issues/35588#issue-2777961980


## 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?

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.

@ArthurZucker

<!-- 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: @ylacombe, @eustlb
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Rocketknight1
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @SunMarc
- chat templates: @Rocketknight1

Integrations:

- deepspeed: HF Trainer/Accelerate: @muellerzr
- 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: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


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 @arthurzucker for FA2!
Log the correct learning rate
Author: SunMarc
Pull request: yes

# What does this PR do?

> The Trainer class steps the learning rate scheduler at the end of each training loop iteration before calling Trainer._maybe_log_save_evaluate(). As a result, the logged learning rate is the learning rate of the next training step, not the one that was just performed. This off-by-one error is usually not much of a problem with monotonic schedulers, but with cycling schedulers such as cosine_with_restarts, it can be the difference between something very close to zero and the max learning rate at cycle boundaries.

Fixes https://github.com/huggingface/transformers/issues/35942
Similar to https://github.com/huggingface/transformers/pull/30169

Comments:
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the `Ready for review` button (at the bottom of the PR page). This will assign reviewers.

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

This might potentially break trl dpo_online trainer I think @qgallouedec 

Thank you! I will check and correct TRL if necessary. But feel free to merge, I can do it once merged.
Allow easy registration of custom attention functions
Author: Cyrilvallez
Pull request: yes

# What does this PR do?

Basic design idea:

```python
from transformers import AttentionInterface

def my_new_attention():
    ...

AttentionInterface.register("my_new_attention", my_new_attention)
```


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).

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

we are discussing this PR on slack here: https://snow-external.slack.com/archives/C06UEKNNN1L/p1742577094917669?thread_ts=1741376677.268139&cid=C06UEKNNN1L if you want to join. 

The most recent suggestion was to turn this into `collections.abc.MutableMapping` and not an an incomplete `dict` as it's currently in this PR.

Sounds good, never used that before, what does it enable>?
[docs] Attention mask image
Author: stevhliu
Pull request: yes

Adds image from attention mask visualizer

Comments:
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the `Ready for review` button (at the bottom of the PR page). This will assign reviewers.

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_36970). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
fix transformers_cli import relative path issue
Author: yao-matrix
Pull request: yes

**Issue**
when use `python src/transformers/commands/transformers_cli.py env` to get env list by following this [doc](https://huggingface.co/docs/transformers/en/contributing), will report below error:

> Traceback (most recent call last): File "/workspace/transformers/src/transformers/commands/transformers_cli.py", line 18, in <module> from .add_fast_image_processor import AddFastImageProcessorCommand ImportError: attempted relative import with no known parent package

**Fix**
1. replace relative path import to module based import
2. add the missing XPU info

**Results**
Both  `python src/transformers/commands/transformers_cli.py env` and `transformers-cli env` works


Comments:
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the `Ready for review` button (at the bottom of the PR page). This will assign reviewers and trigger CI.

@gante I believe you worked on the CLI recently - have you seen this error too? It seems like quite a large error for us to have missed

@Rocketknight1 yes, but due to a different issue (one import was not guarded) :D 

(merged with main to re-trigger tests, `run_tests` was not starting)

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

# What does this PR do?

The training arguments declared to be removed in earlier versions have been removed. Usage of these arguments have been fixed. Some smaller typing problems also fixed along the way.

Comments:
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the `Ready for review` button (at the bottom of the PR page). This will assign reviewers.

cc @sunmarc @muellerzr
python_interpreter.py  seems not support asyncio.run()
Author: gdw439
Pull request: no
Labels: name: bug

### System Info

python_interpreter.py  seems not support asyncio.run(),

when I use this code,
<img width="876" alt="Image" src="https://github.com/user-attachments/assets/88356177-bf7c-4cb8-a656-9427e217f589" />


it takes that error,
<img width="1114" alt="Image" src="https://github.com/user-attachments/assets/f54c9b7c-2e82-427c-8fe8-390b36733dc1" />


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

some error

### Expected behavior

pass run code in python_interpreter.py, when define my tool function with asyncio.run()

Comments:
cc @aymeric-roucher, but note that `transformers.agents` is now deprecated in favour of [smolagents](https://github.com/huggingface/smolagents), so we may not fix this!

Not wanting to be a square, but asyncio isn't even used upstream of your code. This error happens when a closed loop is already running, but the only time an asyncio loop is created on a  `transformers.agents` is on the `testing_utils` that this file doesn't seem to invoke. Please check out [this](https://medium.com/@vyshali.enukonda/how-to-get-around-runtimeerror-this-event-loop-is-already-running-3f26f67e762e) and implement the `nest_asyncio` lib on your workflow, since this seems to be a problem with your env, not with huggingface

lots o' love

- Jean

P.If you can trace the point where the asyncio loop is created upstream of your code, let me know and I'll eat my words.

Okay, much appreciated. I'll try it later.
Learning rate logging off by one training step
Author: phoerious
Pull request: no
Labels: name: bug

### System Info

transformers==4.48.1

### Who can help?

@muellerz @SunMarc

### Information

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

The Trainer class steps the learning rate scheduler at the end of each training loop iteration before calling `Trainer._maybe_log_save_evaluate()`. As a result, the logged learning rate is the learning rate of the next training step, not the one that was just performed. This off-by-one error is usually not much of a problem with monotonic schedulers, but with cycling schedulers such as `cosine_with_restarts`, it can be the difference between something very close to zero and the max learning rate at cycle boundaries.

LR scheduler is stepped here: https://github.com/huggingface/transformers/blob/4ec425ffad56cdbedfb97ab2d11243e42889f71c/src/transformers/trainer.py#L2605

Logging and checkpointing occurs here: https://github.com/huggingface/transformers/blob/4ec425ffad56cdbedfb97ab2d11243e42889f71c/src/transformers/trainer.py#L2611

### Expected behavior

The call to `Trainer._maybe_log_save_evaluate()` should be moved above the LR scheduler step (or vice versa), otherwise an incorrect learning rate will be logged.

Comments:
I wonder how this might interact with checkpoints. Depending on how you serialise the scheduler, there might be no easy solution to this unless you split logging and saving or keep track of the previous LR before doing the step. Otherwise you might skip a step when resuming from a saved checkpoint.

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.

Beep

gentle ping @muellerzr @SunMarc 

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.

😒 

Sorry for the wait, can you give this a try ? @phoerious 
https://github.com/huggingface/transformers/pull/36973

Looks good.
past_key_values type support bug
Author: real-zhangzhe
Pull request: no
Labels: name: Documentation

In many `XXXXForCausalLM` Class, the past_key_values ​​signature of the forward function is: `past_key_values: Optional[Union[Cache, List[torch.FloatTensor]]] = None,` but the corresponding past_key_values ​​signature of the forward function of the `XXXXModel` Class is: `past_key_values: Optional[Cache] = None,` and the function implementation does not support the `List` type. `past_key_values` ​​will causes an error when calling `self.model` use List type `past_key_values`.

Like `LlamaForCausalLM` and `Qwen2ForCausalLM`

Comments:
cc @zucchini-nlp @gante

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.

But this issue has not been solved yet!

Hey @real-zhangzhe ! 

Right, we might have missed to update the types of cache in some models. We do still support list if list cache in the base model, and then convert it to `Cache` object before passing to decoder layers. There is an effort going on here to fully remove list of list cache format, and I believe the contributor also updates the docs
[Modeling] Load FP8 safetensors such as DeepSeek
Author: kylesayrs
Pull request: yes

## Purpose ##
* Support loading safetensors in FP8

## Changes ##
* Add `F8_E4M3` to `str_to_torch_dtype` mapping used by safetensors loading logic
* Add a value error `Cannot load safetensors of unknown dtype {k_dtype}` if string lookup fails

## Testing ##
* Load DeepSeekV3, which has fp8 weight safetensors

```python3
from transformers import AutoModelForCausalLM

model_id = "deepseek-ai/DeepSeek-V3"
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    device_map="auto",
    torch_dtype="auto",
    trust_remote_code=True,
)
```

## Reviewers ##
@ArthurZucker 

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).

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

@ArthurZucker Although fp8 operations have always been someone limited and hardware dependent (gpu vs cpu), there is no hardware requirement for loading fp8 tensors outside of the required torch version

Will just update the branch to have the ci run! 

Thanks @kylesayrs 🤗
Mark 2 tests as flaky for now
Author: ydshieh
Pull request: yes

# What does this PR do?

Mark 2 tests as flaky for now ...

Comments:
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the `Ready for review` button (at the bottom of the PR page). This will assign reviewers and trigger CI.

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

# What does this PR do?

Fixes the issue of the wrong iterations scheduler being reported and adds a test

Solves https://github.com/huggingface/transformers/issues/28124


## 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).
- [x] 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.

@amyeroberts 

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

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.

Let's close this PR since the fix was merged in the above PR
[Trainer.train] learning rate logging inconsistency: learning rate for the future step is logged
Author: HanGuo97
Pull request: no
Labels: name: trainer

### System Info

NA

### Who can help?

@muellerzr and @pacman100

### 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](https://github.com/huggingface/transformers/blob/c52b515e948fc12ff58ad773a0385860d0162f61/src/transformers/trainer.py#L1913) line of code steps forward the LR scheduler, before `_maybe_log_save_evaluate` is called. This means the learning rate logged represents the learning in the upcoming iteration.


For most of the use cases, the differences between them is small. However, in certain cases, this caused confusion.

### Expected behavior

The learning rate for the current iteration is logged.

Comments:
Gentle ping @muellerzr @pacman100 

Gentle ping @muellerzr @pacman100 

Another ping @muellerzr 

cc @muellerzr @SunMarc 

cc @muellerzr @SunMarc

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.

@ArthurZucker pls assign this issue 2 me

@SunMarc pls check this out

@ArthurZucker Please assign this issue to me


IM still working on it @phoenix0706 pls refer 2 the comment thread


Hey! Thanks both, we don't assign issues, so first PR is what we look at ! 🤗 

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.

Fixed here https://github.com/huggingface/transformers/pull/36973
remove redundant code in trainer
Author: hiyouga
Pull request: yes

# What does this PR do?

The inti func of wsd scheduler is the same as the other schedulers, we do not need explicitly init it.

## 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?

@muellerzr and @SunMarc 


Comments:
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the `Ready for review` button (at the bottom of the PR page). This will assign reviewers and trigger CI.