
- **Add SPDX license headers to python source files** - **Check for SPDX headers using pre-commit** commit 9d7ef44c3cfb72ca4c32e1c677d99259d10d4745 Author: Russell Bryant <rbryant@redhat.com> Date: Fri Jan 31 14:18:24 2025 -0500 Add SPDX license headers to python source files This commit adds SPDX license headers to python source files as recommended to the project by the Linux Foundation. These headers provide a concise way that is both human and machine readable for communicating license information for each source file. It helps avoid any ambiguity about the license of the code and can also be easily used by tools to help manage license compliance. The Linux Foundation runs license scans against the codebase to help ensure we are in compliance with the licenses of the code we use, including dependencies. Having these headers in place helps that tool do its job. More information can be found on the SPDX site: - https://spdx.dev/learn/handling-license-info/ Signed-off-by: Russell Bryant <rbryant@redhat.com> commit 5a1cf1cb3b80759131c73f6a9dddebccac039dea Author: Russell Bryant <rbryant@redhat.com> Date: Fri Jan 31 14:36:32 2025 -0500 Check for SPDX headers using pre-commit Signed-off-by: Russell Bryant <rbryant@redhat.com> --------- Signed-off-by: Russell Bryant <rbryant@redhat.com>
83 lines
2.0 KiB
Python
83 lines
2.0 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
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 how to pass input to the chat method:
|
|
|
|
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)
|
|
|
|
# You can run batch inference with llm.chat API
|
|
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.",
|
|
},
|
|
]
|
|
conversations = [conversation for _ in range(10)]
|
|
|
|
# We turn on tqdm progress bar to verify it's indeed running batch inference
|
|
outputs = llm.chat(messages=conversations,
|
|
sampling_params=sampling_params,
|
|
use_tqdm=True)
|
|
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,
|
|
# )
|