2024-06-18 10:34:33 +08:00
|
|
|
from vllm import LLM, SamplingParams
|
2024-07-16 14:12:25 +08:00
|
|
|
from vllm.assets.image import ImageAsset
|
2024-07-03 11:34:00 +08:00
|
|
|
|
2024-06-18 10:34:33 +08:00
|
|
|
|
|
|
|
def run_phi3v():
|
|
|
|
model_path = "microsoft/Phi-3-vision-128k-instruct"
|
2024-06-27 14:20:01 +08:00
|
|
|
|
2024-06-28 23:34:29 -07:00
|
|
|
# Note: The default setting of max_num_seqs (256) and
|
|
|
|
# max_model_len (128k) for this model may cause OOM.
|
2024-07-03 15:14:16 -07:00
|
|
|
# You may lower either to run this example on lower-end GPUs.
|
|
|
|
|
2024-06-28 23:34:29 -07:00
|
|
|
# In this example, we override max_num_seqs to 5 while
|
|
|
|
# keeping the original context length of 128k.
|
2024-06-18 10:34:33 +08:00
|
|
|
llm = LLM(
|
|
|
|
model=model_path,
|
|
|
|
trust_remote_code=True,
|
2024-06-28 23:34:29 -07:00
|
|
|
max_num_seqs=5,
|
2024-06-18 10:34:33 +08:00
|
|
|
)
|
|
|
|
|
2024-07-16 14:12:25 +08:00
|
|
|
image = ImageAsset("cherry_blossom").pil_image
|
2024-06-18 10:34:33 +08:00
|
|
|
|
|
|
|
# single-image prompt
|
|
|
|
prompt = "<|user|>\n<|image_1|>\nWhat is the season?<|end|>\n<|assistant|>\n" # noqa: E501
|
|
|
|
sampling_params = SamplingParams(temperature=0, max_tokens=64)
|
|
|
|
|
2024-06-19 17:58:32 +08:00
|
|
|
outputs = llm.generate(
|
|
|
|
{
|
|
|
|
"prompt": prompt,
|
2024-07-02 00:57:09 -07:00
|
|
|
"multi_modal_data": {
|
|
|
|
"image": image
|
|
|
|
},
|
2024-06-19 17:58:32 +08:00
|
|
|
},
|
|
|
|
sampling_params=sampling_params)
|
2024-06-18 10:34:33 +08:00
|
|
|
for o in outputs:
|
|
|
|
generated_text = o.outputs[0].text
|
|
|
|
print(generated_text)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
run_phi3v()
|