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
a30b3ce2
Commit
a30b3ce2
authored
Apr 03, 2025
by
zhuwenwen
Browse files
update triton_decode_attention.py
parent
343a10fa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
4 deletions
+28
-4
examples/mla/triton_decode_attention.py
examples/mla/triton_decode_attention.py
+14
-2
vllm/attention/ops/triton_decode_attention.py
vllm/attention/ops/triton_decode_attention.py
+14
-2
No files found.
examples/mla/triton_decode_attention.py
View file @
a30b3ce2
...
...
@@ -753,6 +753,12 @@ def decode_attention_v1(
@
triton
.
autotune
(
configs
=
[
triton
.
Config
({
"BLOCK_N"
:
16
,
"BLOCK_DIM"
:
64
},
num_warps
=
2
,
num_stages
=
1
),
triton
.
Config
({
"BLOCK_N"
:
16
,
"BLOCK_DIM"
:
64
},
num_warps
=
4
,
num_stages
=
1
),
triton
.
Config
({
"BLOCK_N"
:
32
,
"BLOCK_DIM"
:
64
},
num_warps
=
2
,
num_stages
=
1
),
triton
.
Config
({
"BLOCK_N"
:
32
,
"BLOCK_DIM"
:
64
},
num_warps
=
4
,
num_stages
=
1
),
triton
.
Config
({
"BLOCK_N"
:
64
,
"BLOCK_DIM"
:
32
},
num_warps
=
2
,
num_stages
=
1
),
triton
.
Config
({
"BLOCK_N"
:
64
,
"BLOCK_DIM"
:
32
},
num_warps
=
4
,
num_stages
=
1
),
triton
.
Config
({
"BLOCK_N"
:
16
,
"BLOCK_DIM"
:
64
},
num_warps
=
2
,
num_stages
=
2
),
triton
.
Config
({
"BLOCK_N"
:
16
,
"BLOCK_DIM"
:
64
},
num_warps
=
4
,
num_stages
=
2
),
triton
.
Config
({
"BLOCK_N"
:
32
,
"BLOCK_DIM"
:
64
},
num_warps
=
2
,
num_stages
=
2
),
...
...
@@ -1146,11 +1152,17 @@ def decode_attentionv2_fwd(
):
assert
num_kv_splits
==
attn_logits
.
shape
[
2
]
kv_group_num
=
q
.
shape
[
1
]
//
v_buffer
.
shape
[
-
2
]
current_device
=
torch
.
cuda
.
current_device
()
props
=
torch
.
cuda
.
get_device_properties
(
current_device
)
cu_num
=
props
.
multi_processor_count
num_b
=
min
(
kv_group_num
,
16
)
grid_num
=
(
q
.
shape
[
1
]
+
num_b
-
1
)
//
num_b
*
q
.
shape
[
0
]
L
=
req_to_token
.
shape
[
1
]
*
page_size
if
grid_num
*
num_kv_splits
<
128
:
num_kv_splits
=
(
127
+
grid_num
)
//
grid_num
if
grid_num
*
num_kv_splits
<
cu_num
:
num_kv_splits
=
(
cu_num
-
1
+
grid_num
)
//
grid_num
#[TODO] The relationship between L and block is to be analyzed
if
L
>=
2048
:
num_kv_splits
=
(
2
*
cu_num
-
1
+
grid_num
)
//
grid_num
attn_logits_v1
=
torch
.
empty
(
(
q
.
shape
[
0
],
q
.
shape
[
1
],
num_kv_splits
,
v_buffer
.
shape
[
-
1
]
+
1
),
dtype
=
torch
.
float32
,
...
...
vllm/attention/ops/triton_decode_attention.py
View file @
a30b3ce2
...
...
@@ -1064,6 +1064,12 @@ def decode_attention_v1(
# @triton.autotune(
# configs=[
# triton.Config({"BLOCK_N": 16, "BLOCK_DIM":64}, num_warps=2, num_stages=1),
# triton.Config({"BLOCK_N": 16, "BLOCK_DIM":64}, num_warps=4, num_stages=1),
# triton.Config({"BLOCK_N": 32, "BLOCK_DIM":64}, num_warps=2, num_stages=1),
# triton.Config({"BLOCK_N": 32, "BLOCK_DIM":64}, num_warps=4, num_stages=1),
# triton.Config({"BLOCK_N": 64, "BLOCK_DIM":32}, num_warps=2, num_stages=1),
# triton.Config({"BLOCK_N": 64, "BLOCK_DIM":32}, num_warps=4, num_stages=1),
# triton.Config({"BLOCK_N": 16, "BLOCK_DIM":64}, num_warps=2, num_stages=2),
# triton.Config({"BLOCK_N": 16, "BLOCK_DIM":64}, num_warps=4, num_stages=2),
# triton.Config({"BLOCK_N": 32, "BLOCK_DIM":64}, num_warps=2, num_stages=2),
...
...
@@ -1545,11 +1551,17 @@ def decode_attention_fwd(
page_size,
logit_cap,
)'''
current_device
=
torch
.
cuda
.
current_device
()
props
=
torch
.
cuda
.
get_device_properties
(
current_device
)
cu_num
=
props
.
multi_processor_count
num_b
=
min
(
kv_group_num
,
16
)
grid_num
=
(
q
.
shape
[
1
]
+
num_b
-
1
)
//
num_b
*
q
.
shape
[
0
]
L
=
req_to_token
.
shape
[
1
]
*
page_size
if
grid_num
*
num_kv_splits
<
128
:
num_kv_splits
=
(
127
+
grid_num
)
//
grid_num
if
grid_num
*
num_kv_splits
<
cu_num
:
num_kv_splits
=
(
cu_num
-
1
+
grid_num
)
//
grid_num
#[TODO] The relationship between L and block is to be analyzed
if
L
>=
2048
:
num_kv_splits
=
(
2
*
cu_num
-
1
+
grid_num
)
//
grid_num
attn_logits_v2
=
torch
.
empty
(
(
q
.
shape
[
0
],
q
.
shape
[
1
],
num_kv_splits
,
v_buffer
.
shape
[
-
1
]
+
1
),
dtype
=
torch
.
float32
,
...
...
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