Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
d59eb984
"vllm/model_executor/models/internlm2.py" did not exist on "93b38bea5dd03e1b140ca997dfaadef86f8f1855"
Unverified
Commit
d59eb984
authored
Jul 11, 2024
by
Michael Goin
Committed by
GitHub
Jul 12, 2024
Browse files
[Model][Phi3-Small] Remove scipy from blocksparse_attention (#6343)
parent
adf32e0a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
8 deletions
+27
-8
vllm/attention/ops/blocksparse_attention/utils.py
vllm/attention/ops/blocksparse_attention/utils.py
+27
-8
No files found.
vllm/attention/ops/blocksparse_attention/utils.py
View file @
d59eb984
...
...
@@ -4,16 +4,35 @@
from
functools
import
lru_cache
import
numpy
as
np
import
torch
import
triton
try
:
from
scipy
import
sparse
except
ImportError
as
err
:
raise
ImportError
(
"Please install scipy via "
"`pip install scipy` to use "
"BlockSparseAttention in "
"models such as Phi-3."
)
from
err
class
csr_matrix
:
"""Simple implementation of CSR matrix conversion without scipy.
This replaced scipy.sparse.csr_matrix() previously used."""
def
__init__
(
self
,
input_array
):
if
not
isinstance
(
input_array
,
np
.
ndarray
):
raise
ValueError
(
"Input must be a NumPy array"
)
self
.
shape
=
input_array
.
shape
rows
,
cols
=
self
.
shape
data
=
[]
indices
=
[]
indptr
=
[
0
]
for
i
in
range
(
rows
):
for
j
in
range
(
cols
):
if
input_array
[
i
,
j
]:
data
.
append
(
input_array
[
i
,
j
])
indices
.
append
(
j
)
indptr
.
append
(
len
(
indices
))
self
.
data
=
np
.
array
(
data
)
self
.
indices
=
np
.
array
(
indices
)
self
.
indptr
=
np
.
array
(
indptr
)
def
dense_to_crow_col
(
x
:
torch
.
Tensor
):
...
...
@@ -26,7 +45,7 @@ def dense_to_crow_col(x: torch.Tensor):
assert
x
.
dim
()
in
(
2
,
3
)
if
x
.
dim
()
==
2
:
x
=
x
[
None
]
x
=
[
sparse
.
csr_matrix
(
xi
.
bool
().
cpu
().
numpy
())
for
xi
in
x
]
x
=
[
csr_matrix
(
xi
.
bool
().
cpu
().
numpy
())
for
xi
in
x
]
crows
=
torch
.
vstack
([
torch
.
from_numpy
(
xi
.
indptr
)
for
xi
in
x
])
cols
=
[
torch
.
from_numpy
(
xi
.
indices
)
for
xi
in
x
]
max_cols
=
max
(
len
(
xi
)
for
xi
in
cols
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment