Skip to content

Conversation

@Cyrilvallez
Copy link
Member

@Cyrilvallez Cyrilvallez commented Nov 17, 2025

What does this PR do?

This PR re-add support for weight offloading to disk using the device_map, which was temporarily dropped in #41580 to simplify the PR (because weights need to be resaved correctly after performing custom Ops during dynamic loading).

It further improve the offloading mechanism as everything is now offloaded in safetensors format, vs numpy format originally when using accelerate. This is much easier and efficient.

Slow tests are exactly similar to before the big weight loading refactor (10 failing over all models)

@HuggingFaceDocBuilderDev

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.

@Cyrilvallez Cyrilvallez changed the title [loading] Re-add disk offloading support [loading] Re-add and improve disk offloading support Nov 17, 2025
Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

for the weight renaming, IMO we should just use the prepare model state dict instead of the weights

Comment on lines 597 to 581
# Offloading support
if param_device == "disk":
missing_keys.discard(target_name)
# If not already offloaded, or if we applied any special Operation, we need to re-save
if target_name not in disk_offload_index or len(operations) > 0:
disk_offload_index = offload_weight(
param, target_name, disk_offload_folder, disk_offload_index
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can be done inside set param for module as its kinda related

Copy link
Member Author

Choose a reason for hiding this comment

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

I preferred to keep it outside for now, as it's actually not setting the param! (just saves it to disk and skip loading) So would be a bit weird IMO to do that inside set_param as it does not set it

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Very nice thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there were other tests I skiped with a todo @Cyrilvallez but ff to check

Copy link
Member Author

@Cyrilvallez Cyrilvallez Nov 24, 2025

Choose a reason for hiding this comment

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

Indeed I missed a few! Nice catch!

@github-actions
Copy link
Contributor

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

run-slow: deepseek_vl_hybrid, glm4_moe

@Cyrilvallez Cyrilvallez merged commit af6a36a into main Nov 24, 2025
22 of 24 checks passed
@Cyrilvallez Cyrilvallez deleted the offloading branch November 24, 2025 13:53
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