-
Notifications
You must be signed in to change notification settings - Fork 27.7k
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
Create the return value on device to avoid unnecessary copying from CPU #26151
Conversation
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.
Are you implying that torch.tensor([0], device=hidden_states.device)
does not create the tensor on device=hidden_states.device
? The [0]
is copied but it does not have a place from where it's copied no?
Do you have a reference for this the doc does not seem to indicate this:
device (torch.device, optional) – the device of the constructed tensor. If None and data is a tensor then the device of data is used. If None and data is not a tensor then the result tensor is constructed on the CPU.
I am sorry that I did not explain clearly. The tensor is created on This overhead seems unnecessary, so I have suggested this change in this commit. |
@mksit Are you sure the |
@fxmarty The |
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.
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.
Thanks
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. |
What does this PR do?
router_tuple = (torch.tensor([0], device=hidden_states.device),)
introduces an unnecessary data copy from the CPU. I have changed it to create the return tensor on the device to avoid potential performance issues.Fixes # (issue)
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.