add flash-attn deterministic option to flash-attn>=2.4.1#31961
Merged
ArthurZucker merged 4 commits intoJul 16, 2024
Conversation
ArthurZucker
left a comment
Collaborator
There was a problem hiding this comment.
sounds good! are there other args we should be reading from env ?
| import torch.nn.functional as F | ||
|
|
||
| from .utils import is_flash_attn_2_available | ||
| from .utils import is_flash_attn_2_available, is_flash_attn_greater_or_equal_2_41 |
Collaborator
There was a problem hiding this comment.
Suggested change
| from .utils import is_flash_attn_2_available, is_flash_attn_greater_or_equal_2_41 | |
| from .utils import is_flash_attn_2_available, is_flash_attn_greater |
| ) | ||
| flash_kwargs = {"window_size": (sliding_window, sliding_window)} if use_sliding_windows else {} | ||
|
|
||
| if is_flash_attn_greater_or_equal_2_41(): |
Collaborator
There was a problem hiding this comment.
Suggested change
| if is_flash_attn_greater_or_equal_2_41(): | |
| if is_flash_attn_greater_or_equal("2.41"): |
Comment on lines
+817
to
+821
| def is_flash_attn_greater_or_equal_2_41(): | ||
| if not _is_package_available("flash_attn"): | ||
| return False | ||
|
|
||
| return version.parse(importlib.metadata.version("flash_attn")) >= version.parse("2.4.1") |
Collaborator
There was a problem hiding this comment.
Suggested change
| def is_flash_attn_greater_or_equal_2_41(): | |
| if not _is_package_available("flash_attn"): | |
| return False | |
| return version.parse(importlib.metadata.version("flash_attn")) >= version.parse("2.4.1") |
unnecessary, see def is_flash_attn_greater_or_equal(library_version: str):
…lash_attn_greater_or_equal`
Contributor
Author
@ArthurZucker |
4 tasks
ghost
approved these changes
Jul 16, 2024
ArthurZucker
approved these changes
Jul 16, 2024
ArthurZucker
left a comment
Collaborator
There was a problem hiding this comment.
thanks for iterating
5 tasks
4 tasks
4 tasks
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.
What does this PR do?
This PR introduces support for the deterministic mode available in Flash Attention version 2.4.1 and above.
The deterministic mode in Flash Attention 2.4.1 ensures reproducible results, which is crucial for debugging and scientific research. By integrating this feature, users can benefit from deterministic behavior in their models.
The changes include enabling deterministic behavior through an environment variable and integrating this feature into the _flash_attention_forward function.
Flash Attention Forward Function Update:
Trainer Utilities Update:
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@ArthurZucker