Skip to content

[Hardware][AMD] integrate aiter into vllm #17710

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

fsx950223
Copy link

@fsx950223 fsx950223 commented May 6, 2025

CMD: VLLM_TORCH_PROFILER_DIR=/mnt/raid0/sixifang/vllm/vllm_profile HIP_VISIBLE_DEVICES=4,5,6,7 VLLM_ROCM_USE_AITER=1 VLLM_USE_V1=1 vllm serve /models/models--amd--Meta-Llama-3.1-8B-Instruct-FP8-KV/snapshots/fa42f9a9105c545755fea25cf69f49ac8c8b40e1/ --tensor-parallel-size 4 --gpu-memory-utilization 0.9 --trust-remote-code --disable-log-requests --block-size 16 --max-model-len 32768 --dtype float16 --quantization fp8 --no-enable-prefix-caching --max-num-batched-tokens=8192

Performance without aiter:
Screenshot from 2025-05-09 17-44-07

vllm (pretrained=/models/models--amd--Meta-Llama-3.1-8B-Instruct-FP8-KV/snapshots/fa42f9a9105c545755fea25cf69f49ac8c8b40e1/,tensor_parallel_size=1,max_model_len=10000,trust_remote_code=True), gen_kwargs: (None), limit: None, num_fewshot: 5, batch_size: auto
|Tasks|Version|     Filter     |n-shot|  Metric   |   |Value |   |Stderr|
|-----|------:|----------------|-----:|-----------|---|-----:|---|-----:|
|gsm8k|      3|flexible-extract|     5|exact_match|↑  |0.7733|±  |0.0115|
|     |       |strict-match    |     5|exact_match|↑  |0.7437|±  |0.0120|

Performance with aiter:
Screenshot from 2025-05-09 18-00-43

vllm (pretrained=/models/models--amd--Meta-Llama-3.1-8B-Instruct-FP8-KV/snapshots/fa42f9a9105c545755fea25cf69f49ac8c8b40e1/,tensor_parallel_size=1,max_model_len=10000,trust_remote_code=True), gen_kwargs: (None), limit: None, num_fewshot: 5, batch_size: auto
|Tasks|Version|     Filter     |n-shot|  Metric   |   |Value |   |Stderr|
|-----|------:|----------------|-----:|-----------|---|-----:|---|-----:|
|gsm8k|      3|flexible-extract|     5|exact_match|↑  |0.7612|±  |0.0117|
|     |       |strict-match    |     5|exact_match|↑  |0.7233|±  |0.0123|

Copy link

github-actions bot commented May 6, 2025

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

@mergify mergify bot added the v1 label May 6, 2025
Copy link

mergify bot commented May 6, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @fsx950223.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

Copy link

mergify bot commented May 6, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @fsx950223.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@gshtras
Copy link
Collaborator

gshtras commented May 7, 2025

What is the minimal AITER commit that has the required functionality?
Also, I think we need a separate flag to toggle this part of AITER on and off, like we have for the others

@mergify mergify bot added documentation Improvements or additions to documentation ci/build tpu Related to Google TPUs labels May 8, 2025
Copy link

mergify bot commented May 8, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @fsx950223.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot removed the tpu Related to Google TPUs label May 8, 2025
logger.info("Using Triton Attention backend on V1 engine.")
return ("vllm.v1.attention.backends."
"triton_attn.TritonAttentionBackend")
if envs.VLLM_ROCM_USE_AITER and envs.VLLM_ROCM_USE_AITER_MHA:
Copy link
Contributor

Choose a reason for hiding this comment

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

should we add on_mi250_mi300() to the condition?

Copy link
Author

Choose a reason for hiding this comment

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

MHA should be used in mi350 too. I won't add the condition.

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM.
It is fine to leave the condition out if we don't expect Radeon GPU users to use AITER.

@fsx950223
Copy link
Author

@fsx950223 could you run lm_eval for some of the models that is using this new kernels and share some performance gain that comes with this kernel?

How to run?

@tjtanaa
Copy link
Contributor

tjtanaa commented May 8, 2025

@fsx950223 could you run lm_eval for some of the models that is using this new kernels and share some performance gain that comes with this kernel?

How to run?

@fsx950223

The steps are:

  1. Install lm_eval

python3 -m pip install lm_eval

  1. Example command
VLLM_USE_V1=1 \
VLLM_ROCM_USE_AITER=1 \
VLLM_USE_TRITON_FLASH_ATTN=0 \
SAFETENSORS_FAST_GPU=1 \
lm_eval --model vllm --model_args pretrained=Qwen/Qwen3-32B,tensor_parallel_size=1,max_model_len=10000 --trust_remote_code --tasks gsm8k --num_fewshot 5 --batch_size auto \
> pr_gsm8k-Qwen_Qwen3-32B.log 2>&1
  1. Example output:
vllm (pretrained=Qwen/Qwen3-32B,tensor_parallel_size=1,max_model_len=10000,trust_remote_code=True), gen_kwargs: (None), limit: None, num_fewshot: 5, batch_size: auto
|Tasks|Version|     Filter     |n-shot|  Metric   |   |Value |   |Stderr|
|-----|------:|----------------|-----:|-----------|---|-----:|---|-----:|
|gsm8k|      3|flexible-extract|     5|exact_match|↑  |0.6255|±  |0.0133|
|     |       |strict-match    |     5|exact_match|↑  |0.7369|±  |0.0121|

Can you provide lm_eval of non-AITER as baseline reference as well?

# Whether to use aiter mha ops.
# By default is enabled.
"VLLM_ROCM_USE_AITER_MHA":
lambda: (os.getenv("VLLM_ROCM_USE_AITER_MHA", "True").lower() in
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to override #16828 by default?

Signed-off-by: fsx950223 <[email protected]>
@fsx950223
Copy link
Author

I found there should be a pa kernel to optimize kernel performance when query len=1. A commit will be submitted.

@fsx950223
Copy link
Author

Done.

Signed-off-by: fsx950223 <[email protected]>
@tdoublep
Copy link
Member

tdoublep commented May 9, 2025

Wouldn't it make more sense to create a new v1 attention backend called aiter_attn for this rather than changing the flash_attn backend?

@coderfeli
Copy link

coderfeli commented May 10, 2025

se to create a new v1 attention backend called aiter_attn for this rather than changing the flash_attn backend?

@tdoublep do you think this is a must? We can do it but need some extra time to re-organize the code. as aiter_attn is very similar to flash_attn and it has a big impact to the performance. can we have this flash_attn changed at first and then reconstruct it to a new one as next step?

Copy link

mergify bot commented May 10, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @fsx950223.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label May 10, 2025
@mergify mergify bot removed the needs-rebase label May 12, 2025
Signed-off-by: fsx950223 <[email protected]>
@fsx950223
Copy link
Author

Wouldn't it make more sense to create a new v1 attention backend called aiter_attn for this rather than changing the flash_attn backend?

Done

@@ -80,6 +80,7 @@
VLLM_ROCM_USE_AITER_MOE: bool = True
VLLM_ROCM_USE_AITER_RMSNORM: bool = True
VLLM_ROCM_USE_AITER_MLA: bool = True
VLLM_ROCM_USE_AITER_MHA: bool = True
Copy link
Collaborator

Choose a reason for hiding this comment

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

wondering what's difference between VLLM_ROCM_USE_AITER and VLLM_ROCM_USE_AITER_MHA?

Copy link
Author

Choose a reason for hiding this comment

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

wondering what's difference between VLLM_ROCM_USE_AITER and VLLM_ROCM_USE_AITER_MHA?

Main switch and submodule switch.

Copy link

mergify bot commented May 13, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @fsx950223.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label May 13, 2025
@mergify mergify bot removed the needs-rebase label May 14, 2025
)
rocm_aiter_rms_norm = torch.ops.vllm.rocm_aiter_rms_norm

except AttributeError:
Copy link
Contributor

@tjtanaa tjtanaa May 15, 2025

Choose a reason for hiding this comment

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

I think we don't need to use the try catch statement. Because the registration must work as vLLM is going to deprecate V0. If registration does not work when aiter is present on ROCm env, this could mean there is a bug.

An example unit tests to check if the registration works is as follows https://github.com/vllm-project/vllm/blob/main/tests/kernels/moe/test_rocm_aiter_topk.py

Copy link
Author

Choose a reason for hiding this comment

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

Done

Signed-off-by: fsx950223 <[email protected]>
@tjtanaa
Copy link
Contributor

tjtanaa commented May 17, 2025

@fsx950223 does this feature works with AITER commit: c1debd87ce0391aa27438d9e07e76e4fea7c4b70 ?
We are trying to fix the AITER features when using this AITER commit. Right now after merging this PR #17912, we are fixing the compatibility of the integrated AITER kernels (e.g. PR #18271)

If you could share us the AITER commit that you are using, we could also try to validate if other AITER kernels needs to be fixed.

@fsx950223
Copy link
Author

I use aiter main branch directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/build documentation Improvements or additions to documentation tool-calling v1
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

6 participants