KEMBAR78
Fix unique memory address when doing group-offloading with disk by sayakpaul · Pull Request #11767 · huggingface/diffusers · GitHub
Skip to content

Conversation

sayakpaul
Copy link
Member

What does this PR do?

#11760 (comment)

@sayakpaul sayakpaul requested a review from DN6 June 22, 2025 10:33
@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.

self.safetensors_file_path = os.path.join(self.offload_to_disk_path, f"group_{id(self)}.safetensors")
self._group_id = _group_id
short_hash = _compute_group_hash(self._group_id)
self.safetensors_file_path = os.path.join(self.offload_to_disk_path, f"group_{short_hash}.safetensors")
Copy link
Collaborator

Choose a reason for hiding this comment

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

The passed in group_id argument should be unique no? I don't think we need to compute a hash.

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 don't see any edge cases, either. But having a hash is a bit more future-proof to me.

raise ValueError("Group offloading is not enabled for the provided module.")


def _compute_group_hash(group_id):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't think we need to hash the group id strings, they should be unique already.

Copy link
Member Author

Choose a reason for hiding this comment

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

record_stream=False,
low_cpu_mem_usage=low_cpu_mem_usage,
onload_self=True,
_group_id=_GROUP_ID_LAZY_LEAF,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't think this is needed. Lazy hook doesn't do anything with it.

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean to exclude group_id here? In that case, it would default id(self) I think.

@sayakpaul sayakpaul requested a review from DN6 June 24, 2025 03:03
@sayakpaul sayakpaul requested a review from a-r-r-o-w June 26, 2025 07:02
@sayakpaul
Copy link
Member Author

@DN6 a gentle ping

@sayakpaul sayakpaul merged commit 2d3d376 into main Jul 9, 2025
32 checks passed
@sayakpaul sayakpaul deleted the fix-memory-address-problem branch July 9, 2025 15:59
@sayakpaul
Copy link
Member Author

@DN6 thanks for your help on this PR :)

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