Phi3V Example#

Source vllm-project/vllm.

 1import os
 2import subprocess
 3
 4from PIL import Image
 5
 6from vllm import LLM, SamplingParams
 7
 8# The assets are located at `s3://air-example-data-2/vllm_opensource_llava/`.
 9# You can use `.buildkite/download-images.sh` to download them
10
11
12def run_phi3v():
13    model_path = "microsoft/Phi-3-vision-128k-instruct"
14
15    # Note: The default setting of max_num_seqs (256) and
16    # max_model_len (128k) for this model may cause OOM.
17    # You may lower either to run this example on lower-end GPUs.
18
19    # In this example, we override max_num_seqs to 5 while
20    # keeping the original context length of 128k.
21    llm = LLM(
22        model=model_path,
23        trust_remote_code=True,
24        max_num_seqs=5,
25    )
26
27    image = Image.open("images/cherry_blossom.jpg")
28
29    # single-image prompt
30    prompt = "<|user|>\n<|image_1|>\nWhat is the season?<|end|>\n<|assistant|>\n"  # noqa: E501
31    sampling_params = SamplingParams(temperature=0, max_tokens=64)
32
33    outputs = llm.generate(
34        {
35            "prompt": prompt,
36            "multi_modal_data": {
37                "image": image
38            },
39        },
40        sampling_params=sampling_params)
41    for o in outputs:
42        generated_text = o.outputs[0].text
43        print(generated_text)
44
45
46if __name__ == "__main__":
47    s3_bucket_path = "s3://air-example-data-2/vllm_opensource_llava/"
48    local_directory = "images"
49
50    # Make sure the local directory exists or create it
51    os.makedirs(local_directory, exist_ok=True)
52
53    # Use AWS CLI to sync the directory, assume anonymous access
54    subprocess.check_call([
55        "aws",
56        "s3",
57        "sync",
58        s3_bucket_path,
59        local_directory,
60        "--no-sign-request",
61    ])
62    run_phi3v()