-
Notifications
You must be signed in to change notification settings - Fork 38
Encoder-decoder Multihead attention cpu optimization #43
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
base: main
Are you sure you want to change the base?
Conversation
Good improvement!
|
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.
Also update readme and number in benchmark script
torch.bool), float("-inf")) | ||
else: | ||
#Not supported |
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.
add "assert False, reason"
else: | ||
q = q.contiguous().view(tgt_len, bsz * self.num_heads, |
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.
why contiguous is needed here?
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.
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.
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 are other places using contiguous. please also check if they can be removed as well.
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 just checked this. In all other places, its present after permute/transpose operations which is essential.
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: