Skip to content

Fix TorchAO group offload CPU cache aliasing - #14457

Open
rathodkunj2005 wants to merge 1 commit into
huggingface:mainfrom
rathodkunj2005:fix-group-offloading-torchao-copy-20260812
Open

Fix TorchAO group offload CPU cache aliasing#14457
rathodkunj2005 wants to merge 1 commit into
huggingface:mainfrom
rathodkunj2005:fix-group-offloading-torchao-copy-20260812

Conversation

@rathodkunj2005

Copy link
Copy Markdown

Fixes #14433.

What changed

ModuleGroup._to_cpu() now creates a real CPU copy for TorchAO tensor subclasses with to("cpu", copy=True) instead of cpu(). 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-backed qdata.

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 -q
    • 36 passed, 4 skipped in 10.45s
  • ruff check src/diffusers/hooks/group_offloading.py tests/hooks/test_group_offloading.py
    • All checks passed!
  • ruff format --check src/diffusers/hooks/group_offloading.py tests/hooks/test_group_offloading.py
    • 2 files already formatted
  • git diff --check
    • passed

AI-assisted contribution disclosure: I used an AI agent for code navigation and drafting, and verified the diff and commands above locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hooks size/S PR with diff < 50 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Title: Group offloading with use_stream=True fails on torchao int8 version=2 (pin_memory on CUDA qdata)

1 participant