Fix TorchAO group offload CPU cache aliasing - #14457
Open
rathodkunj2005 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14433.
What changed
ModuleGroup._to_cpu()now creates a real CPU copy for TorchAO tensor subclasses withto("cpu", copy=True)instead ofcpu(). For already-CPU TorchAO tensors,cpu()can return the original object, so the group-offload CPU cache aliases the live parameter. When_swap_torchao_tensor()later mutates the live parameter's inner tensor attributes during onload, the cached "CPU" copy follows it to the accelerator and the streamed pinning path can fail on accelerator-backedqdata.The regression test covers the aliasing mechanism with a TorchAO int8 v2 parameter and verifies that the cached tensor's internal data stays on CPU after the live parameter is swapped away, then can restore the parameter back to CPU.
Verification
python -m pytest tests/hooks/test_group_offloading.py -q36 passed, 4 skipped in 10.45sruff check src/diffusers/hooks/group_offloading.py tests/hooks/test_group_offloading.pyAll checks passed!ruff format --check src/diffusers/hooks/group_offloading.py tests/hooks/test_group_offloading.py2 files already formattedgit diff --checkAI-assisted contribution disclosure: I used an AI agent for code navigation and drafting, and verified the diff and commands above locally.