Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/transformers/generation/continuous_batching/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Comment thread
vasqu marked this conversation as resolved.
Resolved
cuda_available = torch.cuda.is_available()
fa_cuda = is_flash_attention_requested(config, version=3) and cuda_available
Comment on lines +107 to +109

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you check if this is still an issue with fa2 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested flash_attention_2 on A100 and it works normally. However, paged|kernels-community/flash-attn2 fails at the kvcache kernel shape check. The current PR can first ensure XPU access to the CB pipeline.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

flash_attn 2.8.3

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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: pytest -ra tests/generation/test_continuous_batching.py::ContinuousBatchingWithAcceleratorTest -k test_flash_attn2_with_kvcache_parity.

Test Results:

flash_attn 2.8.3: passed
flash_attn 2.8.4 (pip install git+https://github.com/Dao-AILab/flash-attention.git@main): inconsistent output text
kernels-community/flash-attn2: triggered internal out CHECK_SHAPE error

kernels 0.14.1, and it should be unrelated to kernels, it's an internal issue with FA.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, can we merge the current PR for XPU first? Thanks!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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

Expand Down
Loading