Skip to content
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

Chat method for offline llm #5049

Merged
merged 16 commits into from
Aug 16, 2024

Conversation

nunjunj
Copy link
Contributor

@nunjunj nunjunj commented May 25, 2024

Apply chat template for the offline LLM class. Adding new method generate_chat(), which generates chat responses for the input messages.

FIX #1582
FIX #3718
FIX #6191
FIX #6416

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:

  • We adhere to Google Python style guide and Google C++ style guide.
  • Pass all linter checks. Please use format.sh to format your code.
  • The code need to be well-documented to ensure future contributors can easily understand the code.
  • Include sufficient tests to ensure the project to stay correct and robust. This includes both unit tests and integration tests.
  • Please add documentation to 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:

  • After the PR is submitted, the PR will be assigned to a reviewer. Every reviewer will pick up the PRs based on their expertise and availability.
  • After the PR is assigned, the reviewer will provide status update every 2-3 days. If the PR is not reviewed within 7 days, please feel free to ping the reviewer or the vLLM team.
  • After the review, the reviewer will put an 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.
  • Please respond to all comments within a reasonable time frame. If a comment isn't clear or you disagree with a suggestion, feel free to ask for clarification or discuss the suggestion.

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!

Copy link
Collaborator

@simon-mo simon-mo left a comment

Choose a reason for hiding this comment

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

Great first step

  • Let's call it just chat because generate_chat has duplicated meaning. Chat method is generating.
  • Let's also support just a string or list of string for simplicity. We will apply it as a single turn conversation in this case. We should also take a parameter specifying the global system prompt. This is done for usability and it's simple to adopt the chat method.
  • Let's add support for specifying custom chat template via a string. This is supported in online api server.
  • Please add a good example script in the examples directory showcase the many different ways the chat method can be used with string comments.

@DarkLight1337
Copy link
Member

This should also fix #1582. I have edited the OP accordingly.

@DarkLight1337
Copy link
Member

DarkLight1337 commented May 31, 2024

Let's leave out multi_modal_data from the function signature; just focus on text input for now. We can later pass that in as an item of message (where message is a dictionary) to be more similar to OpenAI API.

Also, I would rename test_chat.py to test_llm_chat.py to match the naming convention of the other tests.

tests/entrypoints/test_chat.py Outdated Show resolved Hide resolved
Comment on lines 235 to 240
messages = [{
'role':
'system',
'content':
global_system_prompt or default_system_prompt
}, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

some model (like Mixtral) doesn't support system prompt

Copy link
Contributor Author

@nunjunj nunjunj Jun 6, 2024

Choose a reason for hiding this comment

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

Should I remove the default_system_prompt, and only include a system prompt when it is explicitly passed in?
Or Is there a method or property I can check to see if a model supports system prompts? Thank you for your guidance!

examples/offline_inference_chat.py Outdated Show resolved Hide resolved
examples/offline_inference_chat.py Outdated Show resolved Hide resolved
examples/offline_inference_chat.py Show resolved Hide resolved
@llmpros
Copy link
Contributor

llmpros commented Jul 8, 2024

hi @nunjunj kindly want to check if you may want to continue on this PR? Thanks

@nunjunj
Copy link
Contributor Author

nunjunj commented Jul 8, 2024 via email

Comment on lines 97 to 115
# str and list[str] inputs are treated as text completions, similar to LLM.generate(),
message = "Entropy is"
outputs = llm.chat(
message,
sampling_params=sampling_params,
use_tqdm=False,
)
print_outputs(outputs)

messages = [
"Relativity is a theory about", "Bangkok is a city in",
"One of the best programming languages is"
]
outputs = llm.chat(
messages,
sampling_params=sampling_params,
use_tqdm=False,
)
print_outputs(outputs)
Copy link
Member

Choose a reason for hiding this comment

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

I'm unsure if llm.chat should accept unformatted text completions. It is possible users will use this and be unaware that no chat templating is happening even though they are using the chat interface. I believe HF's apply_chat_template fails if a non-dictionary is passed in, so we may want to follow that lead.

vllm/entrypoints/llm.py Outdated Show resolved Hide resolved
vllm/entrypoints/llm.py Outdated Show resolved Hide resolved
@llmpros
Copy link
Contributor

llmpros commented Jul 17, 2024

Yes, I am working on some merge conflicts and it should be done in a couple of days.

On Tue, Jul 9, 2024 at 2:56 AM ning.zhang @.> wrote: hi @nunjunj https://github.com/nunjunj kindly want to check if you may want to continue on this PR? Thanks — Reply to this email directly, view it on GitHub <#5049 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZLBZ7VMFFVUCPMM6WR3T2DZLLVG3AVCNFSM6AAAAABIIWS5SCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMJVGA4DKOBWHE . You are receiving this because you were mentioned.Message ID: @.>

Hello @nunjunj just want to kindly ping and circle back to see if there may be any update on this feature. Thanks

@nunjunj nunjunj force-pushed the chat-method-for-offline-llm branch 4 times, most recently from e26dc5d to c49532c Compare July 23, 2024 17:34
@nunjunj nunjunj force-pushed the chat-method-for-offline-llm branch 2 times, most recently from 7fcc1bf to 7530495 Compare July 23, 2024 17:49
@DarkLight1337
Copy link
Member

You may consider using the utilities in chat_utils.py (#6602) to avoid code duplication.

@DarkLight1337
Copy link
Member

DarkLight1337 commented Aug 3, 2024

Also, please avoid unnecessarily editing whitespace.

@nunjunj nunjunj force-pushed the chat-method-for-offline-llm branch from a8f42d2 to c4ca2f3 Compare August 8, 2024 18:13
@nunjunj nunjunj force-pushed the chat-method-for-offline-llm branch 2 times, most recently from 7b7b481 to f54c406 Compare August 15, 2024 15:23
@nunjunj nunjunj force-pushed the chat-method-for-offline-llm branch from f54c406 to c64cc8c Compare August 15, 2024 15:25
vllm/entrypoints/llm.py Outdated Show resolved Hide resolved
vllm/entrypoints/llm.py Outdated Show resolved Hide resolved
vllm/entrypoints/llm.py Outdated Show resolved Hide resolved
vllm/entrypoints/llm.py Outdated Show resolved Hide resolved
Copy link
Member

@DarkLight1337 DarkLight1337 left a comment

Choose a reason for hiding this comment

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

LGTM now, thanks for implementing this! We can address multi-modal support in a future PR.

@DarkLight1337 DarkLight1337 enabled auto-merge (squash) August 15, 2024 16:21
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 15, 2024
Copy link
Member

@mgoin mgoin left a comment

Choose a reason for hiding this comment

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

LGTM as well!

@youkaichao youkaichao disabled auto-merge August 16, 2024 02:41
@youkaichao youkaichao merged commit 3b19e39 into vllm-project:main Aug 16, 2024
67 of 69 checks passed
kylesayrs pushed a commit to neuralmagic/vllm that referenced this pull request Aug 17, 2024
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: Cyrus Leung <[email protected]>
Co-authored-by: DarkLight1337 <[email protected]>
zifeitong pushed a commit to zifeitong/vllm that referenced this pull request Aug 20, 2024
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: Cyrus Leung <[email protected]>
Co-authored-by: DarkLight1337 <[email protected]>
fialhocoelho pushed a commit to opendatahub-io/vllm that referenced this pull request Aug 22, 2024
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: Cyrus Leung <[email protected]>
Co-authored-by: DarkLight1337 <[email protected]>
omrishiv pushed a commit to omrishiv/vllm that referenced this pull request Aug 26, 2024
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: Cyrus Leung <[email protected]>
Co-authored-by: DarkLight1337 <[email protected]>
Alvant pushed a commit to compressa-ai/vllm that referenced this pull request Oct 26, 2024
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: Cyrus Leung <[email protected]>
Co-authored-by: DarkLight1337 <[email protected]>
Signed-off-by: Alvant <[email protected]>
KuntaiDu pushed a commit to KuntaiDu/vllm that referenced this pull request Nov 20, 2024
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: nunjunj <[email protected]>
Co-authored-by: Cyrus Leung <[email protected]>
Co-authored-by: DarkLight1337 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
6 participants