Skip to content

Conversation

@NickLucche
Copy link
Collaborator

@NickLucche NickLucche commented Mar 21, 2025

The torch sdpa F.scaled_dot_product_attention impl is particularly inefficient on TPU.
It's both slow and also causes issues when XLA compiling as reported here #15051, which is a major obstacle in multimodal adoption on TPU.

This PR adds a Pallas branch to the vanilla MHA module used in most ViTs.

Some numbers:

Pre PR (TPUv6):

VLLM_USE_V1=1 vllm serve llava-hf/llava-1.5-7b-hf --max-model-len 2512 --max-num-seqs 16 --max-num-batched-tokens 512 --chat-template examples/template_llava.jinja 

============ Serving Benchmark Result ============
Successful requests:                     100       
Benchmark duration (s):                  144.89    
Total input tokens:                      1388      
Total generated tokens:                  7859      
Request throughput (req/s):              0.69      
Output token throughput (tok/s):         54.24     
Total Token throughput (tok/s):          63.82     
---------------Time to First Token----------------
Mean TTFT (ms):                          99840.40  
Median TTFT (ms):                        104402.54 
P99 TTFT (ms):                           141547.78 
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          215.15    
Median TPOT (ms):                        133.66    
P99 TPOT (ms):                           930.35    
---------------Inter-token Latency----------------
Mean ITL (ms):                           206.93    
Median ITL (ms):                         42.99     
P99 ITL (ms):                            3931.00   
==================================================

Post PR (TPUv6):

VLLM_USE_V1=1 vllm serve llava-hf/llava-1.5-7b-hf --max-model-len 2512 --max-num-seqs 16 --max-num-batched-tokens 512 --chat-template examples/template_llava.jinja 

============ Serving Benchmark Result ============
Successful requests:                     100       
Benchmark duration (s):                  39.41     
Total input tokens:                      1388      
Total generated tokens:                  7749      
Request throughput (req/s):              2.54      
Output token throughput (tok/s):         196.60    
Total Token throughput (tok/s):          231.82    
---------------Time to First Token----------------
Mean TTFT (ms):                          20138.36  
Median TTFT (ms):                        21187.89  
P99 TTFT (ms):                           35919.35  
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          67.93     
Median TPOT (ms):                        61.32     
P99 TPOT (ms):                           135.02    
---------------Inter-token Latency----------------
Mean ITL (ms):                           66.88     
Median ITL (ms):                         38.68     
P99 ITL (ms):                            151.16    
==================================================

Throughput boost is significant, almost 4x in this instance.

Signed-off-by: NickLucche <[email protected]>
@github-actions
Copy link

👋 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.

🚀

@NickLucche NickLucche marked this pull request as ready for review March 21, 2025 11:24
@mergify mergify bot added the v1 label Mar 21, 2025
Copy link
Member

@mgoin mgoin left a comment

Choose a reason for hiding this comment

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

LGTM nice work! FYI @Isotr0py

from vllm.attention.selector import _cached_get_attn_backend
from vllm.platforms import current_platform

if not envs.VLLM_USE_V1:
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this also check for the default behavior env bar as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I remember I discussed it with @robertgshaw2-redhat 🤔
Maybe I can check if the env was set rather than its value?

@mgoin mgoin added tpu Related to Google TPUs ready ONLY add when PR is ready to merge/full CI is needed multi-modality Related to multi-modality (#4194) labels Mar 21, 2025
Copy link
Member

@Isotr0py Isotr0py left a comment

Choose a reason for hiding this comment

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

The ViT part LGTM too!

@NickLucche
Copy link
Collaborator Author

FYI CI errors look unrelated, it's the same thing we have on main https://buildkite.com/vllm/ci/builds/16011#0195b8a1-d554-46b6-9929-798657dcabbf

@Isotr0py
Copy link
Member

You can merge from main branch, the failing kennel tests have been fixed by #15282

@vllm-bot vllm-bot merged commit cfbb8c9 into vllm-project:main Mar 21, 2025
40 of 45 checks passed
@NickLucche
Copy link
Collaborator Author

Thanks! Didn't see the PR mb

erictang000 pushed a commit to erictang000/vllm that referenced this pull request Mar 25, 2025
lulmer pushed a commit to lulmer/vllm that referenced this pull request Apr 7, 2025
Signed-off-by: NickLucche <[email protected]>
Signed-off-by: Louis Ulmer <[email protected]>
shreyankg pushed a commit to shreyankg/vllm that referenced this pull request May 3, 2025
RichardoMrMu pushed a commit to RichardoMrMu/vllm that referenced this pull request May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

multi-modality Related to multi-modality (#4194) ready ONLY add when PR is ready to merge/full CI is needed tpu Related to Google TPUs v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants