Only allocate encoder metadata for encoder-decoder models (#16527)
This commit is contained in:
@@ -325,6 +325,7 @@ class FlashAttentionBackend(AttentionBackend):
|
|||||||
and model_runner.model_config.is_encoder_decoder
|
and model_runner.model_config.is_encoder_decoder
|
||||||
), "Sliding window and cross attention are not supported together"
|
), "Sliding window and cross attention are not supported together"
|
||||||
|
|
||||||
|
self.is_encoder_decoder = model_runner.model_config.is_encoder_decoder
|
||||||
self.forward_metadata: FlashAttentionMetadata = None
|
self.forward_metadata: FlashAttentionMetadata = None
|
||||||
# extra metadata for handling speculative decoding topk > 1, extended draft decode and verify
|
# extra metadata for handling speculative decoding topk > 1, extended draft decode and verify
|
||||||
self.forward_metadata_spec_decode_expand: FlashAttentionMetadata = None
|
self.forward_metadata_spec_decode_expand: FlashAttentionMetadata = None
|
||||||
@@ -1574,20 +1575,25 @@ class FlashAttentionBackend(AttentionBackend):
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
self.encoder_metadata = {
|
# Only allocate encoder metadata for encoder-decoder models
|
||||||
"encoder_page_table": torch.zeros(
|
if self.is_encoder_decoder:
|
||||||
max_bs,
|
self.encoder_metadata = {
|
||||||
self.max_context_len,
|
"encoder_page_table": torch.zeros(
|
||||||
dtype=torch.int32,
|
max_bs,
|
||||||
device=self.device,
|
self.max_context_len,
|
||||||
),
|
dtype=torch.int32,
|
||||||
"encoder_lens_int32": torch.zeros(
|
device=self.device,
|
||||||
max_bs, dtype=torch.int32, device=self.device
|
),
|
||||||
),
|
"encoder_lens_int32": torch.zeros(
|
||||||
"encoder_cu_seqlens_k": torch.zeros(
|
max_bs, dtype=torch.int32, device=self.device
|
||||||
max_bs + 1, dtype=torch.int32, device=self.device
|
),
|
||||||
),
|
"encoder_cu_seqlens_k": torch.zeros(
|
||||||
}
|
max_bs + 1, dtype=torch.int32, device=self.device
|
||||||
|
),
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
# For decoder-only models, skip encoder_metadata allocation
|
||||||
|
self.encoder_metadata = {}
|
||||||
|
|
||||||
def init_forward_metadata_capture_cuda_graph(
|
def init_forward_metadata_capture_cuda_graph(
|
||||||
self,
|
self,
|
||||||
|
|||||||
Reference in New Issue
Block a user