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

Conversation

yao-matrix
Copy link
Contributor

@yao-matrix yao-matrix commented Jun 11, 2025

  1. when run pytest -rA tests/models/unets/test_models_unet_2d_condition.py::UNet2DConditionModelTests::test_load_sharded_checkpoint_device_map_from_hub_local on 8 devices(CUDA, XPU), there will be a RuntimeError "RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:4 and cuda:1!", fix it by moving to same device
  2. enable one gpu-only case on accelerator(XPU test passed)

@sayakpaul , pls help review, thx.

@sayakpaul sayakpaul requested a review from SunMarc June 11, 2025 02:25
@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.

@yao-matrix
Copy link
Contributor Author

@SunMarc , could you pls help review? Thx very much.

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

Thanks ! Left a comment

Comment on lines +2560 to +2561
if hidden_states.device != res_hidden_states.device:
res_hidden_states = res_hidden_states.to(hidden_states.device)
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.

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