Fix SDPA dispatch & make SDPA CI compatible with torch<2.1.1#27940
Merged
fxmarty merged 1 commit intohuggingface:mainfrom Dec 11, 2023
Merged
Fix SDPA dispatch & make SDPA CI compatible with torch<2.1.1#27940fxmarty merged 1 commit intohuggingface:mainfrom
fxmarty merged 1 commit intohuggingface:mainfrom
Conversation
LysandreJik
approved these changes
Dec 11, 2023
Member
LysandreJik
left a comment
There was a problem hiding this comment.
Ok, looks good, would like @ArthurZucker to take a quick look before merging. Will cherry-pick this for the release.
| # Here we use config._attn_implementation_internal to check whether the attention implementation was explicitely set by the user. | ||
| # The property `PretrainedConfig._attn_implementation` is never `None`, for backward compatibility (always fall back on "eager"). | ||
| # The `hasattr` here is used as some Transformers tests for some reason do not call PretrainedConfig __init__ (e.g. test_no_super_init_config_and_model) | ||
| requested_attn_implementation = None |
Member
There was a problem hiding this comment.
Should this be "default" instead?
Contributor
Author
There was a problem hiding this comment.
No, the idea here is to check whether the user passed attn_implementation="eager", attn_implementation="sdpa" or attn_implementation="sdpa" explicitly when loading the model from from_pretrained or from_config.
In case attn_implementation is explicitly set, we hard error if a dependency is missing (torch>=2.1.1, model does not support SDPA), otherwise we smoothly fall back on eager.
ArthurZucker
approved these changes
Dec 11, 2023
| config = cls._check_and_enable_sdpa(config, hard_check_only=hard_check_only) | ||
| elif not hard_check_only: | ||
| config = cls._check_and_enable_sdpa( | ||
| config, hard_check_only=False if requested_attn_implementation is None else True |
iantbutler01
pushed a commit
to BismuthCloud/transformers
that referenced
this pull request
Dec 16, 2023
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.
As per title.
On torch==2.0.1, these do pass
On torch==2.1.1, these do pass (#26572 (comment))
There was a bug where even though we manually request
attn_implementation="eager", we would still go into the SDPA controlflow and hard check that the requirements are fine. Which is not what we want.