Skip to content
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

Fix cos_sin device issue in Falcon model #26448

Merged
merged 3 commits into from
Sep 28, 2023
Merged

Fix cos_sin device issue in Falcon model #26448

merged 3 commits into from
Sep 28, 2023

Conversation

ydshieh
Copy link
Collaborator

@ydshieh ydshieh commented Sep 27, 2023

What does this PR do?

We should update the device accordingly. See the comments along the changes.

So far, running the model on GPU, then change model to CPU and running CPU inputs, the cached tensors (like cos_cached) will be on GPU and fail to run with CPU tensors.

Comment on lines 133 to 136
# the cached tensors need to update their devices (for example, after we change the model's device)
if device != self.cos_cached:
self.cos_cached = self.cos_cached.to(device)
self.sin_cached = self.sin_cached.to(device)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

without this, we have problems when switching a model device

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be a check on the device of self.cos_cached rather than on the tensor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, don't know why I made such mistake (as it works on the code snippet I am using 😅 sorry). You saved me!

@ydshieh ydshieh requested a review from LysandreJik September 27, 2023 15:27
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Sep 27, 2023

The documentation is not available anymore as the PR was closed or merged.

Comment on lines +134 to +135
self.cos_cached = self.cos_cached.to(device)
self.sin_cached = self.sin_cached.to(device)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed the check of device. As we can't compare device (given by a tensor) with a string directly.
If it is on the same device (inferred by torch itself), there won't be any operation performed.

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Great, thanks @ydshieh!

@LysandreJik LysandreJik merged commit 375b4e0 into main Sep 28, 2023
@LysandreJik LysandreJik deleted the fix_flacon_device branch September 28, 2023 08:00
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