vllm.attention.ops.blocksparse_attention.utils
csr_matrix
¶
Simple implementation of CSR matrix conversion without scipy. This replaced scipy.sparse.csr_matrix() previously used.
Source code in vllm/attention/ops/blocksparse_attention/utils.py
__init__
¶
Source code in vllm/attention/ops/blocksparse_attention/utils.py
_get_sparse_attn_mask_homo_head
¶
_get_sparse_attn_mask_homo_head(
q_len: int,
max_seqlen: int,
dtype: dtype,
device: device,
block_size: int = 128,
local_blocks: int = 4,
vert_stride: int = 4,
return_dense: bool = False,
)
:return: a tuple of 3:
- tuple of crow_indices, col_indices representation
of CSR format.
- block dense mask
- all token dense mask (be aware that it can be
OOM if it is too big) if return_dense==True
,
otherwise, None
Source code in vllm/attention/ops/blocksparse_attention/utils.py
ccol_row_to_dense
¶
crow_col_to_dense
¶
Source code in vllm/attention/ops/blocksparse_attention/utils.py
dense_to_crow_col
¶
dense_to_crow_col(x: Tensor)
Turning a 2D/3D torch tensor (x) to CSR rows/cols indexing. NOTE: col_indices padded -1
Source code in vllm/attention/ops/blocksparse_attention/utils.py
get_head_sliding_step
¶
get_sparse_attn_mask
cached
¶
get_sparse_attn_mask(
n_heads: int,
q_len: int,
max_seqlen: int,
dtype: dtype,
device: device,
block_size: int = 64,
local_blocks: int = 4,
vert_stride: int = 4,
homo_head: bool = True,
return_dense: bool = False,
dense_mask_type: str = "binary",
)
:param dense_mask_type: "binary" (0 for skip token, 1 for others)
or "bias" (-inf for skip token, 0 or others)
:return: a tuple of 3:
- tuple of crow_indices, col_indices representation
of CSR format.
- block dense mask
- all token dense mask (be aware that it can be OOM if it
is too big) if return_dense==True
, otherwise, None
Source code in vllm/attention/ops/blocksparse_attention/utils.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|