Skip to content

Move missing weights and non-persistent buffers to correct device earlier - #43021

Merged
Cyrilvallez merged 3 commits into
mainfrom
move-it-early
Dec 23, 2025
Merged

Cyrilvallez merged 3 commits into
mainfrom
move-it-early

Conversation

@Cyrilvallez

Copy link
Copy Markdown
Member

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

Comment on lines +4340 to +4342
# This is the only case where we do not initialize the model on meta device, so we don't have to do anything here
if is_deepspeed_zero3_enabled() and not is_quantized:
return

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @SunMarc, could you make extra sure that simply doing this is enough? It should be as it's technically useless to reset the internal param, as it was not on meta before anyway - but let's make sure as you made that change yesterday

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@github-actions

Copy link
Copy Markdown
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=43021&sha=a75715

@SunMarc SunMarc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks ! This is much better

@Cyrilvallez
Cyrilvallez merged commit d6a6c82 into main Dec 23, 2025
24 of 26 checks passed
@Cyrilvallez
Cyrilvallez deleted the move-it-early branch December 23, 2025 17:18

@RatStar811 RatStar811 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request

SangbumChoi pushed a commit to SangbumChoi/transformers that referenced this pull request Jan 23, 2026
…lier (huggingface#43021)

* move to correct device earlier

* fix typo

* simplify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants