Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tune paged attention parameters for AMD GPU. #3255

Merged
merged 5 commits into from
Feb 2, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ def _decode_att_m_fwd(
logit_cap,
):
BLOCK = 64
# [TODO] work around SGPR limit on MI3xx
if is_hip_:
BLOCK = 8
NUM_KV_SPLITS = num_kv_splits
Lk = k_buffer.shape[-1]
Lv = v_buffer.shape[-1]
Expand All @@ -194,6 +197,8 @@ def _decode_att_m_fwd(
num_warps = 4
else:
num_warps = 2
if is_hip_:
num_warps = 1

BLOCK_DMODEL = triton.next_power_of_2(Lk)
BLOCK_DV = triton.next_power_of_2(Lv)
Expand Down Expand Up @@ -433,10 +438,12 @@ def _decode_grouped_att_m_fwd(
)

extra_kargs = {}
num_stages = 2
if is_hip_:
# https://rocm.docs.amd.com/en/docs-6.2.0/how-to/llm-fine-tuning-optimization/optimizing-triton-kernel.html
# https://github.com/triton-lang/triton/blob/main/third_party/amd/backend/compiler.py
extra_kargs = {"waves_per_eu": 4, "matrix_instr_nonkdim": 16, "kpack": 2}
extra_kargs = {"waves_per_eu": 1, "matrix_instr_nonkdim": 16, "kpack": 2}
num_stages = 1

_fwd_grouped_kernel_stage1[grid](
q,
Expand Down Expand Up @@ -467,7 +474,7 @@ def _decode_grouped_att_m_fwd(
NUM_KV_SPLITS=NUM_KV_SPLITS,
logit_cap=logit_cap,
num_warps=4,
num_stages=2,
num_stages=num_stages,
Lk=Lk,
Lv=Lv,
**extra_kargs,
Expand Down
4 changes: 4 additions & 0 deletions python/sglang/srt/server_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ def __post_init__(self):
) and check_gguf_file(self.model_path):
self.quantization = self.load_format = "gguf"

# AMD-specific Triton attention KV splits default number
if is_hip():
self.triton_attention_num_kv_splits = 16

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whchung we noticed that default 8 works better to most cases? Is 16 slightly better as you see, or better toward long sequences as you interested?

Copy link
Collaborator

@HaiShaw HaiShaw Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@this PR boosts grok, etc. as observed.

@staticmethod
def add_cli_args(parser: argparse.ArgumentParser):
# Model and port args
Expand Down
Loading