-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[Model] Add Phi-2 LoRA support #4886
Conversation
Testfrom vllm import LLM
from vllm import SamplingParams
from vllm.lora.request import LoRARequest
llm = LLM("/data/LLM-model/phi-2", enable_lora=True)
sql_lora_path = "/data/PEFT-LoRA/phi-2/phi-2-universal-NER"
prompts = [
"<|im_start|>human\nText: Mit Patel here from India<|im_end|>\n<|im_start|>gpt\nI've read this text.<|im_end|>\n<|im_start|>human\nwhat is a name of the person in the text?<|im_end|>\n<|im_start|>gpt:\n",
]
sampling_params = SamplingParams(
temperature=0.8, top_p=0.95, max_tokens=64, stop="<|im_end|>"
)
outputs = llm.generate(
prompts, sampling_params, lora_request=LoRARequest("phi_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}") OutputINFO 05-17 21:22:23 llm_engine.py:103] Initializing an LLM engine (v0.4.2) with config: model='/data/LLM-model/phi-2', speculative_config=None, tokenizer='/data/LLM-model/phi-2', skip_tokenizer_init=False, tokenizer_mode=auto, revision=None, tokenizer_revision=None, trust_remote_code=False, dtype=torch.float16, max_seq_len=2048, 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/phi-2)
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
WARNING 05-17 21:22:23 cpu_executor.py:112] float16 is not supported on CPU, casting to bfloat16.
WARNING 05-17 21:22:23 cpu_executor.py:115] CUDA graph is not supported on CPU, fallback to the eager mode.
WARNING 05-17 21:22:23 cpu_executor.py:142] Environment variable VLLM_CPU_KVCACHE_SPACE (GB) for CPU backend is not set, using 4 by default.
WARNING 05-17 21:22:23 punica.py:14] punica LoRA kernels require a GPU to run. But you are using the CPU version vLLM
INFO 05-17 21:22:24 selector.py:52] Using Torch SDPA backend.
INFO 05-17 21:22:35 cpu_executor.py:71] # CPU blocks: 819
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
Processed prompts: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [09:09<00:00, 549.94s/it, Generation Speed: 0.02 toks/s]
Prompt: "<|im_start|>human\nText: Mit Patel here from India<|im_end|>\n<|im_start|>gpt\nI've read this text.<|im_end|>\n<|im_start|>human\nwhat is a name of the person in the text?<|im_end|>\n<|im_start|>gpt:\n", Generated text: 'Mit Patel\n' |
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.
LGTM. Consider adding a test similar to https://github.com/vllm-project/vllm/blob/main/tests/lora/test_llama.py? Also cc @Yard1
OK, but I haven't tested this on punica kernel yet, and only tested it on the cpu kernel proposed in another PR: #4830. I will test it in GPU environment later. It seems that Phi-2 has a different vocab_size compared to existing punica dimension in |
cc @Yard1 for the question above (who's more familiar with punica kernel) |
Well, this works on RTX3080 Ti with INFO 05-18 01:19:13 llm_engine.py:103] Initializing an LLM engine (v0.4.2) with config: model='/data/LLM-model/phi-2', speculative_config=None, tokenizer='/data/LLM-model/phi-2', skip_tokenizer_init=False, tokenizer_mode=auto, revision=None, tokenizer_revision=None, trust_remote_code=False, dtype=torch.float16, max_seq_len=2048, download_dir=None, load_format=LoadFormat.AUTO, tensor_parallel_size=1, disable_custom_all_reduce=False, quantization=None, enforce_eager=True, kv_cache_dtype=auto, quantization_param_path=None, device_config=cuda, decoding_config=DecodingConfig(guided_decoding_backend='outlines'), seed=0, served_model_name=/data/LLM-model/phi-2)
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
INFO 05-18 01:19:14 selector.py:37] Using FlashAttention-2 backend.
INFO 05-18 01:19:16 model_runner.py:145] Loading model weights took 5.1933 GB
INFO 05-18 01:19:18 gpu_executor.py:83] # GPU blocks: 948, # CPU blocks: 819
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
Processed prompts: 100%|█████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 2.72it/s, Generation Speed: 27.19 toks/s]
Prompt: "<|im_start|>human\nText: Mit Patel here from India<|im_end|>\n<|im_start|>gpt\nI've read this text.<|im_end|>\n<|im_start|>human\nwhat is a name of the person in the text?<|im_end|>\n<|im_start|>gpt:\n", Generated text: 'Mit Patel\n' I will add the remaining test later. |
sounds great! It is awesome we just need to change supported modules specification |
Emmm, it's strange that the CI worker OOM during running
Is there any way to solve this? |
@Isotr0py try reducing max_loras in the test to 2 |
It seems that |
@Isotr0py we can keep it but can you add a comment whenever you use |
yeah technically enforce_eager=False case should be already tested |
I have added a comment to mark that |
looks like the test is failing with this error. |
The failure looks kind of unrelated... let me retry the test |
FILL IN THE PR DESCRIPTION HERE
FIX #4141
FIX #3562
BEFORE 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!