Skip to content

fix "Expected all tensors to be on the same device, but found at least two devices" error #11690

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 11 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion src/diffusers/models/unets/unet_2d_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2557,7 +2557,8 @@ def forward(
b1=self.b1,
b2=self.b2,
)

if hidden_states.device != res_hidden_states.device:
res_hidden_states = res_hidden_states.to(hidden_states.device)
Comment on lines +2560 to +2561
Copy link
Member

Choose a reason for hiding this comment

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

we shouldn't need that since both hidden_states and res_hidden_states should be on the same device no ? The pre-forward hook added by accelerate should be move all the inputs to the same device.

hidden_states = torch.cat([hidden_states, res_hidden_states], dim=1)

if torch.is_grad_enabled() and self.gradient_checkpointing:
Expand Down
5 changes: 2 additions & 3 deletions tests/models/test_modeling_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
require_torch_2,
require_torch_accelerator,
require_torch_accelerator_with_training,
require_torch_gpu,
require_torch_multi_accelerator,
run_test_in_subprocess,
slow,
Expand Down Expand Up @@ -1744,7 +1743,7 @@ def test_push_to_hub_library_name(self):
delete_repo(self.repo_id, token=TOKEN)


@require_torch_gpu
@require_torch_accelerator
@require_torch_2
@is_torch_compile
@slow
Expand Down Expand Up @@ -1789,7 +1788,7 @@ def test_compile_with_group_offloading(self):
model.eval()
# TODO: Can test for other group offloading kwargs later if needed.
group_offload_kwargs = {
"onload_device": "cuda",
"onload_device": torch_device,
"offload_device": "cpu",
"offload_type": "block_level",
"num_blocks_per_group": 1,
Expand Down