Skip to content
Merged
Show file tree
Hide file tree
Changes from 157 commits
Commits
Show all changes
166 commits
Select commit Hold shift + click to select a range
6bf2e52
add sink_size parameter in mha_fwd and varlen_mha_fwd
LJ-underdog Oct 27, 2025
12f28c4
Update mha.py
LJ-underdog Oct 28, 2025
b884d23
update mha_varlen_fwd_kernels
LJ-underdog Oct 28, 2025
85de02a
ca_refactor_fix (#1268)
valarLip Oct 28, 2025
e5e7402
fix_fp4_quant_dtype (#1271)
lalala-sh Oct 28, 2025
b38205d
add sample use outer exponential (#1267)
junhaha666 Oct 28, 2025
1d63101
Fix rowwise a8w8 gemm in swizzled hipb_mm (#1258)
kliuae-amd Oct 28, 2025
97b1f9c
CI: Use TW cluster to run sglang tests (#1273)
gyohuangxin Oct 28, 2025
0e3d750
Catchall PR for all 355_wip related changes (#1148)
azaidy Oct 28, 2025
853bbf0
[MI35X] fix core check (#1276)
amd-ruitang3 Oct 29, 2025
f20e5a3
Refactor gemm bf16 tuner (#1275)
yzhou103 Oct 29, 2025
8c1b7ba
CI: Operators tuning pipelines (#1163)
gyohuangxin Oct 29, 2025
f4426ff
fix the problem that v3's performance is worse than ck's (#1237)
minmengdie Oct 29, 2025
51fc112
fix the python mha test error (#1277)
minmengdie Oct 29, 2025
da47070
Reuse custom decorator in core and torch guard (#1278)
ZhangLirong-amd Oct 29, 2025
18b64ca
integrate deep gemm (#1265)
lalala-sh Oct 29, 2025
f925cc1
add a tuned config and insert entries in untuned config (#1243)
hongxiayang Oct 29, 2025
1c19f56
Enable large batch size and optimization of non-Ragged batching (#1269)
valechen Oct 29, 2025
c02f0cd
add few more fw ds f4 untuned and tuned shapes for using asm kernel (…
hongxiayang Oct 30, 2025
f5b8e60
CI: Optimize autotuning pipeline and inital the docs (#1286)
gyohuangxin Oct 30, 2025
a5f3b9d
topk per row kernel (#1262)
ukannika Oct 30, 2025
7af8b72
fix aot (#1279)
fsx950223 Oct 30, 2025
6ef39d9
Fix ATOM fp8 model quant fail issue in torch compile (#1299)
ZhangLirong-amd Oct 30, 2025
3ef016c
feat - pa_fwd support block map with stride in num_kv_heads_dim (#1301)
alibaba-miji Oct 30, 2025
655f7f3
Fix how to update accumulator for dot_scaled (#1297)
zhanglx13 Oct 30, 2025
561c778
CI: Optimize autotuning pipeline docs (#1300)
gyohuangxin Oct 31, 2025
380230f
Fix the lint issue (#1307)
gyohuangxin Oct 31, 2025
061e684
fix fwd perf calc error (#1305)
minmengdie Oct 31, 2025
f11109d
add the asm kernel performance of fwd and bwd (#1270)
minmengdie Oct 31, 2025
84dc96d
Fused TopK and Sigmoid kernel (#1251)
samremes Oct 31, 2025
614d1bc
Ar rms (#1290)
TennyWang1223 Oct 31, 2025
d8a270e
Dsv32 cache (#1314)
junhaha666 Nov 1, 2025
292393b
Fix displaying supported architectures (#1316)
HollowMan6 Nov 1, 2025
e787f6c
using standalone pybind (#1317)
valarLip Nov 2, 2025
df7ab92
Enable mha bwd hd192_hd128 (#1308)
slippedJim Nov 3, 2025
25e807e
CI: Add pre-check status check (#1252)
gyohuangxin Nov 3, 2025
7e3e8bf
[CK_TILE] fmha: Add backward pass support for padded inputs (#1212)
Jeff-Huang Nov 3, 2025
6718e93
Mla splitkv enhance split alg inte (#1233)
valarLip Nov 3, 2025
9e88874
Fix gemm tuner error mi350 (#1313)
yzhou103 Nov 3, 2025
c03abe5
CI: Skip triton setup in Aiter standard/multigpu tests and add retrie…
gyohuangxin Nov 4, 2025
1b4712a
Fix global variable torch_fp8 initialization caused issue (#1322)
huizhougit Nov 4, 2025
17c6e6a
Add transpose scale to the triton fused_rms_fp8_group_quant (#1291)
tjtanaa Nov 4, 2025
1561ac3
[Triton] 355 wip Llama FP4 triton fusion + TP8 triton decode shape tu…
k50112113 Nov 4, 2025
9e1ab29
[TRITON] Kernel naming: add reusable constexpr repr helper (#1260)
Boss2002n Nov 4, 2025
e17dc1c
Merge tuned file (#1327)
yzhou103 Nov 5, 2025
bb105a2
fix graph_breaks by return tensor for bool op (#1333)
ZhangLirong-amd Nov 5, 2025
8dc8340
fix_bf16gemm_asm (#1329)
amd-ruitang3 Nov 5, 2025
65ab026
Improve Memory Usage in MLA (#1338)
ruanjm Nov 5, 2025
5b5947e
fix tune error caused by merge tuned_file (#1342)
yzhou103 Nov 5, 2025
05921d3
rm rocblas in tuner (#1337)
yzhou103 Nov 5, 2025
4b1930e
[Triton] DS a16w8 GEMM and fused reduce_rms_fp8_group_quant (#1328)
k50112113 Nov 5, 2025
8be3a72
Add block_m=16 for a8w8_ck_moe_blockscale (#1081)
huaiguxu Nov 6, 2025
093fdcd
Add Fused RMSNorm + FP8 Per-tensor Static Quantization Triton Kernel …
farlukas Nov 6, 2025
116676b
[TRITON] GEMM kernels nomenclature changes (#1283)
Boss2002n Nov 6, 2025
a958f6e
Temporarily run aiter standard and multigpu tests on the TW cluster, …
gyohuangxin Nov 7, 2025
96ff111
[Triton] Disable failing lean attention tests (#1357)
cagrikymk Nov 7, 2025
2aacbdb
add config (#1355)
valarLip Nov 7, 2025
f16cf5e
add how_v3_bf16_cvt control to the Python API (#1351)
minmengdie Nov 7, 2025
4b2c780
[fix]: car 6 rank coredump (#1335)
TennyWang1223 Nov 7, 2025
0cbe0f6
Wrapper_flash_attn_backward custom op to avoid functionalize fallback…
ZhangLirong-amd Nov 7, 2025
5f1a97a
[TRITON] GEMM kernels nomenclature changes (#1292)
Boss2002n Nov 7, 2025
7daab1c
[TRITON] Initial implementations of sparse attention kernels (#1296)
cagrikymk Nov 7, 2025
d906ec7
[MI35X]cktile moe a16w4 support (#1341)
solinzby1 Nov 7, 2025
50170fb
[TRITON] Batched GEMM kernels nomenclature changes (#1293)
Boss2002n Nov 7, 2025
ec4fc5f
[TRITON] Instruction shape fix for Gluon gemm_a8w8_blockscale kernel …
eky-amd Nov 7, 2025
2671d47
moe mxfp4 block_m = 64/128 (#1266)
xudoyuan Nov 8, 2025
782bf07
bug fix (#1370)
valarLip Nov 8, 2025
7345673
[opus] enhance opus utility (#1324)
carlushuang Nov 9, 2025
0985afb
Fix issue in metadata v1.2 where batch size is too large (#1352)
ruanjm Nov 10, 2025
3f7fbae
[GEMM][Config] add a8w8 block scale tuned config for deepseek-v3 (#1310)
gbyu-amd Nov 10, 2025
50da101
support all logit values (#1323)
ukannika Nov 10, 2025
b09d863
CI: Skip triton in Aiter standard and multigpu tests (#1374)
gyohuangxin Nov 10, 2025
55e2227
add the performance data bar chart in the readme (#1372)
minmengdie Nov 10, 2025
7e2266f
force ds ptpc moe use 1 stage moe (#1373)
junhaha666 Nov 10, 2025
abb3346
[TRITON] MHA PA optimizations (#1245)
cagrikymk Nov 10, 2025
d844368
Enable fa multii target build on other arch (#1318)
slippedJim Nov 11, 2025
9012066
[Triton] DS FP4 triton fusion (#1371)
k50112113 Nov 11, 2025
ea183ac
[TRITON] Simplify and optimize triton_kernels moe code and move it in…
lburzawa Nov 11, 2025
ee0ea56
Use torch.zeros_like instead of empty_like to prevent accruacy drop (…
hubertlu-tw Nov 12, 2025
528b2ea
CI: Temporarily using old vllm nightly image (#1389)
gyohuangxin Nov 12, 2025
5d7e28b
Revert "[Triton] DS FP4 triton fusion (#1371)" (#1392)
valarLip Nov 12, 2025
2234ef0
add a8w8 ptpc gemm config for dsv3 (#1382)
junhaha666 Nov 12, 2025
0595973
Test the CI on both MI325 and MI355 (#1364)
gyohuangxin Nov 13, 2025
1c92909
[Triton] change BF16 GEMM config filename (#1398)
k50112113 Nov 13, 2025
4dddd56
Support distributed_init_method and DP in init_distributed (#1353)
ZhangLirong-amd Nov 13, 2025
f653b6e
FA V3(fp8) and paged Attention compressed (CI green) (#1065)
micmelesse Nov 13, 2025
6b58536
is_shuffled (#1377)
xudoyuan Nov 14, 2025
a5ab0a3
Ar rms new interface (#1401)
TennyWang1223 Nov 14, 2025
29cc55b
minor fix for mi355 (#1408)
valarLip Nov 14, 2025
a36f8bc
[Fix] Add sliding window feature for paged_attention_v1 (#1362)
luocheng25 Nov 14, 2025
c8339b9
fused_qk_rope_cat_and_cache_mla: Fix Triton compilation error and bat…
xudonlyu Nov 15, 2025
85f1691
max mla splits perbatch (#1390)
Zzz9990 Nov 17, 2025
9cef005
topk_per_row_opt (#1394)
valarLip Nov 17, 2025
9b1dbb1
Fix fused_rms_mxfp4_quant comment (#1369)
drewads Nov 17, 2025
29cf2dd
leanAttn softmax fix for spurious data mismatch test failures (#1396)
valechen Nov 17, 2025
f044797
Add reduce_scatter api (#1413)
ZhangLirong-amd Nov 18, 2025
6fa502c
fix error in fmoe_tuner (#1405)
yzhou103 Nov 18, 2025
39162a9
optimize thread divergence (#1421)
carlushuang Nov 18, 2025
e4271da
[TRITON] complex number multiplication that supports 3D ROPE triton k…
LiuYinfeng01 Nov 18, 2025
5166dbb
Feat: pa_mqa_logits performance optimization & support kv_preshuffle …
sjfeng1999 Nov 18, 2025
beffb41
[Config] add tuned moe and gemm config for qwen3 235b (#1378)
gbyu-amd Nov 18, 2025
6b1c1ea
fix repeated unnecessary device check (#1221)
b8zhong Nov 18, 2025
b4998e2
remove lru func in fake (#1429)
ZhangLirong-amd Nov 19, 2025
c00de10
Temporarily disable the test on mi355 (#1437)
gyohuangxin Nov 19, 2025
325cad4
Enable MI355 test on main branch
gyohuangxin Nov 19, 2025
ede13c0
CI: Aiter tests bug fix
gyohuangxin Nov 19, 2025
afeb92f
[M308] tune silu&act (#1404)
zufayu Nov 19, 2025
bae6f35
add deepseek ep moe tune config (#1431)
junhaha666 Nov 19, 2025
c13bfc9
[TRITON] Moe a8w4 tuning (#1410)
lburzawa Nov 19, 2025
fbfed27
[TRITON] Apply config-aware naming (kernel_repr) to attention kernel…
Boss2002n Nov 19, 2025
f1c5cdd
[fix]: prebuild gen so (#1412)
TennyWang1223 Nov 19, 2025
0621618
[TRITON] FP8 MQA optimizations (#1422)
cagrikymk Nov 20, 2025
21433da
redirect asm_moe_tkw1 call to fused_moe in order to force kernel tuni…
antsaukk Nov 20, 2025
3b44501
CI: Move some tests to MI355 due to the network issue of TW cluster (…
gyohuangxin Nov 20, 2025
141a9fe
CI: Move Triton tests from TW cluster to internal cluster (#1451)
gyohuangxin Nov 20, 2025
567d549
tune a8w8_blockscale&bpreshuffle for tencent (#1444)
LJ-underdog Nov 20, 2025
0f756a1
[fix]: add ar switch (#1376)
TennyWang1223 Nov 21, 2025
c0484d5
CI: Test pypi connection (#1458)
gyohuangxin Nov 21, 2025
b609ba4
cktile weight preshuffle test and auto tuning for a8w8 (#1400)
solinzby1 Nov 21, 2025
e34fbab
fix_prebuiild_asm (#1439)
amd-ruitang3 Nov 22, 2025
4f12958
fix merged tuned config error (#1460)
yzhou103 Nov 22, 2025
c975485
update triton version check for pa_mqa_logits (#1440)
valarLip Nov 22, 2025
3ff3344
fix all_reduce_fake (#1465)
valarLip Nov 23, 2025
ea1f8bd
CI: Use ausartifactory.amd.com in pip installation (#1469)
gyohuangxin Nov 23, 2025
f94afd1
update codegen (#1471)
amd-ruitang3 Nov 23, 2025
3a278a8
CI: Fix sglang CI test (#1473)
gyohuangxin Nov 24, 2025
48b50f7
CI: Add checkout retry in vLLM benchmark tests (#1476)
gyohuangxin Nov 24, 2025
21d85ef
CI: Move SGlang and Triton tests to MI300 runners (#1485)
gyohuangxin Nov 25, 2025
9471aa5
fix merging aiter config (#1443)
yzhou103 Nov 25, 2025
6fd8081
fix fmoe tune preshuffle error (#1430)
yzhou103 Nov 25, 2025
53632bd
Fix issue: Add nhead=128 support to bf16 and align restrictions (#1450)
ruanjm Nov 25, 2025
b392ea3
fix fwd_v3 output/lse is nan when kseq=0 and fix qseq >> kseq error (…
minmengdie Nov 26, 2025
e23a861
fix the build error of rtp (#1438)
lalala-sh Nov 26, 2025
d161536
Add 32x64 to tuned fmoe config (#1386)
antsaukk Nov 26, 2025
1eecfae
some fix for support gpt_oss (#1488)
junhaha666 Nov 26, 2025
0bd8e89
CI: Revert vllm_benchmark to use the latest nightly image (#1402)
gyohuangxin Nov 26, 2025
dec216b
add sink_size parameter in mha_fwd and varlen_mha_fwd
LJ-underdog Oct 27, 2025
889605e
update ck api
LJ-underdog Nov 26, 2025
839977a
Merge branch 'main' into lj_sink
LJ-underdog Nov 27, 2025
9b40dec
Remove redundant assignment to sink_size
LJ-underdog Nov 27, 2025
3b2f367
Update mha_fwd_kernels.cu
LJ-underdog Nov 27, 2025
0fe7ee7
Update mha.py
LJ-underdog Nov 27, 2025
d9f4423
Add false argument to fmha_batch_prefill call
LJ-underdog Nov 27, 2025
890520b
update ck commit
LJ-underdog Nov 27, 2025
aadd3fe
Handle sink_size with conditional window_size length
LJ-underdog Nov 27, 2025
e06855a
update fmha_api
LJ-underdog Dec 8, 2025
3d1c78b
Merge branch 'main' into lj_sink
LJ-underdog Dec 8, 2025
0e8a494
update ck commit
LJ-underdog Dec 8, 2025
02bc0d4
update ck_commit
LJ-underdog Dec 8, 2025
94cc393
update ck commmit
LJ-underdog Dec 8, 2025
04d1150
fix op test error
LJ-underdog Dec 9, 2025
515874e
Merge branch 'main' into lj_sink
LJ-underdog Dec 9, 2025
9463b79
Update mha.py
LJ-underdog Dec 9, 2025
eaf84f7
Update csrc/include/torch/mha_fwd.h
LJ-underdog Dec 10, 2025
0af1b66
Update csrc/py_itfs_ck/mha_fwd_kernels.cu
LJ-underdog Dec 10, 2025
0bcfcd3
Update csrc/py_itfs_ck/mha_varlen_fwd_kernels.cu
LJ-underdog Dec 10, 2025
b6f92c8
Merge branch 'main' into lj_sink
LJ-underdog Dec 10, 2025
87f99c6
add some comments
LJ-underdog Dec 10, 2025
d4062ca
Update mha_fwd_generate.py
LJ-underdog Dec 10, 2025
a548de2
Clarify sink_size parameter in asm_mha_varlen_fwd.cu
LJ-underdog Dec 10, 2025
ad5abd8
Merge branch 'main' into lj_sink
LJ-underdog Dec 10, 2025
1d4a1b3
Merge branch 'main' into lj_sink
LJ-underdog Dec 12, 2025
4d4394c
Merge branch 'main' into lj_sink
LJ-underdog Dec 15, 2025
0fa5a7c
update ck commit
LJ-underdog Dec 15, 2025
57db2b7
Merge branch 'main' into lj_sink
LJ-underdog Dec 15, 2025
a39061c
Merge branch 'main' into lj_sink
gyohuangxin Dec 15, 2025
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
19 changes: 17 additions & 2 deletions aiter/ops/mha.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def cmdGenFunc_mha_fwd(
is_causal: bool,
window_size_left: int,
window_size_right: int,
sink_size: int,
return_softmax_lse: bool,
return_dropout_randval: bool,
cu_seqlens_q: Optional[torch.Tensor] = None,
Expand Down Expand Up @@ -164,6 +165,7 @@ def gen_mha_fwd_fake_tensors(
is_causal: bool,
window_size_left: int,
window_size_right: int,
sink_size: int,
return_softmax_lse: bool,
return_dropout_randval: bool,
cu_seqlens_q: Optional[torch.Tensor] = None,
Expand Down Expand Up @@ -196,6 +198,7 @@ def mha_fwd(
is_causal: bool,
window_size_left: int,
window_size_right: int,
sink_size: int,
return_softmax_lse: bool,
return_dropout_randval: bool,
cu_seqlens_q: Optional[torch.Tensor] = None,
Expand Down Expand Up @@ -270,6 +273,7 @@ def cmdGenFunc_mha_varlen_fwd(
is_causal: bool,
window_size_left: int,
window_size_right: int,
sink_size: int,
return_softmax_lse: bool,
return_dropout_randval: bool,
out: Optional[torch.Tensor] = None,
Expand Down Expand Up @@ -435,6 +439,7 @@ def gen_mha_varlen_fwd_fake_tensor(
is_causal: bool,
window_size_left: int,
window_size_right: int,
sink_size: int,
return_softmax_lse: bool,
return_dropout_randval: bool,
out: Optional[torch.Tensor] = None,
Expand Down Expand Up @@ -502,6 +507,7 @@ def mha_varlen_fwd(
is_causal: bool,
window_size_left: int,
window_size_right: int,
sink_size: int,
return_softmax_lse: bool,
return_dropout_randval: bool,
out: Optional[torch.Tensor] = None,
Expand Down Expand Up @@ -1211,6 +1217,7 @@ def _flash_attn_forward(
causal: bool,
window_size_left: int,
window_size_right: int,
sink_size: int,
bias: Optional[torch.Tensor],
alibi_slopes: Optional[torch.Tensor],
q_descale: Optional[torch.Tensor],
Expand Down Expand Up @@ -1288,6 +1295,7 @@ def _validate_cu(name: str, x: Optional[torch.Tensor]):
causal,
window_size_left,
window_size_right,
sink_size,
return_lse,
return_softmax,
cu_seqlens_q,
Expand Down Expand Up @@ -1706,6 +1714,7 @@ def forward(
causal=causal,
window_size_left=int(window_size[0]),
window_size_right=int(window_size[1]),
sink_size=int(window_size[2]) if len(window_size) == 3 else 0,
bias=bias,
alibi_slopes=alibi_slopes,
q_descale=None,
Expand Down Expand Up @@ -1824,7 +1833,7 @@ def flash_attn_func(
dropout_p=0.0,
softmax_scale=None,
causal=False,
window_size=(-1, -1), # -1 means infinite context window
window_size=(-1, -1, 0), # -1 means infinite context window
Comment thread
LJ-underdog marked this conversation as resolved.
Outdated
bias=None,
alibi_slopes=None,
deterministic=True,
Expand Down Expand Up @@ -1923,6 +1932,7 @@ def _flash_attn_varlen_forward(
logits_soft_cap: float = 0.0,
window_size_left: int = -1,
window_size_right: int = -1,
sink_size: int = 0,
bias: Optional[torch.Tensor] = None,
alibi_slopes: Optional[torch.Tensor] = None,
q_descale: Optional[torch.Tensor] = None,
Expand All @@ -1943,6 +1953,7 @@ def _flash_attn_varlen_forward(
# mask
window_size_left = -1 if window_size_left >= max_seqlen_k else window_size_left
window_size_right = -1 if window_size_right >= max_seqlen_k else window_size_right
sink_size = 0 if sink_size >= max_seqlen_k else sink_size
mask = causal == True and window_size_left == -1 # causal mask
nmask = (
causal == False and window_size_left == -1 and window_size_right == -1
Expand Down Expand Up @@ -2026,6 +2037,7 @@ def _validate(name: str, t: torch.Tensor):
causal,
window_size_left,
window_size_right,
sink_size,
return_lse,
return_softmax,
out=out,
Expand Down Expand Up @@ -2293,6 +2305,7 @@ def forward(
logits_soft_cap=logits_soft_cap,
window_size_left=window_size[0],
window_size_right=window_size[1],
sink_size=window_size[2] if len(window_size) > 2 else 0,
bias=bias,
alibi_slopes=alibi_slopes,
q_descale=None,
Expand Down Expand Up @@ -2777,6 +2790,7 @@ def flash_attn_fp8_pertensor_func(
causal=causal,
window_size_left=int(window_size[0]),
window_size_right=int(window_size[1]),
sink_size=int(window_size[2]) if len(window_size) == 3 else 0,
bias=None,
alibi_slopes=None,
q_descale=q_descale,
Expand All @@ -2803,7 +2817,7 @@ def flash_attn_varlen_fp8_pertensor_func(
min_seqlen_q=0,
logits_soft_cap=0.0,
causal=False,
window_size=(-1, -1), # -1 means infinite context window
window_size=(-1, -1, 0), # -1 means infinite context window
softmax_scale=None,
):
if softmax_scale is None:
Expand Down Expand Up @@ -2832,6 +2846,7 @@ def flash_attn_varlen_fp8_pertensor_func(
logits_soft_cap=logits_soft_cap,
window_size_left=int(window_size[0]),
window_size_right=int(window_size[1]),
sink_size=int(window_size[2]) if len(window_size) == 3 else 0,
bias=None,
alibi_slopes=None,
q_descale=q_descale,
Expand Down
22 changes: 16 additions & 6 deletions csrc/cpp_itfs/mha_fwd_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
bool has_dropout,
quant_scale_enum qscale_type,
bool use_ext_asm,
bool has_sink,
int how_v3_bf16_cvt = 1,
bool skip_min_seqlen_q = false)
{{
Expand All @@ -54,7 +55,8 @@
qscale_type,
use_ext_asm,
how_v3_bf16_cvt,
skip_min_seqlen_q);
skip_min_seqlen_q,
has_sink);
}}

mha_fwd_splitkv_traits get_mha_fwd_splitkv_traits(int head_size_q,
Expand All @@ -64,7 +66,8 @@
bool has_logits_soft_cap,
mask_enum mask_type,
bias_enum bias_type,
bool has_lse)
bool has_lse,
bool has_sink)
{{
return mha_fwd_splitkv_traits(head_size_q,
head_size_v,
Expand All @@ -73,7 +76,8 @@
has_logits_soft_cap,
mask_type,
bias_type,
has_lse);
has_lse,
has_sink);
}}
{F_dispatch}

Expand All @@ -91,6 +95,7 @@
bool has_lse,
quant_scale_enum qscale_type,
bool use_ext_asm,
bool has_sink,
int how_v3_bf16_cvt,
const void* seqstart_q_padding_ptr,
const void* seqstart_k_padding_ptr,
Expand All @@ -110,6 +115,7 @@
has_dropout,
qscale_type,
use_ext_asm,
has_sink,
how_v3_bf16_cvt,
args.min_seqlen_q != 0);
float t = -1;
Expand All @@ -124,7 +130,8 @@
bool is_group_mode,
mask_enum mask_type,
bias_enum bias_type,
bool has_lse)
bool has_lse,
bool has_sink)
{
int head_size_q = args.hdim_q;
int head_size_v = args.hdim_v;
Expand All @@ -135,7 +142,8 @@
args.logits_soft_cap > 0.f,
mask_type,
bias_type,
has_lse);
has_lse,
has_sink);
return fmha_fwd_splitkv(traits, args, stream_config);
}"""

Expand All @@ -161,8 +169,10 @@
bias_type,
has_lse,
has_dropout,
false,
Comment thread
LJ-underdog marked this conversation as resolved.
Outdated
quant_scale_enum::no_scale,
use_ext_asm);
use_ext_asm,
has_sink);
return fmha_batch_prefill(traits, args, stream_config);
}"""

Expand Down
1 change: 1 addition & 0 deletions csrc/include/mha_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ inline void print_fmha_fwd_args(ARG args)
printf("batch_stride_o = %d\n", args.batch_stride_o);
printf("window_size_left = %d\n", args.window_size_left);
printf("window_size_right = %d\n", args.window_size_right);
printf("sink_size = %d\n", args.sink_size);
printf("mask_type = %d\n", args.mask_type);
printf("p_drop = %f\n", args.p_drop);
printf("s_randval = %d\n", args.s_randval);
Expand Down
16 changes: 11 additions & 5 deletions csrc/include/mha_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ struct mha_fwd_traits : public fmha_fwd_traits
quant_scale_enum qscale_type,
bool use_ext_asm,
int how_v3_bf16_cvt,
bool skip_min_seqlen_q)
bool skip_min_seqlen_q,
bool has_sink)
: fmha_fwd_traits{head_size_q,
head_size_v,
dtype,
Expand All @@ -35,7 +36,8 @@ struct mha_fwd_traits : public fmha_fwd_traits
has_lse,
has_dropout,
qscale_type,
skip_min_seqlen_q},
skip_min_seqlen_q,
has_sink},
use_ext_asm(use_ext_asm),
how_v3_bf16_cvt(how_v3_bf16_cvt)
{
Expand All @@ -53,7 +55,8 @@ struct mha_fwd_splitkv_traits : public fmha_fwd_splitkv_traits
bool has_logits_soft_cap,
mask_enum mask_type,
bias_enum bias_type,
bool has_lse)
bool has_lse,
bool has_sink)
: fmha_fwd_splitkv_traits{head_size_q,
head_size_v,
dtype,
Expand All @@ -63,7 +66,8 @@ struct mha_fwd_splitkv_traits : public fmha_fwd_splitkv_traits
mask_type,
bias_type,
has_lse,
false} // do_fp8_static_quant
false, // do_fp8_static_quant
has_sink}
{
}
};
Expand All @@ -81,6 +85,7 @@ __attribute__((visibility("default"))) float mha_fwd(mha_fwd_args args,
bool has_lse,
quant_scale_enum qscale_type,
bool use_ext_asm,
bool has_sink = false,
int how_v3_bf16_cvt = 1,
const void* seqstart_q_padding_ptr = nullptr,
const void* seqstart_k_padding_ptr = nullptr,
Expand All @@ -93,7 +98,8 @@ mha_fwd_splitkv(mha_fwd_splitkv_args args,
bool is_group_mode,
mask_enum mask_type,
bias_enum bias_type,
bool has_lse);
bool has_lse,
bool has_sink = false);

__attribute__((visibility("default"))) float
mha_batch_prefill(mha_batch_prefill_args args,
Expand Down
2 changes: 2 additions & 0 deletions csrc/include/rocm_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ namespace py = pybind11;
py::arg("is_causal"), \
py::arg("window_size_left"), \
py::arg("window_size_right"), \
py::arg("sink_size"), \
py::arg("return_softmax_lse"), \
py::arg("return_dropout_randval"), \
py::arg("cu_seqlens_q") = std::nullopt, \
Expand Down Expand Up @@ -869,6 +870,7 @@ namespace py = pybind11;
py::arg("is_causal"), \
py::arg("window_size_left"), \
py::arg("window_size_right"), \
py::arg("sink_size"), \
py::arg("return_softmax_lse"), \
py::arg("return_dropout_randval"), \
py::arg("out") = std::nullopt, \
Expand Down
1 change: 1 addition & 0 deletions csrc/include/torch/mha_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ std::vector<at::Tensor> mha_fwd(at::Tensor& q, // [b, sq, hq, d]
bool is_causal,
int window_size_left,
int window_size_right,
int sink_size,
bool return_softmax_lse,
bool return_dropout_randval,
std::optional<at::Tensor> cu_seqlens_q,
Expand Down
1 change: 1 addition & 0 deletions csrc/include/torch/mha_varlen_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mha_varlen_fwd(at::Tensor& q, // [total_q, hq, d
bool is_causal,
int window_size_left,
int window_size_right,
int sink_size,
bool return_softmax_lse,
bool return_dropout_randval,
std::optional<at::Tensor> out, // [total_q, hq, d]
Expand Down
10 changes: 7 additions & 3 deletions csrc/py_itfs_ck/mha_fwd_kernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ mha_fwd_args get_ck_fmha_fwd_args(bool has_lse,
batch_stride_o,
mask.left,
mask.right,
mask.sink,
static_cast<ck_tile::index_t>(mask.type),
0, // min_seqlen_q
p_dropout,
Expand All @@ -161,6 +162,7 @@ mha_fwd(at::Tensor &q, // [b, sq, hq, d]
bool is_causal,
int window_size_left,
int window_size_right,
int sink_size,
bool return_softmax_lse,
bool return_dropout_randval,
std::optional<at::Tensor> cu_seqlens_q_,
Expand Down Expand Up @@ -233,17 +235,18 @@ mha_fwd(at::Tensor &q, // [b, sq, hq, d]
if (is_causal) {
// Causal is the special case where window_size_right == 0 and window_size_left < 0.
window_size_right = 0;
std::string mask_identify = "b:" + std::to_string(window_size_left) + "," + "0";
std::string mask_identify = "b:" + std::to_string(window_size_left) + "," + "0" + "," + std::to_string(sink_size);
mask = mask_info::decode(mask_identify, seqlen_q, seqlen_k); // casual
}
else if (window_size_left == -1 && window_size_right == -1) {
mask = mask_info::decode("0", seqlen_q, seqlen_k); // no mask
}
else {
// Local is the more general case where window_size_right >= 0 or window_size_left >= 0.
std::string mask_identify = "b:" + std::to_string(window_size_left) + "," + std::to_string(window_size_right);
std::string mask_identify = "b:" + std::to_string(window_size_left) + "," + std::to_string(window_size_right) + "," + std::to_string(sink_size);
mask = mask_info::decode(mask_identify, seqlen_q, seqlen_k); // local
}
bool has_sink = mask.sink > 0;

TORCH_CHECK(!(bias_.has_value() && alibi_slopes_.has_value()), "cannot apply bias and alibi at the same time");
bias_enum bias_type = bias_.has_value() ? bias_enum::elementwise_bias :
Expand Down Expand Up @@ -362,7 +365,8 @@ mha_fwd(at::Tensor &q, // [b, sq, hq, d]
bias_type,
has_lse,
qscale_type,
false);
false,
has_sink);
TORCH_CHECK(t >= 0, "invalid argument for fmha_fwd");
}
else {
Expand Down
Loading
Loading