-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
[Hardware][Intel] Add LoRA adapter support for CPU backend #4830
Conversation
Test Resultfrom vllm import LLM
from vllm import SamplingParams
from vllm.lora.request import LoRARequest
llm = LLM("meta-llama/Llama-2-7b-hf", enable_lora=True)
sql_lora_path = "yard1/llama-2-7b-sql-lora-test"
prompts = [
"[user] Write a SQL query to answer the question based on the table schema.\n\n context: CREATE TABLE table_name_74 (icao VARCHAR, airport VARCHAR)\n\n question: Name the ICAO for lilongwe international airport [/user] [assistant]",
"[user] Write a SQL query to answer the question based on the table schema.\n\n context: CREATE TABLE table_name_11 (nationality VARCHAR, elector VARCHAR)\n\n question: When Anchero Pantaleone was the elector what is under nationality? [/user] [assistant]",
]
sampling_params = SamplingParams(temperature=0.8, top_p=0.95, max_tokens=128, stop=["[/assistant]"])
outputs = llm.generate(prompts, sampling_params, lora_request=LoRARequest("sql_adapter", 1, sql_lora_path))
# Print the outputs.
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}") Outputs: INFO 05-16 16:05:44 llm_engine.py:103] Initializing an LLM engine (v0.4.2) with config: model='/data/LLM-model/Llama-2-7b-hf', speculative_config=None, tokenizer='/data/LLM-model/Llama-2-7b-hf', skip_tokenizer_init=False, tokenizer_mode=auto, revision=None, tokenizer_revision=None, trust_remote_code=False, dtype=torch.float16, max_seq_len=4096, download_dir=None, load_format=LoadFormat.AUTO, tensor_parallel_size=1, disable_custom_all_reduce=False, quantization=None, enforce_eager=False, kv_cache_dtype=auto, quantization_param_path=None, device_config=cpu, decoding_config=DecodingConfig(guided_decoding_backend='outlines'), seed=0, served_model_name=/data/LLM-model/Llama-2-7b-hf)
WARNING 05-16 16:05:44 cpu_executor.py:112] float16 is not supported on CPU, casting to bfloat16.
WARNING 05-16 16:05:44 cpu_executor.py:115] CUDA graph is not supported on CPU, fallback to the eager mode.
WARNING 05-16 16:05:44 cpu_executor.py:142] Environment variable VLLM_CPU_KVCACHE_SPACE (GB) for CPU backend is not set, using 4 by default.
WARNING 05-16 16:05:44 punica.py:14] punica LoRA kernels require a GPU to run. But you are using the CPU version vLLM
INFO 05-16 16:05:45 selector.py:52] Using Torch SDPA backend.
INFO 05-16 16:05:53 cpu_executor.py:71] # CPU blocks: 512
Processed prompts: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:46<00:00, 23.45s/it, Generation Speed: 1.13 toks/s]
Prompt: '[user] Write a SQL query to answer the question based on the table schema.\n\n context: CREATE TABLE table_name_74 (icao VARCHAR, airport VARCHAR)\n\n question: Name the ICAO for lilongwe international airport [/user] [assistant]', Generated text: " SELECT icao FROM table_name_74 WHERE airport = 'lilongwe international airport' "
Prompt: '[user] Write a SQL query to answer the question based on the table schema.\n\n context: CREATE TABLE table_name_11 (nationality VARCHAR, elector VARCHAR)\n\n question: When Anchero Pantaleone was the elector what is under nationality? [/user] [assistant]', Generated text: " SELECT nationality FROM table_name_11 WHERE elector = 'Anchero Pantaleone' " |
@Isotr0py Hi, thanks for enabling the LoRA feature on CPU! The patch seems outdated, could you please help to do a rebase in case you are available? thanks, -yuan |
@zhouyuan I have rebased the code. The native lora kernel should work again. |
@zhouyuan @bigPYJ1151 Could you please review this PR? Thanks! |
LGTM, thanks for your efforts to make LoRA work on the CPU backend, let's find a way to make it more efficient. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Isotr0py Thanks for submitting the PR!
Overall, I'm good with the implementation here. My only concern is, I'm not sure whether we'd like to a feature with (extremely) unoptimized performance. We've seen that people sometimes misunderstand the performance of vLLM due to such unoptimized features.
Let me discuss more with the team and get back to you.
"The CPU backend does not support custom kernels for LoRA. " | ||
"Falling back to unoptimized PyTorch-native implementation, " | ||
"which may lead to performance drop.") | ||
elif torch.cuda.get_device_capability() < (8, 0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QQ: Is this implementation compatible with CUDA graphs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation works with enforce_eager=False
, and the CUDA graphs is captured successfully:
(VllmWorkerProcess pid=6403) WARNING 06-26 03:11:20 punica.py:20] punica LoRA kernels require compute capability >= 8.0, but you are running on device with compute capability < 8.0. Falling back to unoptimized PyTorch-native implementation, which may lead to performance drop.
(VllmWorkerProcess pid=6403) INFO 06-26 03:11:25 selector.py:142] Cannot use FlashAttention-2 backend for Volta and Turing GPUs.
(VllmWorkerProcess pid=6403) INFO 06-26 03:11:25 selector.py:52] Using XFormers backend.
(VllmWorkerProcess pid=6403) INFO 06-26 03:11:26 multiproc_worker_utils.py:215] Worker ready; awaiting tasks
(VllmWorkerProcess pid=6403) INFO 06-26 03:11:27 utils.py:672] Found nccl from library libnccl.so.2
(VllmWorkerProcess pid=6403) INFO 06-26 03:11:27 pynccl.py:63] vLLM is using nccl==2.20.5
(VllmWorkerProcess pid=6403) INFO 06-26 03:11:27 custom_all_reduce_utils.py:208] reading GPU P2P access cache from /root/.config/vllm/gpu_p2p_access_cache_for_0,1.json
(VllmWorkerProcess pid=6403) WARNING 06-26 03:11:27 custom_all_reduce.py:175] Custom allreduce is disabled because your platform lacks GPU P2P capability or P2P test failed. To silence this warning, specify disable_custom_all_reduce=True explicitly.
(VllmWorkerProcess pid=6403) INFO 06-26 03:11:27 selector.py:142] Cannot use FlashAttention-2 backend for Volta and Turing GPUs.
(VllmWorkerProcess pid=6403) INFO 06-26 03:11:27 selector.py:52] Using XFormers backend.
(VllmWorkerProcess pid=6403) INFO 06-26 03:11:28 weight_utils.py:218] Using model weights format ['*.safetensors']
(VllmWorkerProcess pid=6403) INFO 06-26 03:11:29 model_runner.py:160] Loading model weights took 2.6537 GB
INFO 06-26 03:11:33 distributed_gpu_executor.py:56] # GPU blocks: 1912, # CPU blocks: 1638
(VllmWorkerProcess pid=6403) INFO 06-26 03:11:36 model_runner.py:889] Capturing the model for CUDA graphs. This may lead to unexpected consequences if the model is not static. To run the model in eager mode, set 'enforce_eager=True' or use '--enforce-eager' in the CLI.
(VllmWorkerProcess pid=6403) INFO 06-26 03:11:36 model_runner.py:893] CUDA graphs can take additional 1~3 GiB memory per GPU. If you are running out of memory, consider decreasing `gpu_memory_utilization` or enforcing eager mode. You can also reduce the `max_num_seqs` as needed to decrease memory usage.
(VllmWorkerProcess pid=6403) INFO 06-26 03:12:15 model_runner.py:965] Graph capturing finished in 38 secs.
So I think this should be compatible with CUDA graphs.
This pull request has been automatically marked as stale because it has not had any activity within 90 days. It will be automatically closed if no further activity occurs within 30 days. Leave a comment if you feel this pull request should remain open. Thank you! |
This pull request has merge conflicts that must be resolved before it can be |
This PR adds the implementation of
bgmv
anddispatch_bgmv_low_level
in pytorch.This works for the device which doesn't satisfy
compute capacity >= 8.0
to launchpunica
kernel.Features
bgmv
anddispatch_bgmv_low_level
function in pytorchBEFORE SUBMITTING, PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE
PR Checklist (Click to Expand)
Thank you for your contribution to vLLM! Before submitting the pull request, please ensure the PR meets the following criteria. This helps vLLM maintain the code quality and improve the efficiency of the review process.
PR Title and Classification
Only specific types of PRs will be reviewed. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:
[Bugfix]
for bug fixes.[CI/Build]
for build or continuous integration improvements.[Doc]
for documentation fixes and improvements.[Model]
for adding a new model or improving an existing model. Model name should appear in the title.[Frontend]
For changes on the vLLM frontend (e.g., OpenAI API server,LLM
class, etc.)[Kernel]
for changes affecting CUDA kernels or other compute kernels.[Core]
for changes in the core vLLM logic (e.g.,LLMEngine
,AsyncLLMEngine
,Scheduler
, etc.)[Hardware][Vendor]
for hardware-specific changes. Vendor name should appear in the prefix (e.g.,[Hardware][AMD]
).[Misc]
for PRs that do not fit the above categories. Please use this sparingly.Note: If the PR spans more than one category, please include all relevant prefixes.
Code Quality
The PR need to meet the following code quality standards:
format.sh
to format your code.docs/source/
if the PR modifies the user-facing behaviors of vLLM. It helps vLLM user understand and utilize the new features or changes.Notes for Large Changes
Please keep the changes as concise as possible. For major architectural changes (>500 LOC excluding kernel/data/config/test), we would expect a GitHub issue (RFC) discussing the technical design and justification. Otherwise, we will tag it with
rfc-required
and might not go through the PR.What to Expect for the Reviews
The goal of the vLLM team is to be a transparent reviewing machine. We would like to make the review process transparent and efficient and make sure no contributor feel confused or frustrated. However, the vLLM team is small, so we need to prioritize some PRs over others. Here is what you can expect from the review process:
action-required
label on the PR if there are changes required. The contributor should address the comments and ping the reviewer to re-review the PR.Thank You
Finally, thank you for taking the time to read these guidelines and for your interest in contributing to vLLM. Your contributions make vLLM a great tool for everyone!