Skip to content

Follow up for Group Offload to Disk #11760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Follow up for Group Offload to Disk #11760

wants to merge 5 commits into from

Conversation

DN6
Copy link
Collaborator

@DN6 DN6 commented Jun 19, 2025

What does this PR do?

Since we now have multiple offload options available in group offload (standard, low_cpu_mem_usage, offload_to_disk), it would make sense to create separate utility functions for them and try to reuse common patterns e.g. try to use cpu_param_dict and the pinned_memory context manager with streams.

This PR is just to organize the module a bit so that it's a bit easier to add further functionality, e.g. #11758 without having a lot of conditional paths.

Fixes # (issue)

Before submitting

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.

@DN6 DN6 requested review from a-r-r-o-w and sayakpaul and removed request for a-r-r-o-w June 19, 2025 16:47
@DN6
Copy link
Collaborator Author

DN6 commented Jun 19, 2025

btw @sayakpaul This line

self.safetensors_file_path = os.path.join(self.offload_to_disk_path, f"group_{id(self)}.safetensors")

Uses the memory address of the group object to create the filename, but that can change across sessions. So you could have the offload directory growing quite substantially if running an inference script multiple times.

Might need to come up with another way to name the files so that new ones aren't created across sessions.

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

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

Clean as water. Thanks a lot.

Looking into the memory address thing.

@torch.compiler.disable()
def onload_(self):
r"""Onloads the group of modules to the onload_device."""
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for it to et out? 👁️


@torch.compiler.disable()
Copy link
Member

Choose a reason for hiding this comment

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

I guess we don't need it as it's being called from offload_() which is already decorated with it.

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.

3 participants