Skip to content
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

Enable patching Fused SDPA #569

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion requirements-hpu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ pandas
tabulate
setuptools>=61
setuptools-scm>=8
vllm-hpu-extension @ git+https://github.com/HabanaAI/vllm-hpu-extension.git@070591a
vllm-hpu-extension @ git+https://github.com/HabanaAI/vllm-hpu-extension.git@41ff369
neural-compressor @ git+https://github.com/intel/neural-compressor.git@b196432
14 changes: 13 additions & 1 deletion vllm/attention/backends/hpu_attn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import torch
import vllm_hpu_extension.ops as ops
from vllm_hpu_extension.utils import Matmul, Softmax, VLLMKVCache
from vllm_hpu_extension.utils import (Matmul, ModuleFusedSDPA, Softmax,
nirda7 marked this conversation as resolved.
Show resolved Hide resolved
VLLMKVCache)

from vllm.attention.backends.abstract import (AttentionBackend, AttentionImpl,
AttentionMetadata, AttentionType)
Expand All @@ -20,6 +21,14 @@

logger = init_logger(__name__)

HPUFusedSDPA = None
try:
from habana_frameworks.torch.hpex.kernels import FusedSDPA
HPUFusedSDPA = FusedSDPA
except ImportError:
logger.warning("Could not import HPU FusedSDPA kernel. "
"vLLM will use native implementation.")


class HPUAttentionBackend(AttentionBackend):

Expand Down Expand Up @@ -117,6 +126,8 @@ def __init__(
self.block2batch_matmul = Matmul()
self.k_cache = VLLMKVCache()
self.v_cache = VLLMKVCache()
self.fused_scaled_dot_product_attention = None if HPUFusedSDPA is None \
else ModuleFusedSDPA(HPUFusedSDPA)
self.num_kv_heads = num_heads if num_kv_heads is None else num_kv_heads
self.sliding_window = sliding_window
self.alibi_slopes = alibi_slopes
Expand Down Expand Up @@ -222,6 +233,7 @@ def forward(
softmax_op=self.softmax,
matmul_av_op=self.matmul_av,
valid_seq_lengths=attn_metadata.seq_lens_tensor,
fsdpa_op=self.fused_scaled_dot_product_attention,
)
else:
# TODO: enable FusedSDPA
Expand Down
3 changes: 2 additions & 1 deletion vllm/executor/hpu_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def stop_profile(self) -> None:
self.driver_worker.stop_profile()

def shutdown(self) -> None:
if hasattr(self.driver_worker, 'shutdown_inc'):
if hasattr(self, "driver_worker") and hasattr(self.driver_worker,
'shutdown_inc'):
self.driver_worker.shutdown_inc()


Expand Down
Loading