-
-
Notifications
You must be signed in to change notification settings - Fork 11k
Chat method for offline llm #5049
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
youkaichao
merged 16 commits into
vllm-project:main
from
nunjunj:chat-method-for-offline-llm
Aug 16, 2024
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e4b1d87
add chat method
nunjunj 189b100
add chat_template and add_generation_prompt params
7fcc1bf
run format.sh
6ee29e8
Merge remote-tracking branch origin/main into chat-method-for-offline…
2373936
apply parse_chat_messages
a5ed382
Merge remote-tracking branch origin/main into chat-method-for-offline…
c4ca2f3
remove support for multiple chats
b7c4031
Merge branch 'main' into chat-method-for-offline-llm
nunjunj c64cc8c
fix lint
nunjunj 3cd737e
revert format changes
nunjunj 9cead6b
fix lint
nunjunj 20b38d9
Reduce diffs
DarkLight1337 415193d
Clean
DarkLight1337 7eb64e2
Clean 2
DarkLight1337 64993b6
Fix docs
DarkLight1337 465b65e
Merge remote-tracking branch 'upstream/main' into chat-method-for-off…
DarkLight1337 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| from vllm import LLM, SamplingParams | ||
|
|
||
| llm = LLM(model="meta-llama/Meta-Llama-3-8B-Instruct") | ||
| sampling_params = SamplingParams(temperature=0.5) | ||
|
|
||
|
|
||
| def print_outputs(outputs): | ||
| for output in outputs: | ||
| prompt = output.prompt | ||
| generated_text = output.outputs[0].text | ||
| print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}") | ||
| print("-" * 80) | ||
|
|
||
|
|
||
| print("=" * 80) | ||
|
|
||
| # In this script, we demonstrate two ways to pass input to the chat method: | ||
|
|
||
| # Conversation with a list of dictionaries | ||
| conversation = [ | ||
| {"role": "system", "content": "You are a helpful assistant"}, | ||
| {"role": "user", "content": "Hello"}, | ||
| {"role": "assistant", "content": "Hello! How can I assist you today?"}, | ||
| { | ||
| "role": "user", | ||
| "content": "Write an essay about the importance of higher education.", | ||
| }, | ||
| ] | ||
| outputs = llm.chat( | ||
| conversation, sampling_params=sampling_params, use_tqdm=False | ||
| ) | ||
| print_outputs(outputs) | ||
|
|
||
| # Multiple conversations | ||
| conversations = [ | ||
| [ | ||
| {"role": "system", "content": "You are a helpful assistant"}, | ||
| {"role": "user", "content": "What is dark matter?"}, | ||
| ], | ||
| [ | ||
| {"role": "system", "content": "You are a helpful assistant"}, | ||
| {"role": "user", "content": "How are you?"}, | ||
| { | ||
| "role": "assistant", | ||
| "content": "I'm an AI without feelings, but I'm here to help!", | ||
| }, | ||
| {"role": "user", "content": "Tell me a joke."}, | ||
| ], | ||
| ] | ||
|
|
||
| outputs = llm.chat( | ||
| conversations, | ||
| sampling_params=sampling_params, | ||
| use_tqdm=False, | ||
| ) | ||
| print_outputs(outputs) | ||
|
|
||
| # A chat template can be optionally supplied. | ||
| # If not, the model will use its default chat template. | ||
|
|
||
| # with open('template_falcon_180b.jinja', "r") as f: | ||
| # chat_template = f.read() | ||
|
|
||
| # outputs = llm.chat( | ||
| # conversations, | ||
| # sampling_params=sampling_params, | ||
| # use_tqdm=False, | ||
| # chat_template=chat_template, | ||
| # ) |
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.
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.