Repository navigation
Support FA2 flash_attn_with_kvcache for XPU continuous batching #46028
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
Changes from all commits
0ac2283
1439bd2
2c3cd05
a87a19c
629e8a7
7e38eef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| from ...configuration_utils import PretrainedConfig | ||
| from ...generation.configuration_utils import CompileConfig, ContinuousBatchingConfig | ||
| from ...modeling_flash_attention_utils import lazy_import_paged_flash_attention | ||
| from ...utils import is_torch_xpu_available | ||
| from ...utils.generic import is_flash_attention_requested | ||
| from .requests import logger | ||
| from .utils import WorkloadHints | ||
|
|
@@ -103,27 +104,31 @@ def ensure_decode_fast_path_is_available( | |
| available, and no user-provided max blocks per request, set it to the fallback default.""" | ||
| # Then, if the decode fast path is not turned off, check if it is available | ||
| if cb_config.max_blocks_per_request != 0: | ||
| # NOTE: block table should be available with FA2 and FA3, but there seems to be an issue with FA2 atm | ||
| if is_flash_attention_requested(config, version=3): | ||
| # NOTE: For CUDA, block table should be available with FA2 and FA3, but there seems to be an issue with FA2 atm | ||
| cuda_available = torch.cuda.is_available() | ||
| fa_cuda = is_flash_attention_requested(config, version=3) and cuda_available | ||
|
Comment on lines
+107
to
+109
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you check if this is still an issue with fa2 ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tested
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, that's interesting. What version of FA2 did you use? Usually the kernels version shouldnt diverge from upstream But yea anyways, this feels out of scope
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
flash_attn 2.8.3
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also check the beta versions? I think they indirectly included some changes as well to FA2
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we open a separate issue to track this? Would merge this PR after then and we can track this separately
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Summary: Test script is in repo https://github.com/YangKai0616/transformers/tree/tmp-fa-test, test command: Test Results:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for surfacing this. huggingface/kernels-community#877 -- let's wait for this one to get merged and reconvene.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, can we merge the current PR for XPU first? Thanks!
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opened an issue over here huggingface/kernels-community#894 - I think we will try to sync with the latest FA2 release instead of the main branch. As you also showed it's not stable Merging this PR, thanks for the discussion! Very valuable imo |
||
| # XPU support is given through its kernel variation `kernels-community/flash-attn2` | ||
| xpu_available = is_torch_xpu_available() | ||
| fa_xpu = is_flash_attention_requested(config, version=2) and xpu_available | ||
| if fa_cuda or fa_xpu: # Block table is only supported on these | ||
| flash_attn_with_kvcache = lazy_import_paged_flash_attention(config._attn_implementation)[1] | ||
| conditions = [ | ||
| torch.cuda.is_available(), # Block table is only supported on CUDA | ||
| flash_attn_with_kvcache is not None, # The `flash_attn_with_kvcache` fn is needed | ||
| ] | ||
| # Throw a warning only if the decode fast path was requested by the user | ||
| if not all(conditions): | ||
| if flash_attn_with_kvcache is None: | ||
| if user_requested: | ||
| logger.warning( | ||
| f"Although {cb_config.max_blocks_per_request = }, the decode fast path is not available " | ||
| f"because at least one condition is not met: {conditions}." | ||
| f"because `flash_attn_with_kvcache` is not available for {config._attn_implementation = }." | ||
| ) | ||
| cb_config.max_blocks_per_request = 0 | ||
| # Specific warning for attn implementation other than FA3 | ||
| # Specific warning for unsupported attention implementation/device combinations | ||
| else: | ||
| if user_requested: | ||
| logger.warning( | ||
| f"Although {cb_config.max_blocks_per_request = }, the decode fast path is not available " | ||
| f"because the attention implementation is not FA3. Got {config._attn_implementation = }." | ||
| "because the attention implementation and device combination is not supported. Supported " | ||
| "combinations are Flash Attention 3 on CUDA, or Flash Attention 2 on XPU through " | ||
| "`kernels-community/flash-attn2`. " | ||
| f"Got {config._attn_implementation = }, {cuda_available = }, {xpu_available = }." | ||
| ) | ||
| cb_config.max_blocks_per_request = 0 | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.