|
19 | 19 | from torchtitan.tools.logging import warn_once |
20 | 20 | from torchtitan.tools.utils import has_cuda_capability |
21 | 21 | from vllm.model_executor.layers.attention import Attention |
22 | | -from vllm.v1.attention.backend import AttentionType |
| 22 | +from vllm.v1.attention.backend import AttentionCGSupport, AttentionType |
23 | 23 | from vllm.v1.attention.backends.flash_attn import ( |
24 | 24 | FlashAttentionBackend, |
25 | 25 | FlashAttentionImpl, |
26 | 26 | FlashAttentionMetadata, |
| 27 | + FlashAttentionMetadataBuilder, |
27 | 28 | ) |
28 | 29 | from vllm.v1.attention.backends.registry import AttentionBackendEnum, register_backend |
29 | 30 |
|
@@ -53,6 +54,13 @@ def get_name(): |
53 | 54 | def get_impl_cls(): |
54 | 55 | return PyTorchVarlenAttentionImpl |
55 | 56 |
|
| 57 | + @staticmethod |
| 58 | + def get_builder_cls(): |
| 59 | + class PyTorchVarlenAttentionMetadataBuilder(FlashAttentionMetadataBuilder): |
| 60 | + _cudagraph_support = AttentionCGSupport.ALWAYS |
| 61 | + |
| 62 | + return PyTorchVarlenAttentionMetadataBuilder |
| 63 | + |
56 | 64 |
|
57 | 65 | class PyTorchVarlenAttentionImpl(FlashAttentionImpl): |
58 | 66 | """ |
@@ -146,7 +154,9 @@ def forward( |
146 | 154 |
|
147 | 155 | cu_seqlens_q = attn_metadata.query_start_loc |
148 | 156 | seqused_k = attn_metadata.seq_lens |
149 | | - max_seqlen_q = attn_metadata.max_query_len |
| 157 | + # Pin max_seqlen_q to the total token count for safe cudagraph capture and use |
| 158 | + # the linearize FA3 combine kernel to preserve performance. |
| 159 | + max_seqlen_q = num_actual_tokens |
150 | 160 | max_seqlen_k = attn_metadata.max_seq_len |
151 | 161 | block_table = attn_metadata.block_table |
152 | 162 |
|
|
0 commit comments