Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions aiter/ops/triton/_triton_kernels/attention/mha.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ def _get_config(
enable_dropout: bool,
dtype: torch.dtype,
has_pe: bool = False,
head_dim_v: int | None = None,
):
if not hasattr(_get_config, "_config_dict"):
dev = arch_info.get_arch()
Expand All @@ -952,5 +953,11 @@ def _get_config(
return fwd_cfg["pe"]
elif enable_dropout or dtype == torch.float32:
return fwd_cfg["dropout_or_fp32"]
elif head_dim_v is not None and 16 < head_dim_v <= 64 and "small_head" in fwd_cfg:
# Mid-small V head dims (16 < d <= 64) hit a num_stages=1 software-pipelining
# pathology on this backend (e.g. ~3x slower at d64). Using num_stages=3
# recovers performance and is numerically verified for these dims, but
# regresses d128 and miscompiles d<=16, so only 16 < d <= 64 uses this path.
return fwd_cfg["small_head"]
else:
return fwd_cfg["default"]
4 changes: 3 additions & 1 deletion aiter/ops/triton/attention/mha.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ def _flash_attn_forward(
), f"dao_ai softmax_lse shape {softmax_lse.shape} != expected (batch={batch}, nheads={num_q_heads}, ...)"
else:
if config is None:
config = _get_config(enable_dropout, q.dtype, has_pe=pe_head_dim > 0)
config = _get_config(
enable_dropout, q.dtype, has_pe=pe_head_dim > 0, head_dim_v=v_head_dim
)

grid = lambda META: (
batch * num_q_heads * triton.cdiv(seqlen_q, META["BLOCK_M"]),
Expand Down
11 changes: 10 additions & 1 deletion aiter/ops/triton/configs/gfx950-MHA-DEFAULT.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,23 @@
"num_ctas": 1,
"num_stages": 1
},
"small_head": {
"BLOCK_M": 128,
"BLOCK_N": 64,
"PRELOAD_V": true,
"waves_per_eu": 2,
"num_warps": 4,
"num_ctas": 1,
"num_stages": 3
},
"pe": {
"BLOCK_M": 128,
"BLOCK_N": 32,
"PRELOAD_V": true,
"waves_per_eu": 2,
"num_warps": 4,
"num_ctas": 1,
"num_stages": 1
"num_stages": 3
},
"pe_dropout_or_fp32": {
"BLOCK_M": 256,
Expand Down
Loading