-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
yao-matrix
wants to merge
23
commits into
huggingface:main
Choose a base branch
from
yao-matrix:xpu
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6001899
xx
yao-matrix 8a1d6e5
fix
yao-matrix 603257b
Update model_loading_utils.py
yao-matrix 8cdfdd8
Update test_models_unet_2d_condition.py
yao-matrix 45e29bd
Update test_models_unet_2d_condition.py
yao-matrix 2a7c17d
Merge branch 'main' into xpu
yao-matrix fae7c70
fix style
yao-matrix 80fdbfc
Merge branch 'main' into xpu
yao-matrix 97a37a1
Merge branch 'main' into xpu
yao-matrix 5f0c794
Merge branch 'main' into xpu
yao-matrix 8cd06b3
Merge branch 'main' into xpu
yao-matrix 02a6a35
Merge branch 'main' into xpu
yao-matrix ed1a788
Merge branch 'main' into xpu
yao-matrix 220ce94
Merge branch 'main' into xpu
yao-matrix e59cb0c
Merge branch 'main' into xpu
yao-matrix fd618b5
Merge branch 'main' into xpu
yao-matrix c340f9e
Merge branch 'main' into xpu
yao-matrix e674ce7
Merge branch 'main' into xpu
yao-matrix d389758
Merge branch 'main' into xpu
yao-matrix 7e8ae22
Merge branch 'main' into xpu
yao-matrix c43bb19
Merge branch 'main' into xpu
yao-matrix 49ac5d4
Merge branch 'main' into xpu
yao-matrix b7148d6
Merge branch 'main' into xpu
yao-matrix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SunMarc , i suppose this is a corner case?
torch.cat
is a weight-less function, so seems cannot covered by the pre-forward hook set byaccelerate
...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean since
hidden_states
andres_hidden_states_tuple
are in the forward definition, they should be moved to the same device by the pre-forward hook added by accelerateUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SunMarc We run into a corner case here. Since we have 8 cards here, so the determined
device_map
(by https://github.com/huggingface/diffusers/blob/1bc6f3dc0f21779480db70a4928d14282c0198ed/src/diffusers/models/model_loading_utils.py#L64C5-L64C26) isWe can see
UpBlock
is not the atomic module, its submodules are assigned to different devices(up_blocks.0.resnets.0, up_blocks.0.resnets.1), so pre-hook forUpBlock
will not help in this case. And sincetorch.cat
is not pre-hooked(and cannot since it's a function rather than a module?), so the issue happens.If there is no a
torch.cat
btw the sub-blocks inUpBlock
, things will be all fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SunMarc, need your inputs in how to proceed for this corner case, thx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SunMarc We can see a similar case in
transformers
utpytest -rA tests/models/chameleon/test_modeling_chameleon.py::ChameleonVision2SeqModelTest::test_model_parallel_beam_search
w/ 2 cards, the error log is "RuntimeError: Expected all tensors to be on the same device, but found at least two devices,src/transformers/models/chameleon/modeling_chameleon.py", the reason is evenresidual
is in the same device ashidden_states
at the beginning, but after they went through some operators as both input and output, they finally placed to different device, but when they come to+
which is not a nn.Module(so accelerate cannot pre-hook it), error happens. Do you have some insights on such issues?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SunMarc, could you share your insights on the issue i mentioned above? thx very much.