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.
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
Add flash-attn #41
Add flash-attn #41
Changes from all commits
7d5154f
118f0a8
d50a89b
61fe86d
f5019c8
0ff5746
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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'm wondering if FlashAttention would work with just expand, that doesn't allocate new memory. If it were to work we would get the full benefits of FlashAttention for MQA. (I would expect it to enforce contiguous tensors but it's worth checking)
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 asking whether if it would still work if we remove the call to
.contiguous()
on the next line?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.
That would almost certainly not work (transposed tensors are much harder to deal with), but maybe if we do the expand after the transpose or skip the transpose altogether.
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.
That looks very bad. Megatron uses the
s b
format precisely to avoid this kind of reshape. If FlashAttention usesb s
we should use that format instead. It should be OK to just comment the two conversions, at least without sequence parallelism (SP would need extra changes but we probably won't use it anyway) https://github.com/bigcode-project/Megatron-LM/blob/multi-query-attention/megatron/model/language_model.py#L240 https://github.com/bigcode-project/Megatron-LM/blob/multi-query-attention/megatron/model/gpt_model.py#L43There 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 suggesting to use
b s
through the whole transformer model?I think that would require a big chunk of refactoring work, and also testing to make sure we are not breaking anything.
Looking at the nice performance improvements that flash-attn brings, I wouldn't take the risk of breaking everything else just to avoid a transpose 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.
Actually the order only matters for attention (and sequence parallell), so it should just be about bypassing these two lines.
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.
The transposes have a big impact on memory usage and a moderate one on speed (I think) so it's quite important.