-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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
multi-gpu: fix tensor device placements for various models #35763
Open
dvrogozh
wants to merge
3
commits into
huggingface:main
Choose a base branch
from
dvrogozh:multi-gpu2
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.
+209
−101
Conversation
This file contains 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
Fixing the following errors in few models: ``` > hidden_states = inputs_embeds + pos_embeds E RuntimeError: Expected all tensors to be on the same device, but found at least two devices, xpu:2 and xpu:3! ``` Fixes: huggingface#35762 Signed-off-by: Dmitry Rogozhkin <[email protected]>
Fixes: huggingface#35762 Signed-off-by: Dmitry Rogozhkin <[email protected]>
dvrogozh
requested review from
zucchini-nlp,
ArthurZucker,
amyeroberts and
qubvel
as code owners
January 18, 2025 04:54
dvrogozh
commented
Jan 18, 2025
@@ -309,6 +309,7 @@ def slow_forward( | |||
) # [batch, intermediate_size, seq_len] | |||
else: | |||
conv_state = cache_params.update_conv_state(self.layer_idx, hidden_states, cache_position) | |||
conv_state = conv_state.to(self.conv1d.weight.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.
FYI reviewers, this fix was basically taken from here:
conv_states = cache_params.conv_states[self.layer_idx].to(device=self.conv1d.weight.device) |
@@ -818,7 +818,7 @@ def forward( | |||
if inputs_embeds is None: | |||
inputs_embeds = self.wte(input_ids) | |||
position_embeds = self.wpe(position_ids) | |||
hidden_states = inputs_embeds + position_embeds | |||
hidden_states = inputs_embeds + position_embeds.to(inputs_embeds.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.
FYI reviewers, this fix was taken from here:
hidden_states = inputs_embeds + positions.to(inputs_embeds.device) |
See #30836 (comment) for associated discussion.
Signed-off-by: Dmitry Rogozhkin <[email protected]>
dvrogozh
requested review from
eustlb,
Cyrilvallez and
Rocketknight1
as code owners
January 18, 2025 06:20
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: #35762
CC: @SunMarc @ydshieh @faaany