-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[Bugfix][LoRA] Fix Qwen35 LoRA #36976
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
449ed9e
Init
jeejeelee 80ae3b0
Merge branch 'vllm-project:main' into fix-qwen35-lora
jeejeelee f79deed
Move forward
jeejeelee 736b71a
Fix format
jeejeelee f0d725a
Merge branch 'main' into fix-qwen35-lora
jeejeelee 840cf61
Merge branch 'main' into fix-qwen35-lora
jeejeelee 5941f90
Add dense model testing
jeejeelee 035f1a8
Address conflict
jeejeelee 49c7735
Fix
jeejeelee 1a1c491
Fix
jeejeelee 3447cde
Merge branch 'main' into fix-qwen35-lora
jeejeelee e198400
Fix
jeejeelee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
| from transformers import AutoTokenizer | ||
|
|
||
| import vllm | ||
| import vllm.config | ||
| from vllm.lora.request import LoRARequest | ||
|
|
||
| from ..utils import create_new_process_for_each_test, multi_gpu_test | ||
|
|
||
| MODEL_PATH = "Qwen/Qwen3.5-4B" | ||
|
|
||
| PROMPT_TEMPLATE = """Write a SQL query for the given database.\nSchema:\nTables:\n - stadium(Stadium_ID, Location, Name, Capacity, Highest, Lowest, Average)\n - singer(Singer_ID, Name, Country, Song_Name, Song_release_year, Age, Is_male)\n - concert(concert_ID, concert_Name, Theme, Stadium_ID, Year)\n - singer_in_concert(concert_ID, Singer_ID)\n\nQuestion:\n{query}""" # noqa: E501 | ||
|
|
||
| EXPECTED_LORA_OUTPUT = [ | ||
| "SELECT count(*) FROM singer", | ||
| "SELECT avg(age) , min(age) , max(age) FROM singer WHERE country = 'France'", | ||
| "SELECT name FROM stadium WHERE stadium_id NOT IN (SELECT stadium_id FROM concert)", | ||
| ] | ||
|
|
||
|
|
||
| tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, trust_remote_code=True) | ||
|
|
||
|
|
||
| def do_sample(llm: vllm.LLM, lora_path: str, lora_id: int) -> list[str]: | ||
| prompts = [ | ||
| PROMPT_TEMPLATE.format(query="How many singers do we have?"), | ||
| PROMPT_TEMPLATE.format( | ||
| query=( | ||
| "What is the average, minimum, and maximum " | ||
| "age of all singers from France?" | ||
| ) | ||
| ), | ||
| PROMPT_TEMPLATE.format( | ||
| query=("What are the names of the stadiums without any concerts?") | ||
| ), | ||
| ] | ||
| input_templates = [] | ||
| for prmpt in prompts: | ||
| messages = [{"role": "user", "content": prmpt}] | ||
| prompt = tokenizer.apply_chat_template( | ||
| messages, | ||
| tokenize=False, | ||
| add_generation_prompt=True, | ||
| enable_thinking=False, # disable thinking | ||
| ) | ||
| input_templates.append(prompt) | ||
| sampling_params = vllm.SamplingParams(temperature=0, max_tokens=512) | ||
| outputs = llm.generate( | ||
| input_templates, | ||
| sampling_params, | ||
| lora_request=LoRARequest(str(lora_id), lora_id, lora_path) if lora_id else None, | ||
| ) | ||
|
|
||
| generated_texts: list[str] = [] | ||
| for output in outputs: | ||
| prompt = output.prompt | ||
| generated_text = output.outputs[0].text.strip() | ||
| generated_texts.append(generated_text) | ||
| print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}") | ||
| return generated_texts | ||
|
|
||
|
|
||
| @create_new_process_for_each_test() | ||
| def test_qwen35_dense_model_lora(qwen35_dense_model_lora_files): | ||
| llm = vllm.LLM( | ||
| MODEL_PATH, | ||
| max_model_len=512, | ||
| enable_lora=True, | ||
| max_loras=2, | ||
| max_num_seqs=16, | ||
| max_lora_rank=8, | ||
| trust_remote_code=True, | ||
| ) | ||
|
|
||
| output1 = do_sample(llm, qwen35_dense_model_lora_files, lora_id=1) | ||
| for i in range(len(EXPECTED_LORA_OUTPUT)): | ||
| assert output1[i] == EXPECTED_LORA_OUTPUT[i] | ||
| output2 = do_sample(llm, qwen35_dense_model_lora_files, lora_id=2) | ||
| for i in range(len(EXPECTED_LORA_OUTPUT)): | ||
| assert output2[i] == EXPECTED_LORA_OUTPUT[i] | ||
|
|
||
|
|
||
| @multi_gpu_test(num_gpus=4) | ||
| def test_qwen35_dense_model_lora_tp4(qwen35_dense_model_lora_files): | ||
| llm = vllm.LLM( | ||
| MODEL_PATH, | ||
| max_model_len=1024, | ||
| enable_lora=True, | ||
| max_loras=2, | ||
| max_lora_rank=8, | ||
| max_num_seqs=16, | ||
| tensor_parallel_size=4, | ||
| trust_remote_code=True, | ||
| fully_sharded_loras=False, | ||
| compilation_config=vllm.config.CompilationConfig( # Avoid OOM | ||
| cudagraph_specialize_lora=False, | ||
| ), | ||
| ) | ||
|
|
||
| output1 = do_sample(llm, qwen35_dense_model_lora_files, lora_id=1) | ||
| print(output1) | ||
| for i in range(len(EXPECTED_LORA_OUTPUT)): | ||
| assert output1[i] == EXPECTED_LORA_OUTPUT[i] | ||
| output2 = do_sample(llm, qwen35_dense_model_lora_files, lora_id=2) | ||
| for i in range(len(EXPECTED_LORA_OUTPUT)): | ||
| assert output2[i] == EXPECTED_LORA_OUTPUT[i] | ||
|
|
||
|
|
||
| @multi_gpu_test(num_gpus=4) | ||
| def test_qwen35_dense_model_lora_tp4_fully_sharded_loras(qwen35_dense_model_lora_files): | ||
| llm = vllm.LLM( | ||
| MODEL_PATH, | ||
| max_model_len=512, | ||
| enable_lora=True, | ||
| max_loras=2, | ||
| max_lora_rank=8, | ||
| tensor_parallel_size=4, | ||
| trust_remote_code=True, | ||
| fully_sharded_loras=True, | ||
| gpu_memory_utilization=0.8, | ||
| compilation_config=vllm.config.CompilationConfig( # Avoid OOM | ||
| cudagraph_specialize_lora=False, | ||
| ), | ||
| ) | ||
| output1 = do_sample(llm, qwen35_dense_model_lora_files, lora_id=1) | ||
| for i in range(len(EXPECTED_LORA_OUTPUT)): | ||
| assert output1[i] == EXPECTED_LORA_OUTPUT[i] | ||
| output2 = do_sample(llm, qwen35_dense_model_lora_files, lora_id=2) | ||
| for i in range(len(EXPECTED_LORA_OUTPUT)): | ||
| assert output2[i] == EXPECTED_LORA_OUTPUT[i] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.