-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
Conversation
# 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) |
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.
without this, we have problems when switching a model 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.
Shouldn't this be a check on the device of self.cos_cached
rather than on the tensor?
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.
Yes, don't know why I made such mistake (as it works on the code snippet I am using 😅 sorry). You saved me!
The documentation is not available anymore as the PR was closed or merged. |
self.cos_cached = self.cos_cached.to(device) | ||
self.sin_cached = self.sin_cached.to(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.
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.
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.
Great, thanks @ydshieh!
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.