Encoder-decoder Multihead attention cpu optimization#43
Open
NickNickGo wants to merge 1 commit intomicrosoft:mainfrom
Open
Encoder-decoder Multihead attention cpu optimization#43NickNickGo wants to merge 1 commit intomicrosoft:mainfrom
NickNickGo wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Contributor
|
Good improvement!
|
yuyan2do
approved these changes
Oct 14, 2020
Contributor
yuyan2do
left a comment
There was a problem hiding this comment.
Also update readme and number in benchmark script
| key_padding_mask.unsqueeze(1).to( | ||
| torch.bool), float("-inf")) | ||
| else: | ||
| #Not supported |
Contributor
There was a problem hiding this comment.
add "assert False, reason"
| attn_weights = attn_weights.view(-1, tgt_len, | ||
| *attn_weights.size()[-1:]) | ||
| else: | ||
| q = q.contiguous().view(tgt_len, bsz * self.num_heads, |
Contributor
There was a problem hiding this comment.
why contiguous is needed here?
Contributor
Author
There was a problem hiding this comment.
This was present in the earlier implementation, I didn't touch it since my changes are only meant for en-dec attention. I agree this is redundant. I'll remove it.
Contributor
There was a problem hiding this comment.
There are other places using contiguous. please also check if they can be removed as well.
Contributor
Author
There was a problem hiding this comment.
I just checked this. In all other places, its present after permute/transpose operations which is essential.
This file contains hidden or 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
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.
This PR reduces CPU time for encoder-decoder multihead attention by 25-30%. GPU time is reduced by 10%.
Overall generation time reduces from 47.8 to 44.9.
Attaching before/after profile results: