-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
[V1][TPU] Support standard V1 Sampler #13982
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
Conversation
Signed-off-by: NickLucche <[email protected]>
Signed-off-by: NickLucche <[email protected]>
Signed-off-by: NickLucche <[email protected]>
Signed-off-by: NickLucche <[email protected]>
Signed-off-by: NickLucche <[email protected]>
Signed-off-by: NickLucche <[email protected]>
Signed-off-by: NickLucche <[email protected]>
Signed-off-by: NickLucche <[email protected]>
Signed-off-by: NickLucche <[email protected]>
Signed-off-by: NickLucche <[email protected]>
Signed-off-by: NickLucche <[email protected]>
Signed-off-by: NickLucche <[email protected]>
Signed-off-by: NickLucche <[email protected]>
Signed-off-by: NickLucche <[email protected]>
|
👋 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 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 🚀 |
Signed-off-by: NickLucche <[email protected]>
|
This pull request has merge conflicts that must be resolved before it can be |
|
Following up on our discussion earlier, this PR looks good to me; we'll work on improving the performance as a subsequent step. |
|
I will have to update the logic a bit following the ragged attn kernel. I'll post an update asap. |
This PR aims to enable the support of the V1 Sampler for
TPUModelRunner.TL;DR: topk/topp is way too slow now, but we should be able to interface the other options with the current
Samplercode.The idea is to add the sampling operations to the model xla graph. Since re-utilizing a subgraph (the model fwd) is not supported in xla (this could've been useful to compile a bunch of different sampling graphs on top of the model), a single traced sampling function should be recorded.
This entails we have to provide default values to all sampling options so that we can toggle off the unneeded ones by evaluating them to an Identity operation (eg
top_p=1.0).The Sampler's code is mostly already compatible for being compiled into an xla graph, apart from a few minor options:
logit_bias,min_tokens,all_greedy.The main issue is in executing the topk/topp code on TPU, as it results in a significant slowdown in both compilation/inti and run time. For now, I've resolved to disable both options until we have some faster kernel.
The rest of the PR is just making sure to have an xla-friendly
SamplingMetadatainterface, which avoids recompiling optional parameters and handles the "padding to a pre-compiled shape" that we have on TPUs.Test sampling with
VLLM_USE_V1=1 python -m pytest -s tests/v1/tpu/test_sampler.pyfor "~jit" execution orVLLM_USE_V1=1 vllm serve Qwen/Qwen2.5-1.5B-Instruct --max-model-len 1024 --max-num-seqs 256for pre-compiling.TODO:
UPDATE: On topk/topp performace
I've run some micro-benchmarks on the current topk/topp implementation to highlight differences in time.
It runs a random linear layer (simulated lm_head) followed by sampling. Code here, feel free to double check the scripts.
vLLM sampler on TPUv6 (torch-xla):
vLLM sampler on CUDA, no flashinfer (forward_native) on L4:
INFO 03-03 10:41:46 [__init__.py:207] Automatically detected platform cuda. WARNING 03-03 10:41:46 [topk_topp_sampler.py:46] FlashInfer is not available. Falling back to the PyTorch-native implementation of top-p & top-k sampling. For the best performance, please install FlashInfer. Compiling/Warmup 1 elapsed time: 0.8291933536529541 Compiling/Warmup 4 elapsed time: 0.10055041313171387 Compiling/Warmup 16 elapsed time: 0.013581037521362305 Compiling/Warmup 32 elapsed time: 0.013128995895385742 Running 1 elapsed time: 0.008679866790771484 Running 1 elapsed time: 0.008601188659667969 Running 1 elapsed time: 0.008600711822509766 Running 1 elapsed time: 0.008601903915405273 Running 4 elapsed time: 0.009422063827514648 Running 4 elapsed time: 0.009502649307250977 Running 4 elapsed time: 0.009497880935668945 Running 4 elapsed time: 0.00953054428100586 Running 16 elapsed time: 0.01054692268371582 Running 16 elapsed time: 0.010563373565673828 Running 16 elapsed time: 0.01054239273071289 Running 16 elapsed time: 0.01055598258972168 Running 32 elapsed time: 0.013098955154418945 Running 32 elapsed time: 0.013221025466918945 Running 32 elapsed time: 0.013271808624267578I also benchmarked a barebone jax implementation of the sampling, for comparison.
JAX on same TPU