-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into kill-the-server
- Loading branch information
Showing
84 changed files
with
5,356 additions
and
1,045 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,99 @@ | ||
''' | ||
Demonstrate prompting of text-to-text | ||
encoder/decoder models, specifically BART | ||
''' | ||
|
||
from vllm import LLM, SamplingParams | ||
from vllm.inputs import ExplicitEncoderDecoderPrompt, TextPrompt, TokensPrompt | ||
from vllm.utils import zip_enc_dec_prompt_lists | ||
|
||
dtype = "float" | ||
|
||
# Create a BART encoder/decoder model instance | ||
llm = LLM( | ||
model="facebook/bart-large-cnn", | ||
dtype=dtype, | ||
) | ||
|
||
# Get BART tokenizer | ||
tokenizer = llm.llm_engine.get_tokenizer_group() | ||
|
||
# Test prompts | ||
# | ||
# This section shows all of the valid ways to prompt an | ||
# encoder/decoder model. | ||
# | ||
# - Helpers for building prompts | ||
text_prompt_raw = "Hello, my name is" | ||
text_prompt = TextPrompt(prompt="The president of the United States is") | ||
tokens_prompt = TokensPrompt(prompt_token_ids=tokenizer.encode( | ||
prompt="The capital of France is")) | ||
# - Pass a single prompt to encoder/decoder model | ||
# (implicitly encoder input prompt); | ||
# decoder input prompt is assumed to be None | ||
|
||
single_text_prompt_raw = text_prompt_raw # Pass a string directly | ||
single_text_prompt = text_prompt # Pass a TextPrompt | ||
single_tokens_prompt = tokens_prompt # Pass a TokensPrompt | ||
|
||
# - Pass explicit encoder and decoder input prompts within one data structure. | ||
# Encoder and decoder prompts can both independently be text or tokens, with | ||
# no requirement that they be the same prompt type. Some example prompt-type | ||
# combinations are shown below, note that these are not exhaustive. | ||
|
||
enc_dec_prompt1 = ExplicitEncoderDecoderPrompt( | ||
# Pass encoder prompt string directly, & | ||
# pass decoder prompt tokens | ||
encoder_prompt=single_text_prompt_raw, | ||
decoder_prompt=single_tokens_prompt, | ||
) | ||
enc_dec_prompt2 = ExplicitEncoderDecoderPrompt( | ||
# Pass TextPrompt to encoder, and | ||
# pass decoder prompt string directly | ||
encoder_prompt=single_text_prompt, | ||
decoder_prompt=single_text_prompt_raw, | ||
) | ||
enc_dec_prompt3 = ExplicitEncoderDecoderPrompt( | ||
# Pass encoder prompt tokens directly, and | ||
# pass TextPrompt to decoder | ||
encoder_prompt=single_tokens_prompt, | ||
decoder_prompt=single_text_prompt, | ||
) | ||
|
||
# - Finally, here's a useful helper function for zipping encoder and | ||
# decoder prompt lists together into a list of ExplicitEncoderDecoderPrompt | ||
# instances | ||
zipped_prompt_list = zip_enc_dec_prompt_lists( | ||
['An encoder prompt', 'Another encoder prompt'], | ||
['A decoder prompt', 'Another decoder prompt']) | ||
|
||
# - Let's put all of the above example prompts together into one list | ||
# which we will pass to the encoder/decoder LLM. | ||
prompts = [ | ||
single_text_prompt_raw, single_text_prompt, single_tokens_prompt, | ||
enc_dec_prompt1, enc_dec_prompt2, enc_dec_prompt3 | ||
] + zipped_prompt_list | ||
|
||
print(prompts) | ||
|
||
# Create a sampling params object. | ||
sampling_params = SamplingParams( | ||
temperature=0, | ||
top_p=1.0, | ||
min_tokens=0, | ||
max_tokens=20, | ||
) | ||
|
||
# Generate output tokens from the prompts. The output is a list of | ||
# RequestOutput objects that contain the prompt, generated | ||
# text, and other information. | ||
outputs = llm.generate(prompts, sampling_params) | ||
|
||
# Print the outputs. | ||
for output in outputs: | ||
prompt = output.prompt | ||
encoder_prompt = output.encoder_prompt | ||
generated_text = output.outputs[0].text | ||
print(f"Encoder prompt: {encoder_prompt!r}, " | ||
f"Decoder prompt: {prompt!r}, " | ||
f"Generated text: {generated_text!r}") |
This file contains 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 |
---|---|---|
@@ -1,34 +1,7 @@ | ||
# Common dependencies | ||
# -r requirements-common.txt | ||
# TODO: remove temporary copy of all common dependencies once Optimum Intel will support Transformers >= 4.43.2 | ||
cmake >= 3.21 | ||
ninja # For faster builds. | ||
psutil | ||
sentencepiece # Required for LLaMA tokenizer. | ||
numpy < 2.0.0 | ||
requests | ||
tqdm | ||
py-cpuinfo | ||
transformers < 4.43 | ||
tokenizers >= 0.19.1 # Required for Llama 3. | ||
fastapi | ||
aiohttp | ||
openai | ||
uvicorn[standard] | ||
pydantic >= 2.0 # Required for OpenAI server. | ||
pillow # Required for image processing | ||
prometheus_client >= 0.18.0 | ||
prometheus-fastapi-instrumentator >= 7.0.0 | ||
tiktoken >= 0.6.0 # Required for DBRX tokenizer | ||
lm-format-enforcer == 0.10.3 | ||
outlines >= 0.0.43, < 0.1 # Requires torch >= 2.1.0 | ||
typing_extensions | ||
filelock >= 3.10.4 # filelock starts to support `mode` argument from 3.10.4 | ||
pyzmq | ||
gguf == 0.9.1 | ||
-r requirements-common.txt | ||
|
||
# OpenVINO dependencies | ||
torch >= 2.1.2 | ||
openvino ~= 2024.3.0.dev | ||
openvino-tokenizers[transformers] ~= 2024.3.0.0.dev | ||
optimum-intel[openvino] >= 1.18.1 | ||
openvino ~= 2024.3.0 | ||
optimum-intel[openvino] >= 1.18.2 |
This file contains 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 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.