Skip to content

Commit e58294d

Browse files
authored
[Bugfix] Add verbose error if scipy is missing for blocksparse attention (#5695)
1 parent f1e15da commit e58294d

File tree

1 file changed

+13
-6
lines changed
  • vllm/attention/ops/blocksparse_attention

1 file changed

+13
-6
lines changed

vllm/attention/ops/blocksparse_attention/utils.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66

77
import torch
88
import triton
9-
from scipy import sparse
9+
10+
try:
11+
from scipy import sparse
12+
except ImportError as err:
13+
raise ImportError("Please install scipy via "
14+
"`pip install scipy` to use "
15+
"BlockSparseAttention in "
16+
"models such as Phi-3.") from err
1017

1118

1219
def dense_to_crow_col(x: torch.Tensor):
@@ -77,11 +84,11 @@ def _get_sparse_attn_mask_homo_head(
7784
):
7885
"""
7986
:return: a tuple of 3:
80-
- tuple of crow_indices, col_indices representation
87+
- tuple of crow_indices, col_indices representation
8188
of CSR format.
8289
- block dense mask
83-
- all token dense mask (be aware that it can be
84-
OOM if it is too big) if `return_dense==True`,
90+
- all token dense mask (be aware that it can be
91+
OOM if it is too big) if `return_dense==True`,
8592
otherwise, None
8693
"""
8794
with torch.no_grad():
@@ -148,10 +155,10 @@ def get_sparse_attn_mask(
148155
:param dense_mask_type: "binary" (0 for skip token, 1 for others)
149156
or "bias" (-inf for skip token, 0 or others)
150157
:return: a tuple of 3:
151-
- tuple of crow_indices, col_indices representation
158+
- tuple of crow_indices, col_indices representation
152159
of CSR format.
153160
- block dense mask
154-
- all token dense mask (be aware that it can be OOM if it
161+
- all token dense mask (be aware that it can be OOM if it
155162
is too big) if `return_dense==True`, otherwise, None
156163
"""
157164
assert dense_mask_type in ("binary", "bias")

0 commit comments

Comments
 (0)