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

Update knn_datastore.py #9

Merged
merged 1 commit into from
Dec 26, 2022
Merged

Update knn_datastore.py #9

merged 1 commit into from
Dec 26, 2022

Conversation

ZhaoQianfeng
Copy link
Contributor

change

chang torch.zeros(...).to(queries.device) to torch.zeros(..., device=queries.device)

reason

.to() is slow because it needs to transfer data from main memory to GPU memory. For large tensors, creating them directly in GPU memory is much faster.

result

After changing these two lines, knn-mt and adaptive knn-mt can be much faster(about 3x ~ 4x), and the inference speed will not differ much from NMT.

chang torch.zeros(...).to(queries.device) to torch.zeros(..., device=queries.device)
@zhengxxn zhengxxn merged commit 7997d11 into zhengxxn:main Dec 26, 2022
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.

None yet

2 participants