Skip to content

[Core] Add Lora Support to Beam Search #18346

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 7 commits into from
May 28, 2025

Conversation

alex-jw-brooks
Copy link
Contributor

@alex-jw-brooks alex-jw-brooks commented May 19, 2025

Adds support for passing lora adapters for beam search (offline and online).

FIX #17205

Sample usage (offline):

from vllm import LLM
from vllm.sampling_params import BeamSearchParams
from vllm.lora.request import LoRARequest
from huggingface_hub import snapshot_download

sql_lora_path = snapshot_download(repo_id="yard1/llama-2-7b-sql-lora-test")
llm = LLM(model="meta-llama/Llama-2-7b-hf", enable_lora=True)

sampling_params = BeamSearchParams(
    beam_width=2,
    temperature=0,
    max_tokens=256,
)

outputs = llm.beam_search(
    [
        {"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]"},
        {"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]"},
    ],
    sampling_params,
    # Note - you can also pass a list of LoRARequest/Nones that aligns with the prompt list
    lora_request=LoRARequest("sql_adapter", 1, sql_lora_path),
)

for output in outputs:
    print(f"{output.sequences[0].text}\n\n")

sample output:

<s> [user] Write a SQL query to answer the question based on the table schema.

 context: CREATE TABLE table_name_74 (icao VARCHAR, airport VARCHAR)

 question: Name the ICAO for lilongwe international airport [/user] [assistant] Write a SQL query to answer the question based on the table schema.  context: CREATE TABLE table_name_74 (icao VARCHAR, airport VARCHAR)  question: Name the ICAO for lilongwe international airport     SELECT ICAO FROM table_name_74 WHERE airport = 'lilongwe international airport'     SELECT ICAO FROM table_name_74 WHERE airport = 'lilongwe international airport'    SELECT ICAO FROM table_name_74 WHERE airport = 'lilongwe international airport'   SELECT ICAO FROM table_name_74 WHERE airport = 'lilongwe international airport'   SELECT ICAO FROM table_name_74 WHERE airport = 'lilongwe international airport'  SELECT ICAO FROM table_name_74 WHERE airport = 'lilongwe international airport'  SELECT ICAO FROM table_name_74 WHERE airport = 'lilongwe international airport'  SELECT ICAO FROM table_name_74 WHERE


<s> [user] Write a SQL query to answer the question based on the table schema.

 context: CREATE TABLE table_name_11 (nationality VARCHAR, elector VARCHAR)

 question: When Anchero Pantaleone was the elector what is under nationality? [/user] [assistant] Write a SQL query to answer the question based on the table schema.  context: CREATE TABLE table_name_11 (nationality VARCHAR, elector VARCHAR)  question: When Anchero Pantaleone was the elector what is under nationality?     SELECT nationality FROM table_name_11 WHERE elector = 'anchero pantaleone'    SELECT nationality FROM table_name_11 WHERE elector = 'anchero pantaleone'    SELECT nationality FROM table_name_11 WHERE elector = 'anchero pantaleone'   SELECT nationality FROM table_name_11 WHERE elector = 'anchero pantaleone'   SELECT nationality FROM table_name_11 WHERE elector = 'anchero pantaleone'  SELECT nationality FROM table_name_11 WHERE elector = 'anchero pantaleone'  SELECT nationality FROM table_name_11 WHERE elector = 'anchero pantaleone'  SELECT nationality FROM table_name_11 WHERE elector = 'anchero pantaleone'

Sample usage (online):

Start the server:

python -m vllm.entrypoints.openai.api_server --device cuda --model meta-llama/Llama-2-7b-hf --api-key token-abc123 --dtype=half --enable-lora  --lora-modules test=yard1/llama-2-7b-sql-lora-test
from openai import OpenAI
client = OpenAI(
    base_url="http://localhost:8000/v1",
    api_key="token-abc123",
)

completion = client.completions.create(
    model="test",
    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]",
    n=2,
    extra_body=dict(use_beam_search=True),
    max_tokens=256,
)

print(completion.choices[0].text)

Sample output:

 SELECT icao FROM table_name_74 WHERE airport = 'lilongwe international airport'     SELECT icao FROM table_name_74 WHERE airport = 'lilongwe international airport'    SELECT icao FROM table_name_74 WHERE airport = 'lilongwe international airport'   SELECT icao FROM table_name_74 WHERE airport = 'lilongwe international airport'   SELECT icao FROM table_name_74 WHERE airport = 'lilongwe international airport'   SELECT icao FROM table_name_74 WHERE airport = 'lilongwe international airport'  SELECT icao FROM table_name_74 WHERE airport = 'lilongwe international airport'  SELECT icao FROM table_name_74 WHERE airport = 'lilongwe international airport'  SELECT icao FROM table_name_74 WHERE airport = 'lilongwe international airport'  SELECT icao FROM table_name_74 WHERE airport

CC @jeejeelee

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.

🚀

@mergify mergify bot added the frontend label May 19, 2025
@jeejeelee jeejeelee self-assigned this May 19, 2025
@jeejeelee
Copy link
Collaborator

Thank you, will look at this PR ASAP

Copy link
Collaborator

@jeejeelee jeejeelee left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@jeejeelee jeejeelee added the ready ONLY add when PR is ready to merge/full CI is needed label May 26, 2025
@jeejeelee
Copy link
Collaborator

@alex-jw-brooks Please sync with the main branch to verify if it can fix the CI failure

Signed-off-by: Alex-Brooks <[email protected]>
Signed-off-by: Alex-Brooks <[email protected]>
Signed-off-by: Alex-Brooks <[email protected]>
Signed-off-by: Alex-Brooks <[email protected]>
Signed-off-by: Alex-Brooks <[email protected]>
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) May 27, 2025 16:53
@alex-jw-brooks
Copy link
Contributor Author

Awesome, thanks for the review @jeejeelee! Rebased this PR, but it looks like the image build timed out. Could you please retry it?

@DarkLight1337
Copy link
Member

Retrying

@alex-jw-brooks
Copy link
Contributor Author

Awesome, thanks @DarkLight1337! I think the test failures look unrelated

@vllm-bot vllm-bot merged commit 321331b into vllm-project:main May 28, 2025
71 of 74 checks passed
amitm02 pushed a commit to amitm02/vllm that referenced this pull request Jun 1, 2025
minpeter pushed a commit to minpeter/vllm that referenced this pull request Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Support Lora for Beam Search
4 participants