KEMBAR78
Follow up for Group Offload to Disk by DN6 · Pull Request #11760 · huggingface/diffusers · GitHub
Skip to content

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? 👁️

for tensor_obj in self.tensor_to_key.keys():
tensor_obj.data = torch.empty_like(tensor_obj.data, device=self.offload_device)

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

Copy link
Contributor

@a-r-r-o-w a-r-r-o-w left a comment

Choose a reason for hiding this comment

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

Thanks, very clean! Nothing specific catches my eye that looks incorrect, so we should be good to merge :)

@sayakpaul sayakpaul merged commit 3649d7b into main Jun 26, 2025
16 checks passed
@sayakpaul sayakpaul deleted the refactor-group-offload branch June 26, 2025 01:54
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