add zero_tensors option with default False to flash_attn_varlen_func api#175
Closed
add zero_tensors option with default False to flash_attn_varlen_func api#175
Conversation
Collaborator
|
Could you send PR to upstream directly? |
Author
|
Will send PR to upstream directly |
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.
Motivation
TransformerEngine (TE) integrate flash-attn as one of the attn backends. For the varlen mode in TE, users can create q, k, v with a fixed total_seqlen larger than the cu_seqlen[-1]. Therefore the padding area for O, dQ, dK, dV, from [cu_seqlen[-1]: end] is undefined since we allocate those tensors with torch.empty_like(). Undefined tensors in the padding area can affect the subsequent bwd operations in transformer model. In addition, on NV h100, torch.empty_like already returns zeroed-out tensors.
Therefore we propose an extra zero_tensors option with default value False into api flash_attn_varlen_func. For customers who creates q/k/v with fixed length, we pass this option into ck kernels so that they can zero out padding areas in the output. This won't affect the original default behavior
Technical Details
Add the zero_tensors option into flash_attn_varlen_func api
Test Plan
Will test flash-attn CI and TE CI
Test Result
TE CI passed
Flash-attn CI pending
Submission Checklist